Ericsson / CodeCompass

CodeCompass is a software comprehension tool for large scale software written in C/C++ and Java
https://codecompass.net
GNU General Public License v3.0
520 stars 102 forks source link

Incorrect highlighting of symbols on the New Frontend #628

Closed mcserep closed 9 months ago

mcserep commented 1 year ago

It seems that when a symbol (e.g. a variable) is clicked on the new frontend, the highlighting is not done based on the returned symbols by the backed, but instead some kind of text-based highlighting is performed.

E.g. when I clicked the variable p in StrPair::GetStr() (located in tinyxml2.cpp), all p characters were highlighted in the file: all p characters in other variables, in function names, in comments, etc.

https://codecompass.net/demo/new/project/?workspaceId=TinyXML2&projectFileId=13444780443610084403&editorSelection=358%7C33%7C358%7C34&activeTab=1&languageNodeId=3578118573785437335&activeAccordion=Info+tree

mcserep commented 1 year ago

@mdeme01 If you have time, could you please pinpoint the relevant code segment, so we could fix this easier? Thanks!

mdeme01 commented 1 year ago

@mdeme01 If you have time, could you please pinpoint the relevant code segment, so we could fix this easier? Thanks!

The highlighting is done based on the returned position (line, column) of the ast node. (getCppAstNodeInfoByPosition), and all of this happens in the codemirror-editor.tsx component, in the handleAstNodeSelect and dispatchSelection functions.

First, we check the position of the clicked node using CodeMirror's view.state here. From this we can get the ast node info with the getCppAstNodeInfoByPosition method, the response info will contain the ast node's position (line, column). Then we call CodeMirror's editor.dispatch method with the calculated anchor and head properties.

The highlighting of all other matched text might be related to the newer version of CodeMirror (- I used 6, the old one used 5 if i'm not mistaken.), as I implemented the selection the same way as in the old UI. Maybe there is a flag somewhere at the selection dispatch, but unfortunately, the CodeMirror documentation is really vague.