1- import ReactCodeMirror , { Decoration , EditorView , ReactCodeMirrorRef } from '@uiw/react-codemirror' ;
1+ import ReactCodeMirror , { Decoration , EditorView , Extension , ReactCodeMirrorRef } from '@uiw/react-codemirror' ;
22import { AccordionLabel } from 'enums/accordion-enum' ;
33import { ThemeContext } from 'global-context/theme-context' ;
44import 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' ;
66import { AstNodeInfo , FileInfo , Position , Range } from '@thrift-generated' ;
77import { cpp } from '@codemirror/lang-cpp' ;
8+ import { python } from '@codemirror/lang-python' ;
89import { githubDark , githubLight } from '@uiw/codemirror-theme-github' ;
910import { EditorContextMenu } from 'components/editor-context-menu/editor-context-menu' ;
1011import { 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 ,
0 commit comments