Skip to content

Commit d01523c

Browse files
committed
Fix issues
1 parent 9f84ebc commit d01523c

5 files changed

Lines changed: 35 additions & 5 deletions

File tree

plugins/csharp/service/src/csharpservice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void CsharpServiceHandler::getAstNodeInfo(
7373
if (!file)
7474
{
7575
LOG(warning) << "[csharpservice] getAstNodeInfo: file not found for path: " << return_.range.file;
76+
return_.range.file = ""; // File ID not found safely clear the file path instead of propagating string path
7677
return;
7778
}
7879
std::stringstream ss;

webgui-new/src/components/codemirror-editor/codemirror-editor.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ export const CodeMirrorEditor = (): JSX.Element => {
141141

142142
const highlightExtension = () => {
143143
return EditorView.decorations.of((view) => {
144-
const decorations = highlightRanges.map((pos) =>
145-
createHighlightDecoration(view, pos, highlightColor),
146-
) as never;
144+
const decorations = highlightRanges
145+
.map((pos) => createHighlightDecoration(view, pos, highlightColor))
146+
.filter((d) => d !== undefined) as never;
147147
return Decoration.set(decorations, true);
148148
});
149149
};
@@ -164,9 +164,15 @@ export const CodeMirrorEditor = (): JSX.Element => {
164164
const updateHighlights = async (astNode: AstNodeInfo) => {
165165
const refTypes = await getReferenceTypes(astNode.id as string);
166166
if (visitedLastAstNode?.id !== astNode.id) {
167+
const usageReferenceType = refTypes.get("Usage");
168+
if (usageReferenceType === undefined) {
169+
setHighlightRanges([]);
170+
setVisitedLastAstNode(null);
171+
return;
172+
}
167173
const allReferences = await getReferences(
168174
astNode.id as string,
169-
refTypes.get("Usage") as number,
175+
usageReferenceType,
170176
[],
171177
);
172178
const referencesInFile = allReferences.filter(

webgui-new/src/components/diagrams/diagrams.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, {
88
useState,
99
MouseEvent,
1010
} from "react";
11+
import { toast } from "react-toastify";
1112
import {
1213
createClient,
1314
getAstNodeInfo,
@@ -65,6 +66,11 @@ export const Diagrams = (): JSX.Element => {
6566
? await getFileInfo(appCtx.projectFileId)
6667
: undefined;
6768

69+
if (!fileInfoForClient?.type) {
70+
toast.error("File type is required to generate this diagram.");
71+
return;
72+
}
73+
6874
createClient(appCtx.workspaceId, fileInfoForClient?.type);
6975

7076
const initDiagramInfo =
@@ -121,6 +127,11 @@ export const Diagrams = (): JSX.Element => {
121127
const parsedDiagram = parser.parseFromString(diagram, "text/xml");
122128
const diagramSvg = parsedDiagram.getElementsByTagName("svg")[0];
123129

130+
if (!diagramSvg) {
131+
toast.error("Failed to parse diagram or diagram is empty.");
132+
return;
133+
}
134+
124135
diagramSvg.style.height = "100%";
125136
diagramSvg.style.cursor = "pointer";
126137

@@ -154,6 +165,11 @@ export const Diagrams = (): JSX.Element => {
154165
? await getFileInfo(appCtx.projectFileId)
155166
: undefined;
156167

168+
if (!fileInfoForClient?.type) {
169+
toast.error("File type is required to navigate to this diagram.");
170+
return;
171+
}
172+
157173
createClient(appCtx.workspaceId, fileInfoForClient?.type);
158174

159175
const initDiagramInfo =
@@ -215,6 +231,11 @@ export const Diagrams = (): JSX.Element => {
215231
);
216232
const diagramLegendSvg = parsedDiagramLegend.getElementsByTagName("svg")[0];
217233

234+
if (!diagramLegendSvg) {
235+
toast.error("Failed to parse legend diagram or it is empty.");
236+
return;
237+
}
238+
218239
diagramLegendSvg.style.height = "100%";
219240
diagramLegendContainerRef.current.replaceChildren(diagramLegendSvg);
220241

webgui-new/src/components/file-context-menu/file-context-menu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export const FileContextMenu = ({
4646
);
4747

4848
useEffect(() => {
49-
if (!fileInfo) return;
49+
if (!fileInfo || fileInfo.isDirectory || fileInfo.type === "Unknown")
50+
return;
5051
const init = async () => {
5152
createClient(appCtx.workspaceId, fileInfo?.type);
5253
const initDiagramTypes = await getFileDiagramTypes(fileInfo.id as string);

webgui-new/src/service/language-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const createClient = (
88
workspace: string,
99
fileType: string | undefined,
1010
) => {
11+
client = undefined;
1112
if (!config || !fileType) return;
1213

1314
const service = () => {

0 commit comments

Comments
 (0)