Skip to content

Commit 882b599

Browse files
author
Barnabás Domozi
committed
Webgui-new language service
1 parent 2b5a216 commit 882b599

File tree

6 files changed

+373
-28
lines changed

6 files changed

+373
-28
lines changed

webgui-new/package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webgui-new/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
"dependencies": {
3232
"@codemirror/lang-cpp": "^6.0.2",
33+
"@codemirror/lang-python": "^6.1.6",
3334
"@emotion/react": "^11.10.5",
3435
"@emotion/styled": "^11.10.5",
3536
"@mui/icons-material": "^5.11.0",

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import ReactCodeMirror, { Decoration, EditorView, ReactCodeMirrorRef } from '@uiw/react-codemirror';
1+
import ReactCodeMirror, { Decoration, EditorView, Extension, ReactCodeMirrorRef } from '@uiw/react-codemirror';
22
import { AccordionLabel } from 'enums/accordion-enum';
33
import { ThemeContext } from 'global-context/theme-context';
44
import React, { useContext, useRef, useState, useEffect, MouseEvent } from 'react';
5-
import { getCppAstNodeInfoByPosition, getCppReferenceTypes, getCppReferences } from 'service/cpp-service';
5+
import { createClient, getAstNodeInfoByPosition, getReferenceTypes, getReferences } from 'service/language-service';
66
import { AstNodeInfo, FileInfo, Position, Range } from '@thrift-generated';
77
import { cpp } from '@codemirror/lang-cpp';
8+
import { python } from '@codemirror/lang-python';
89
import { githubDark, githubLight } from '@uiw/codemirror-theme-github';
910
import { EditorContextMenu } from 'components/editor-context-menu/editor-context-menu';
1011
import { FileName } from 'components/file-name/file-name';
@@ -75,6 +76,8 @@ export const CodeMirrorEditor = (): JSX.Element => {
7576
useEffect(() => {
7677
if(!editorRef.current || !editorRef.current.view) return;
7778
setHighlightRanges([]);
79+
80+
createClient(appCtx.workspaceId, fileInfo?.type);
7881
}, [appCtx.workspaceId, fileInfo, fileContent])
7982

8083
const createHighlightDecoration = (view: EditorView, highlightPosition: HighlightPosition, highlightColor: string) => {
@@ -100,10 +103,23 @@ export const CodeMirrorEditor = (): JSX.Element => {
100103
return Decoration.set(decorations, true);
101104
})}
102105

106+
const languageExtension = (fileType?: string) =>
107+
{
108+
switch(fileType)
109+
{
110+
case "CPP":
111+
return cpp();
112+
case "PY":
113+
return python();
114+
default:
115+
return null;
116+
}
117+
}
118+
103119
const updateHighlights = async (astNode : AstNodeInfo) => {
104-
const refTypes = await getCppReferenceTypes(astNode.id as string)
120+
const refTypes = await getReferenceTypes(astNode.id as string)
105121
if(visitedLastAstNode?.id !== astNode.id){
106-
const allReferences = await getCppReferences(astNode.id as string, refTypes.get('Usage') as number, []);
122+
const allReferences = await getReferences(astNode.id as string, refTypes.get('Usage') as number, []);
107123
const referencesInFile = allReferences.filter(ref => ref.range?.file === fileInfo?.id);
108124
setHighlightRanges(referencesInFile.map(nodeInfo => {
109125
const startpos = nodeInfo?.range?.range?.startpos as { line: number, column: number };
@@ -174,7 +190,8 @@ export const CodeMirrorEditor = (): JSX.Element => {
174190
const astNodeInfo =
175191
fileInfo?.type === 'Unknown'
176192
? null
177-
: await getCppAstNodeInfoByPosition(fileInfo?.id as string, line.number, column);
193+
: await getAstNodeInfoByPosition(fileInfo?.id as string, line.number, column);
194+
178195
if (astNodeInfo) {
179196
sendGAEvent({
180197
event_action: 'click_on_word',
@@ -318,7 +335,7 @@ export const CodeMirrorEditor = (): JSX.Element => {
318335
</SC.GitBlameContainer>
319336
<ReactCodeMirror
320337
readOnly={true}
321-
extensions={[cpp(), highlightExtension()]}
338+
extensions={[languageExtension(fileInfo?.type), highlightExtension()].filter(e => e) as Extension[]}
322339
theme={theme === 'dark' ? githubDark : githubLight}
323340
basicSetup={{
324341
syntaxHighlighting: false,

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { IconButton, Menu, MenuItem, Modal, Tooltip } from '@mui/material';
33
import { ChevronRight, Close } from '@mui/icons-material';
44
import { TabName } from 'enums/tab-enum';
55
import {
6-
getCppAstNodeInfo,
7-
getCppDiagramTypes,
8-
getCppDocumentation,
9-
getCppReferenceTypes,
10-
getCppReferences,
11-
} from 'service/cpp-service';
6+
createClient,
7+
getAstNodeInfo,
8+
getDiagramTypes,
9+
getDocumentation,
10+
getReferenceTypes,
11+
getReferences,
12+
} from 'service/language-service';
1213
import { getAsHTMLForNode } from 'service/cpp-reparse-service';
1314
import { AstNodeInfo, Range } from '@thrift-generated';
1415
import { convertSelectionRangeToString } from 'utils/utils';
@@ -52,10 +53,13 @@ export const EditorContextMenu = ({
5253
useEffect(() => {
5354
if (!appCtx.languageNodeId) return;
5455
const init = async () => {
55-
const initAstNodeInfo = await getCppAstNodeInfo(appCtx.languageNodeId);
56+
const fileInfo = await getFileInfo(appCtx.projectFileId);
57+
createClient(appCtx.workspaceId, fileInfo?.type);
58+
59+
const initAstNodeInfo = await getAstNodeInfo(appCtx.languageNodeId);
5660
setAstNodeInfo(initAstNodeInfo);
5761

58-
const initDiagramTypes = await getCppDiagramTypes(appCtx.languageNodeId);
62+
const initDiagramTypes = await getDiagramTypes(appCtx.languageNodeId);
5963
setDiagramTypes(initDiagramTypes);
6064
};
6165
init();
@@ -69,7 +73,7 @@ export const EditorContextMenu = ({
6973
};
7074

7175
const getDocs = async () => {
72-
const initDocs = await getCppDocumentation(astNodeInfo?.id as string);
76+
const initDocs = await getDocumentation(astNodeInfo?.id as string);
7377
const fileInfo = await getFileInfo(appCtx.projectFileId as string);
7478
const parser = new DOMParser();
7579
const parsedHTML = parser.parseFromString(initDocs, 'text/html');
@@ -115,8 +119,8 @@ export const EditorContextMenu = ({
115119
const jumpToDef = async () => {
116120
if (!astNodeInfo) return;
117121

118-
const refTypes = await getCppReferenceTypes(astNodeInfo.id as string);
119-
const defRefs = await getCppReferences(
122+
const refTypes = await getReferenceTypes(astNodeInfo.id as string);
123+
const defRefs = await getReferences(
120124
astNodeInfo.id as string,
121125
refTypes.get('Definition') as number,
122126
astNodeInfo.tags ?? []

webgui-new/src/components/info-tree/info-tree.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { Code } from '@mui/icons-material';
33
import { ExpandMore, ChevronRight } from '@mui/icons-material';
44
import React, { SyntheticEvent, useContext, useEffect, useState } from 'react';
55
import {
6-
getCppReferenceTypes,
7-
getCppReferences,
8-
getCppProperties,
9-
getCppReferenceCount,
10-
getCppAstNodeInfo,
11-
} from 'service/cpp-service';
6+
createClient,
7+
getReferenceTypes,
8+
getReferences,
9+
getProperties,
10+
getReferenceCount,
11+
getAstNodeInfo,
12+
} from 'service/language-service';
1213
import { AstNodeInfo, FileInfo, Range } from '@thrift-generated';
1314
import { FileIcon, RefIcon } from 'components/custom-icon/custom-icon';
1415
import { TabName } from 'enums/tab-enum';
@@ -39,20 +40,23 @@ export const InfoTree = (): JSX.Element => {
3940
if (!appCtx.languageNodeId) return;
4041
setLoadComplete(false);
4142
const init = async () => {
42-
const initAstNodeInfo = await getCppAstNodeInfo(appCtx.languageNodeId as string);
43+
const fileInfo = await getFileInfo(appCtx.projectFileId);
44+
45+
createClient(appCtx.workspaceId, fileInfo?.type);
46+
const initAstNodeInfo = await getAstNodeInfo(appCtx.languageNodeId as string);
4347
if (!initAstNodeInfo) return;
4448

45-
const initProps = await getCppProperties(initAstNodeInfo.id as string);
46-
const initRefTypes = await getCppReferenceTypes(initAstNodeInfo.id as string);
49+
const initProps = await getProperties(initAstNodeInfo.id as string);
50+
const initRefTypes = await getReferenceTypes(initAstNodeInfo.id as string);
4751
const initRefCounts: typeof refCounts = new Map();
4852
const initRefs: typeof refs = new Map();
4953
const initFileUsages: typeof fileUsages = new Map();
5054

5155
for (const [rType, rId] of initRefTypes) {
52-
const refCount = await getCppReferenceCount(initAstNodeInfo.id as string, rId);
56+
const refCount = await getReferenceCount(initAstNodeInfo.id as string, rId);
5357
initRefCounts.set(rType, refCount);
5458

55-
const refsForType = await getCppReferences(initAstNodeInfo.id as string, rId, initAstNodeInfo.tags ?? []);
59+
const refsForType = await getReferences(initAstNodeInfo.id as string, rId, initAstNodeInfo.tags ?? []);
5660
initRefs.set(rType, refsForType);
5761

5862
if (rType === 'Caller' || rType === 'Usage') {

0 commit comments

Comments
 (0)