Use language-service interface for diagram generation#852
Use language-service interface for diagram generation#852barnabasdomozi wants to merge 2 commits intoEricsson:masterfrom
Conversation
Replaced CppService usage with the general language-service interface for generating diagrams in the new React WebGUI. Also added new diagram names needed by the Python plugin.
There was a problem hiding this comment.
Pull request overview
This PR refactors the new React WebGUI’s diagram generation to use the generic language-service interface (instead of hardcoding CppService), and extends the diagram type labels/mappings to support Python plugin diagrams (e.g., module dependency / usage diagrams), addressing #838.
Changes:
- Switch diagram generation in the Diagrams view from
cpp-servicecalls tolanguage-servicecalls. - Switch file context menu diagram-type discovery from
cpp-servicetolanguage-service. - Add new diagram type labels (i18n + enum array entries) and align Python plugin diagram IDs to those indices.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| webgui-new/src/i18n/locales/en.json | Adds English labels for new Python diagram types. |
| webgui-new/src/enums/entity-types.ts | Extends diagramTypeArray to include new diagram types at indices 10–12. |
| webgui-new/src/components/file-context-menu/file-context-menu.tsx | Uses language-service for file diagram type listing, initializing a language client. |
| webgui-new/src/components/diagrams/diagrams.tsx | Replaces cpp-service diagram APIs with language-service diagram APIs. |
| plugins/python/service/include/service/pythonservice.h | Assigns explicit diagram ID values to match the frontend’s diagram type index mapping. |
Comments suppressed due to low confidence (1)
webgui-new/src/components/diagrams/diagrams.tsx:88
Diagramsnow uses the language-service API, but it never initializes the language-service client (viacreateClient). If the user opens the diagrams tab directly (or after a previouscreateClientcall with an unsupported type),getAstNodeInfo/getFileDiagram/getDiagramwill return empty/undefined becauseclientis unset, anddiagramSvg.style...will throw when no<svg>is present. Initialize the client based on the current file’s language (e.g., fromprojectFileId/getFileInfo), and add a guard for empty diagram responses before dereferencing the<svg>element.
useEffect(() => {
if (appCtx.diagramGenId === '' || appCtx.diagramTypeId === '' || !appCtx.diagramType) return;
const init = async () => {
const initDiagramInfo =
appCtx.diagramType === 'file'
? await getFileInfo(appCtx.diagramGenId)
: appCtx.diagramType === 'ast'
? await getAstNodeInfo(appCtx.diagramGenId)
: undefined;
if (!initDiagramInfo) return;
if (parseInt(appCtx.diagramTypeId) === 999) {
const refTypes = await getReferenceTypes(initDiagramInfo.id as string);
if (refTypes.get('Definition') === undefined) return;
const astNodeDef = (
await getReferences(initDiagramInfo.id as string, refTypes.get('Definition') as number, [])
)[0];
setDiagramInfo(astNodeDef);
setCodeBitesDisplayed(true);
return;
}
const diagram =
initDiagramInfo instanceof FileInfo
? await getFileDiagram(appCtx.diagramGenId, parseInt(appCtx.diagramTypeId))
: initDiagramInfo instanceof AstNodeInfo
? await getDiagram(appCtx.diagramGenId, parseInt(appCtx.diagramTypeId))
: '';
sendGAEvent({
event_action: `load_diagram: ${appCtx.diagramTypeId}`,
event_category: appCtx.workspaceId,
event_label:
initDiagramInfo instanceof FileInfo
? initDiagramInfo.name
: initDiagramInfo instanceof AstNodeInfo
? initDiagramInfo.astNodeValue
: '',
});
const parser = new DOMParser();
const parsedDiagram = parser.parseFromString(diagram, 'text/xml');
const diagramSvg = parsedDiagram.getElementsByTagName('svg')[0];
diagramSvg.style.height = '100%';
diagramSvg.style.cursor = 'pointer';
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!fileInfo) return; | ||
| const init = async () => { | ||
| const initDiagramTypes = await getCppFileDiagramTypes(fileInfo.id as string); | ||
| createClient(appCtx.workspaceId, fileInfo?.type); |
There was a problem hiding this comment.
createClient(appCtx.workspaceId, fileInfo?.type) will be called for directories as well, where fileInfo.type is typically "Dir" (and sometimes "Unknown"). The current createClient implementation only handles CPP and PY, so this call can create a client pointing at an invalid service path and getFileDiagramTypes will return an empty map, effectively removing diagram options for directories. Add a guard to only call createClient for supported language types, or handle directory types explicitly so directory diagrams keep working.
| createClient(appCtx.workspaceId, fileInfo?.type); | |
| const supportedLanguageTypes = new Set(['CPP', 'PY']); | |
| if (supportedLanguageTypes.has(fileInfo?.type as string)) { | |
| createClient(appCtx.workspaceId, fileInfo?.type); | |
| } |
There was a problem hiding this comment.
I wouldn't hard code the supported language types here as well, so we could fine without this.
There was a problem hiding this comment.
This is actually a correct finding by AI.
If we right click on a directory, the createClient function in language-service.ts is called with a Dir file type which has no associated service. As a result, the service arrow function in createClient will return undefined, and we will try to create a Thrift service under http://host:port/project_name/undefined.
This is now fixed in commit 0cc3a5d
If no service is available for a particular file type (e.g. for "Dir" file type), the createClient function should return early instead of attempting to connect to an undefined Thrift endpoint.
19bdfb0 to
0cc3a5d
Compare
Replaced CppService usage with the general language-service interface for generating diagrams in the new React WebGUI.
Also added new diagram names needed by the Python plugin.
Closes #838
Example of a Python diagram that now works in the new WebGUI: