weixin_39847437
weixin_39847437
2020-12-02 09:04

Unable to enable semantic highlighting on vscode

  • OS: win10
  • clangd: 10.0.0 (https://github.com/llvm/llvm-project.git 8d6a863b02f199960590973f06b4c4dd29df578f)
c++
class Test {};

int main() {
    Test t; // Test is not highlighted
}

image

  • log

I[12:19:46.326] clangd version 10.0.0 (https://github.com/llvm/llvm-project.git 8d6a863b02f199960590973f06b4c4dd29df578f)
I[12:19:46.327] Working directory: f:\VSCode\STL
I[12:19:46.327] argv[0]: D:/clangd/bin/clangd.exe
I[12:19:46.327] argv[1]: --header-insertion=never
I[12:19:46.327] argv[2]: --log=verbose
I[12:19:46.327] Starting LSP over stdin/stdout
V[12:19:46.327] <<< {"id":0,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dynamicRegistration":true,"isPreferredSupport":true},"codeLens":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"completion":{"completionItem":{"commitCharactersSupport":true,"deprecatedSupport":true,"documentationFormat":["markdown","plaintext"],"preselectSupport":true,"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},"contextSupport":true,"dynamicRegistration":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"documentHighlight":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"documentSymbol":{"dynamicRegistration":true,"hierarchicalDocumentSymbolSupport":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"foldingRange":{"dynamicRegistration":true,"lineFoldingOnly":true,"rangeLimit":5000},"formatting":{"dynamicRegistration":true},"hover":{"contentFormat":["markdown","plaintext"],"dynamicRegistration":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"onTypeFormatting":{"dynamicRegistration":true},"publishDiagnostics":{"relatedInformation":true,"tagSupport":{"valueSet":[1,2]}},"rangeFormatting":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"selectionRange":{"dynamicRegistration":true},"semanticHighlightingCapabilities":{"semanticHighlighting":true},"signatureHelp":{"contextSupport":true,"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"synchronization":{"didSave":true,"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true}},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"executeCommand":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"workspaceEdit":{"documentChanges":true,"failureHandling":"textOnlyTransactional","resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"vscode","version":"1.38.1"},"initializationOptions":{"clangdFileStatus":true},"processId":2224,"rootPath":"f:\\VSCode\\STL","rootUri":"file:///f%3A/VSCode/STL","trace":"off","workspaceFolders":[{"name":"STL","uri":"file:///f%3A/VSCode/STL"}]}}

I[12:19:46.327]  reply:initialize(0) 0 ms
V[12:19:46.328] >>> {"id":0,"jsonrpc":"2.0","result":{"capabilities":{"codeActionProvider":{"codeActionKinds":["quickfix","refactor","info"]},"completionProvider":{"resolveProvider":false,"triggerCharacters":[".",">",":"]},"declarationProvider":true,"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]},"hoverProvider":true,"referencesProvider":true,"renameProvider":{"prepareProvider":true},"selectionRangeProvider":true,"semanticHighlighting":{"scopes":[["variable.other.cpp"],["variable.other.local.cpp"],["variable.parameter.cpp"],["entity.name.function.cpp"],["entity.name.function.method.cpp"],["entity.name.function.method.static.cpp"],["variable.other.field.cpp"],["variable.other.field.static.cpp"],["entity.name.type.class.cpp"],["entity.name.type.enum.cpp"],["variable.other.enummember.cpp"],["entity.name.type.typedef.cpp"],["entity.name.namespace.cpp"],["entity.name.type.template.cpp"],["storage.type.primitive.cpp"],["entity.name.function.preprocessor.cpp"]]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":2,"typeHierarchyProvider":true,"workspaceSymbolProvider":true}}}

V[12:19:46.337] <<< {"jsonrpc":"2.0","method":"initialized","params":{}}

I[12:19:46.337]  textDocument/clangd.fileStatus
V[12:19:46.338] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes","uri":"file:///f:/VSCode/STL/TEST.CPP"}}

I[12:19:46.338] Updating file f:\VSCode\STL\TEST.CPP with command clangd fallback
[f:\VSCode\STL]
D:\clangd\bin\clang f:\VSCode\STL\TEST.CPP -fsyntax-only -resource-dir=D:\clangd\lib\clang\10.0.0
V[12:19:46.341] Preamble for file f:\VSCode\STL\TEST.CPP cannot be reused. Attempting to rebuild it.
V[12:19:46.355] <<< {"id":1,"jsonrpc":"2.0","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///f%3A/VSCode/STL/TEST.CPP"}}}

I[12:19:46.355]  textDocument/publishDiagnostics
V[12:19:46.386] >>> {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[],"uri":"file:///f:/VSCode/STL/TEST.CPP"}}

I[12:19:46.386] --> textDocument/semanticHighlighting
V[12:19:46.386] >>> {"jsonrpc":"2.0","method":"textDocument/semanticHighlighting","params":{"lines":[{"line":0,"tokens":"AAAABgAEAAg="},{"line":2,"tokens":"AAAAAAADAA4AAAAEAAQAAw=="},{"line":3,"tokens":"AAAABAAEAAgAAAAJAAEAAQ=="}],"textDocument":{"uri":"file:///f:/VSCode/STL/TEST.CPP"}}}

I[12:19:46.386] --> reply:textDocument/documentSymbol(1) 31 ms
V[12:19:46.386] >>> {"id":1,"jsonrpc":"2.0","result":[{"kind":5,"name":"Test","range":{"end":{"character":12,"line":0},"start":{"character":0,"line":0}},"selectionRange":{"end":{"character":10,"line":0},"start":{"character":6,"line":0}}},{"kind":12,"name":"main","range":{"end":{"character":0,"line":4},"start":{"character":0,"line":2}},"selectionRange":{"end":{"character":8,"line":2},"start":{"character":4,"line":2}}}]}

I[12:19:46.386] --> reply:textDocument/codeAction(2) 31 ms
V[12:19:46.386] >>> {"id":2,"jsonrpc":"2.0","result":[]}

I[12:19:46.386] --> textDocument/clangd.fileStatus
V[12:19:46.386] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///f:/VSCode/STL/TEST.CPP"}}

该提问来源于开源项目:clangd/clangd

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

10条回答

  • weixin_39687189 weixin_39687189 5月前

    Could you provide more information about your client (VSCode, vscode-clangd)? I didn't reproduce the issue ( VSCode 1.38.1 + vscode-clangd v0.0.18 + Dark + theme).

    I don't see any issue from your log, everything seems work as expected. MytextDocument/semanticHighlighting result is exactly the same as yours.

    点赞 评论 复制链接分享
  • weixin_39847437 weixin_39847437 5月前

    + vscode

    
    Version: 1.38.1 (user setup)
    Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
    Date: 2019-09-11T13:35:15.005Z
    Electron: 4.2.10
    Chrome: 69.0.3497.128
    Node.js: 10.11.0
    V8: 6.9.427.31-electron.0
    OS: Windows_NT x64 10.0.18362
    
    • vscode-clangd: v0.0.18
    点赞 评论 复制链接分享
  • weixin_39847437 weixin_39847437 5月前

    Semantic highlighting works fine on Linux but fails on Windows.

    点赞 评论 复制链接分享
  • weixin_39847437 weixin_39847437 5月前

    This problem may be caused by clangd not handling uri encoding correctly. it cause e.document.uri.toString() !== fileUri return true.

    https://reviews.llvm.org/source/llvm-github/browse/master/clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts$227

    vscode file uri: file:///f%3A/VSCode/STL/TEST.CPP clangd file uri: file:///f:/VSCode/STL/TEST.CPP

    点赞 评论 复制链接分享
  • weixin_39847437 weixin_39847437 5月前

    I think we should escape colon, because vscode always escape it. https://reviews.llvm.org/D53016

    see https://github.com/microsoft/vscode/issues/58985

    点赞 评论 复制链接分享
  • weixin_39710106 weixin_39710106 5月前

    The : is not required to be escaped, but is allowed to be. clangd prefers not to escape it as that is (by far) more common.

    The bug is in the typescript code IMO: the parsed URIs should be compared, not the encoded forms (which are not unique)

    On Fri, Nov 8, 2019, 8:32 AM lh123 wrote:

    https://reviews.llvm.org/D53016?id=168758#inline-466856

    — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/clangd/clangd/issues/176?email_source=notifications&email_token=AAEGBALMRZ4FNVMCHSO2DVTQSUIYVA5CNFSM4I52NWP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDO7V5Q#issuecomment-551418614, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEGBAOZWPN2ZNZ2G4SEZQTQSUIYVANCNFSM4I52NWPQ .

    点赞 评论 复制链接分享
  • weixin_39847437 weixin_39847437 5月前

    I have submit a patch to fix it. https://reviews.llvm.org/D69996

    点赞 评论 复制链接分享
  • weixin_39687189 weixin_39687189 5月前

    We need to update the related test as well, otherwise TS compiler isn't happy.

    
    // run tsc under the llvm-project/clang-tools-extra/clangd/clients/clangd-vscode, logs:
    test/semantic-highlighting.test.ts:91:7 - error TS2416: Property 'applyHighlights' in type 'MockHighlighter' is not assignable to the same property in base type 'Highlighter'.
      Type '(fileUri: string) => void' is not assignable to type '(fileUri: Uri) => void'.
        Types of parameters 'fileUri' and 'fileUri' are incompatible.
          Type 'Uri' is not assignable to type 'string'.
    
    91       applyHighlights(fileUri: string) {
             ~~~~~~~~~~~~~~~
    
    点赞 评论 复制链接分享
  • weixin_39847437 weixin_39847437 5月前

    fixed in https://reviews.llvm.org/D70078

    点赞 评论 复制链接分享
  • weixin_39687189 weixin_39687189 5月前

    Thanks for the fixes. The new version vscode-clangd v0.0.19 has been released on the VSCode market.

    点赞 评论 复制链接分享

相关推荐