Skip to content

Use language-service interface for diagram generation#852

Open
barnabasdomozi wants to merge 2 commits intoEricsson:masterfrom
barnabasdomozi:lang_service_diagrams
Open

Use language-service interface for diagram generation#852
barnabasdomozi wants to merge 2 commits intoEricsson:masterfrom
barnabasdomozi:lang_service_diagrams

Conversation

@barnabasdomozi
Copy link
Copy Markdown
Collaborator

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:

image

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.
@barnabasdomozi barnabasdomozi self-assigned this Apr 19, 2026
@barnabasdomozi barnabasdomozi added Plugin: C++ Issues related to the parsing and presentation of C++ projects. Plugin: Python Issues related to the parsing and presentation of Python projects. Target: WebGUI Issues related to the web frontend. labels Apr 19, 2026
@mcserep mcserep requested review from Copilot and mcserep April 21, 2026 08:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-service calls to language-service calls.
  • Switch file context menu diagram-type discovery from cpp-service to language-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

  • Diagrams now uses the language-service API, but it never initializes the language-service client (via createClient). If the user opens the diagrams tab directly (or after a previous createClient call with an unsupported type), getAstNodeInfo/getFileDiagram/getDiagram will return empty/undefined because client is unset, and diagramSvg.style... will throw when no <svg> is present. Initialize the client based on the current file’s language (e.g., from projectFileId/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);
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
createClient(appCtx.workspaceId, fileInfo?.type);
const supportedLanguageTypes = new Set(['CPP', 'PY']);
if (supportedLanguageTypes.has(fileInfo?.type as string)) {
createClient(appCtx.workspaceId, fileInfo?.type);
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't hard code the supported language types here as well, so we could fine without this.

Copy link
Copy Markdown
Collaborator Author

@barnabasdomozi barnabasdomozi Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcserep

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.
@barnabasdomozi barnabasdomozi force-pushed the lang_service_diagrams branch from 19bdfb0 to 0cc3a5d Compare April 21, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Plugin: C++ Issues related to the parsing and presentation of C++ projects. Plugin: Python Issues related to the parsing and presentation of Python projects. Target: WebGUI Issues related to the web frontend.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python plugin diagrams not supported in the new WebGUI

3 participants