microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

Syntax highlight multi-editor issue #8867

Closed mmlacak closed 2 years ago

mmlacak commented 2 years ago

Bug type: Language Service

Describe the bug

Steps to reproduce

  1. install+enable MS C/C++ extension (without it all syntax highlighting is always the same, default one)
  2. open 2 editors side by side
  3. in left editor open C file
  4. in right editor open H file --> both editors show new (correct) syntax highlighting (must use H file, if C file is used, coloring remains the new, correct one)
  5. make some small change in C code -> H editor changes coloring to default (the one without C/C++ extension)
  6. save C file --> H editor briefly shows correct syntax highlight, then reverts back to default
  7. if H editor is focused (by clicking it, or tab), it switches to correct, new syntax highlighting

Works the other way around, if H file is edited and saved, then C file editor switches to default coloring (as if without C/C++ extension).

Expected behavior

All C and H files retain their new syntax highlight at all times, regardless of any editing, saving, ...

Code sample and logs

------- Workspace parsing diagnostics ------- Number of files discovered (not excluded): 7467 Number of files parsed: 589

- Logs from [the language server logging](https://code.visualstudio.com/docs/cpp/enable-logging-cpp#_enable-logging-for-the-language-server)

loggingLevel: Debug loggingLevel has changed to: Debug cpptools/didChangeCppProperties $/setTraceNotification cpptools/getCodeActions: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 82) cpptools/textEditorSelectionChange cpptools/activeDocumentChange: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 83) textDocument/hover: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 84) textDocument/hover: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 85) textDocument/hover: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 86) textDocument/didChange: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/textEditorSelectionChange cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 87) cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 88) cpptools/getDocumentSymbols: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 89) cpptools/getDocumentSymbols Checking for syntax errors: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c Queueing IntelliSense update for files in translation unit of: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c tag parsing file: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c sending 1 changes to server cpptools/finishUpdateSquiggles Error squiggle count: 0 Error squiggle count: 0 Update IntelliSense time (sec): 2.355 cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 90) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 91) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 92) textDocument/didChange: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/textEditorSelectionChange willSaveWaitUntil: 0ms textDocument/didSave: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c tag parsing file: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/fileChanged: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 94) idle loop: reparsing the active document Checking for syntax errors: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c Queueing IntelliSense update for files in translation unit of: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 95) sending 1 changes to server cpptools/finishUpdateSquiggles Error squiggle count: 0 Error squiggle count: 0 cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 96) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 97) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 98) cpptools/getDocumentSymbols: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 99) cpptools/getDocumentSymbols Checking for syntax errors: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c Queueing IntelliSense update for files in translation unit of: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/finishUpdateSquiggles Error squiggle count: 0 Error squiggle count: 0 Update IntelliSense time (sec): 2.259 cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 100) cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 101) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 102) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 103) textDocument/hover: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 104) textDocument/hover: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 105) cpptools/textEditorSelectionChange cpptools/activeDocumentChange: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h idle loop: reparsing the active document Checking for syntax errors: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h Queueing IntelliSense update for files in translation unit of: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/finishUpdateSquiggles Error squiggle count: 0 Error squiggle count: 0 Update IntelliSense time (sec): 0.257 cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 106) cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 107) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 108) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 109) textDocument/hover: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 110) cpptools/textEditorSelectionChange cpptools/textEditorSelectionChange cpptools/activeDocumentChange: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c idle loop: reparsing the active document Checking for syntax errors: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c Queueing IntelliSense update for files in translation unit of: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c cpptools/finishUpdateSquiggles Error squiggle count: 0 Error squiggle count: 0 Update IntelliSense time (sec): 0.257 cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 111) cpptools/getSemanticTokens: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 112) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/inc/cc_ply.h (id: 113) cpptools/getFoldingRanges: /home/pero/src/crochess/ws/libcrochess/src/cc_ply.c (id: 114)



**Screenshots**
<!-- If applicable, add screenshots to help explain your problem. -->

![Screenshot from 2022-02-15 15-42-21](https://user-images.githubusercontent.com/15709852/154096918-50435708-52ed-42b4-9c3a-d03470cca4f8.png)

**Additional context**
<!--
Providing call stacks:
For bugs like crashes, deadlocks, infinite loops, etc. that we are not able to repro and for which the call stack may be useful, please attach a debugger and/or create a dmp and provide the call stacks. Windows binaries have symbols available in VS Code by setting your "symbolSearchPath" to "https://msdl.microsoft.com/download/symbols".

Instructions for attaching debugger to language service process:
https://github.com/microsoft/vscode-cpptools/wiki/Attaching-debugger-to-cpptools-or-cpptools%E2%80%90srv.

Performance analysis:
For a performance issue see instructions at https://github.com/microsoft/vscode-cpptools/wiki/Troubleshooting-Performance-Issues.
-->
N/A
Colengms commented 2 years ago

Hi @mmlacak . Thank you for reporting this. We appear to have a bug preventing semantic highlighting in a source file from being updated when a header in the same translation unit is changed.

The underlying cause appears to be related to internal use of uri's that are equivalent but not perfect string matches.

sean-mcmanus commented 2 years ago

@Colengms But the user is using Linux -- this isn't related to the Windows drive case capitalization, right?

Colengms commented 2 years ago

You're right, that's another issue. I can also repro this one. :)

Something similar also repro's in VS. Though, instead of clearing the semantic tokens, it simply does not update semantic tokens for the other file until a 'full parse' occurs. So, it may be by-design that the other file is not updated, despite being visible. We could at lease prevent them from being cleared, as stale tokens would appear valid in a majority of scenarios.

Colengms commented 2 years ago

I believe this was addressed in 1.9.1. Closing as fixed.