clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
592 stars 97 forks source link

Issue with highlighting function signatures in hover widgets with `AlwaysBreakAfterDefinitionReturnType: true` in `.clang-format` #626

Closed tokyo4j closed 2 months ago

tokyo4j commented 2 months ago

When there's AlwaysBreakAfterDefinitionReturnType: true in .clang-format, function signatures in hover widgets are not highlighted correctly.

false

true (argc and argv are not highlighted)

Logs

output when I open the workspace and hover the cursor over "main" in the picture above with {"clangd.arguments": ["--log=verbose"]}

I[18:35:11.633] clangd version 17.0.6
I[18:35:11.633] Features: linux
I[18:35:11.633] PID: 35127
I[18:35:11.633] Working directory: /home/hrak/foo
I[18:35:11.633] argv[0]: /usr/bin/clangd
I[18:35:11.633] argv[1]: --log=verbose
V[18:35:11.633] User config file is /home/hrak/.config/clangd/config.yaml
I[18:35:11.633] Starting LSP over stdin/stdout
V[18:35:11.634] <<< {"id":0,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"markdown":{"parser":"marked","version":"1.1.0"},"positionEncodings":["utf-16"],"regularExpressions":{"engine":"ECMAScript","version":"ES2020"},"staleRequestSupport":{"cancel":true,"retryOnContentModified":["textDocument/semanticTokens/full","textDocument/semanticTokens/range","textDocument/semanticTokens/full/delta"]}},"notebookDocument":{"synchronization":{"dynamicRegistration":true,"executionSummarySupport":true}},"textDocument":{"callHierarchy":{"dynamicRegistration":true},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"dynamicRegistration":true,"honorsChangeAnnotations":false,"isPreferredSupport":true,"resolveSupport":{"properties":["edit"]}},"codeLens":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"completion":{"completionItem":{"commitCharactersSupport":true,"deprecatedSupport":true,"documentationFormat":["markdown","plaintext"],"insertReplaceSupport":true,"insertTextModeSupport":{"valueSet":[1,2]},"labelDetailsSupport":true,"preselectSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"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]},"completionList":{"itemDefaults":["commitCharacters","editRange","insertTextFormat","insertTextMode"]},"contextSupport":true,"dynamicRegistration":true,"editsNearCursor":true,"insertTextMode":2},"declaration":{"dynamicRegistration":true,"linkSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"diagnostic":{"dynamicRegistration":true,"relatedDocumentSupport":false},"documentHighlight":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"documentSymbol":{"dynamicRegistration":true,"hierarchicalDocumentSymbolSupport":true,"labelSupport":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]},"tagSupport":{"valueSet":[1]}},"foldingRange":{"dynamicRegistration":true,"foldingRange":{"collapsedText":false},"foldingRangeKind":{"valueSet":["comment","imports","region"]},"lineFoldingOnly":true,"rangeLimit":5000},"formatting":{"dynamicRegistration":true},"hover":{"contentFormat":["markdown","plaintext"],"dynamicRegistration":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"inactiveRegionsCapabilities":{"inactiveRegions":true},"inlayHint":{"dynamicRegistration":true,"resolveSupport":{"properties":["tooltip","textEdits","label.tooltip","label.location","label.command"]}},"inlineValue":{"dynamicRegistration":true},"linkedEditingRange":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"publishDiagnostics":{"codeDescriptionSupport":true,"dataSupport":true,"relatedInformation":true,"tagSupport":{"valueSet":[1,2]},"versionSupport":false},"rangeFormatting":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"honorsChangeAnnotations":true,"prepareSupport":true,"prepareSupportDefaultBehavior":1},"selectionRange":{"dynamicRegistration":true},"semanticTokens":{"augmentsSyntaxTokens":true,"dynamicRegistration":true,"formats":["relative"],"multilineTokenSupport":false,"overlappingTokenSupport":false,"requests":{"full":{"delta":true},"range":true},"serverCancelSupport":true,"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","macro","keyword","modifier","comment","string","number","regexp","operator","decorator"]},"signatureHelp":{"contextSupport":true,"dynamicRegistration":true,"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"synchronization":{"didSave":true,"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"typeHierarchy":{"dynamicRegistration":true}},"window":{"showDocument":{"support":true},"showMessage":{"messageActionItem":{"additionalPropertiesSupport":true}},"workDoneProgress":true},"workspace":{"applyEdit":true,"codeLens":{"refreshSupport":true},"configuration":true,"diagnostics":{"refreshSupport":true},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":true},"executeCommand":{"dynamicRegistration":true},"fileOperations":{"didCreate":true,"didDelete":true,"didRename":true,"dynamicRegistration":true,"willCreate":true,"willDelete":true,"willRename":true},"inlayHint":{"refreshSupport":true},"inlineValue":{"refreshSupport":true},"semanticTokens":{"refreshSupport":true},"symbol":{"dynamicRegistration":true,"resolveSupport":{"properties":["location.range"]},"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]},"tagSupport":{"valueSet":[1]}},"workspaceEdit":{"changeAnnotationSupport":{"groupsOnLabel":true},"documentChanges":true,"failureHandling":"textOnlyTransactional","normalizesLineEndings":true,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"Visual Studio Code","version":"1.88.1"},"initializationOptions":{"clangdFileStatus":true,"fallbackFlags":[]},"locale":"en-us","processId":35100,"rootPath":"/home/hrak/foo","rootUri":"file:///home/hrak/foo","trace":"off","workspaceFolders":[{"name":"foo","uri":"file:///home/hrak/foo"}]}}

I[18:35:11.634] <-- initialize(0)
I[18:35:11.634] --> reply:initialize(0) 0 ms
V[18:35:11.634] >>> {"id":0,"jsonrpc":"2.0","result":{"capabilities":{"astProvider":true,"callHierarchyProvider":true,"clangdInlayHintsProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor","info"]},"compilationDatabase":{"automaticReload":true},"completionProvider":{"resolveProvider":false,"triggerCharacters":[".","<",">",":","\"","/","*"]},"declarationProvider":true,"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentLinkProvider":{"resolveProvider":false},"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]},"foldingRangeProvider":true,"hoverProvider":true,"implementationProvider":true,"inactiveRegionsProvider":true,"inlayHintProvider":true,"memoryUsageProvider":true,"referencesProvider":true,"renameProvider":{"prepareProvider":true},"selectionRangeProvider":true,"semanticTokensProvider":{"full":{"delta":true},"legend":{"tokenModifiers":["declaration","definition","deprecated","deduced","readonly","static","abstract","virtual","dependentName","defaultLibrary","usedAsMutableReference","usedAsMutablePointer","constructorOrDestructor","userDefined","functionScope","classScope","fileScope","globalScope"],"tokenTypes":["variable","variable","parameter","function","method","function","property","variable","class","interface","enum","enumMember","type","type","unknown","namespace","typeParameter","concept","type","macro","modifier","operator","bracket","label","comment"]},"range":false},"signatureHelpProvider":{"triggerCharacters":["(",")","{","}","<",">",","]},"standardTypeHierarchyProvider":true,"textDocumentSync":{"change":2,"openClose":true,"save":true},"typeDefinitionProvider":true,"typeHierarchyProvider":true,"workspaceSymbolProvider":true},"serverInfo":{"name":"clangd","version":"clangd version 17.0.6 linux x86_64-pc-linux-gnu"}}}

V[18:35:11.635] <<< {"jsonrpc":"2.0","method":"initialized","params":{}}

I[18:35:11.635] <-- initialized
V[18:35:11.639] <<< {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"c","text":"#include \n\nint\nmain(int argc, char const *argv[]) {\n  puts(\"hello\");\n}\n","uri":"file:///home/hrak/foo/main.c","version":1}}}

I[18:35:11.639] <-- textDocument/didOpen
I[18:35:11.640] Failed to find compilation database for /home/hrak/foo/main.c
I[18:35:11.640] ASTWorker building file /home/hrak/foo/main.c version 1 with command clangd fallback
[/home/hrak/foo]
/usr/bin/clang -resource-dir=/usr/lib/clang/17 -- /home/hrak/foo/main.c
V[18:35:11.641] Driver produced command: cc1 -cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/hrak/foo -resource-dir /usr/lib/clang/17 -internal-isystem /usr/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../x86_64-pc-linux-gnu/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/home/hrak/foo -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -no-round-trip-args -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c /home/hrak/foo/main.c
I[18:35:11.641] --> textDocument/clangd.fileStatus
V[18:35:11.641] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes, running Update","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.641] Building first preamble for /home/hrak/foo/main.c version 1
I[18:35:11.653] Built preamble of size 298880 for file /home/hrak/foo/main.c version 1 in 0.01 seconds
I[18:35:11.653] --> workspace/semanticTokens/refresh(0)
I[18:35:11.653] Indexing c17 standard library in the context of /home/hrak/foo/main.c
V[18:35:11.653] >>> {"id":0,"jsonrpc":"2.0","method":"workspace/semanticTokens/refresh","params":null}

I[18:35:11.653] --> textDocument/clangd.fileStatus
V[18:35:11.653] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes, running Build AST","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.654] <<< {"id":0,"jsonrpc":"2.0","result":null}

I[18:35:11.654] <-- reply(0)
V[18:35:11.655] indexed preamble AST for /home/hrak/foo/main.c version 1:
  symbol slab: 363 symbols, 108912 bytes
  ref slab: 0 symbols, 0 refs, 128 bytes
  relations slab: 0 relations, 24 bytes
V[18:35:11.656] Build dynamic index for header symbols with estimated memory usage of 544476 bytes
V[18:35:11.657] indexed file AST for /home/hrak/foo/main.c version 1:
  symbol slab: 1 symbols, 4448 bytes
  ref slab: 2 symbols, 2 refs, 4272 bytes
  relations slab: 0 relations, 24 bytes
V[18:35:11.657] Build dynamic index for main-file symbols with estimated memory usage of 11576 bytes
I[18:35:11.657] --> textDocument/publishDiagnostics
V[18:35:11.657] >>> {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[],"uri":"file:///home/hrak/foo/main.c","version":1}}

I[18:35:11.657] --> textDocument/inactiveRegions
V[18:35:11.657] >>> {"jsonrpc":"2.0","method":"textDocument/inactiveRegions","params":{"regions":[],"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.657] --> textDocument/clangd.fileStatus
V[18:35:11.657] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.665] <<< {"id":1,"jsonrpc":"2.0","method":"textDocument/documentLink","params":{"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.665] <-- textDocument/documentLink(1)
V[18:35:11.665] ASTWorker running DocumentLinks on version 1 of /home/hrak/foo/main.c
I[18:35:11.665] --> reply:textDocument/documentLink(1) 0 ms
V[18:35:11.665] >>> {"id":1,"jsonrpc":"2.0","result":[{"range":{"end":{"character":18,"line":0},"start":{"character":9,"line":0}},"target":"file:///usr/include/stdio.h"}]}

I[18:35:11.665] --> textDocument/clangd.fileStatus
V[18:35:11.665] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.672] <<< {"id":2,"jsonrpc":"2.0","method":"textDocument/inlayHint","params":{"range":{"end":{"character":0,"line":6},"start":{"character":0,"line":0}},"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.672] <-- textDocument/inlayHint(2)
V[18:35:11.672] ASTWorker running InlayHints on version 1 of /home/hrak/foo/main.c
I[18:35:11.672] --> reply:textDocument/inlayHint(2) 0 ms
V[18:35:11.672] >>> {"id":2,"jsonrpc":"2.0","result":[{"kind":2,"label":"s:","paddingLeft":false,"paddingRight":true,"position":{"character":7,"line":4}}]}

I[18:35:11.672] --> textDocument/clangd.fileStatus
V[18:35:11.672] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.674] <<< {"id":3,"jsonrpc":"2.0","method":"textDocument/semanticTokens/full","params":{"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.674] <-- textDocument/semanticTokens/full(3)
V[18:35:11.674] ASTWorker running SemanticHighlights on version 1 of /home/hrak/foo/main.c
I[18:35:11.674] --> reply:textDocument/semanticTokens/full(3) 0 ms
V[18:35:11.674] >>> {"id":3,"jsonrpc":"2.0","result":{"data":[3,0,4,3,131075,0,9,4,2,16387,0,18,4,2,16403,1,2,4,3,131584],"resultId":"1"}}

I[18:35:11.674] --> textDocument/clangd.fileStatus
V[18:35:11.674] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

I[18:35:11.701] Indexed c17 standard library: 2841 symbols, 0 filtered
V[18:35:11.708] Build dynamic index for header symbols with estimated memory usage of 2589772 bytes
V[18:35:11.866] <<< {"id":4,"jsonrpc":"2.0","method":"textDocument/documentLink","params":{"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.866] <-- textDocument/documentLink(4)
V[18:35:11.866] <<< {"id":5,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[],"triggerKind":2},"range":{"end":{"character":0,"line":6},"start":{"character":0,"line":6}},"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.866] <-- textDocument/codeAction(5)
V[18:35:11.866] ASTWorker running DocumentLinks on version 1 of /home/hrak/foo/main.c
I[18:35:11.866] --> reply:textDocument/documentLink(4) 0 ms
V[18:35:11.866] >>> {"id":4,"jsonrpc":"2.0","result":[{"range":{"end":{"character":18,"line":0},"start":{"character":9,"line":0}},"target":"file:///usr/include/stdio.h"}]}

V[18:35:11.866] ASTWorker running codeAction on version 1 of /home/hrak/foo/main.c
I[18:35:11.866] --> reply:textDocument/codeAction(5) 0 ms
V[18:35:11.866] >>> {"id":5,"jsonrpc":"2.0","result":[]}

I[18:35:11.866] --> textDocument/clangd.fileStatus
V[18:35:11.866] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.883] <<< {"jsonrpc":"2.0","method":"$/setTrace","params":{"value":"off"}}

I[18:35:11.883] <-- $/setTrace
I[18:35:11.883] unhandled notification $/setTrace
V[18:35:11.883] <<< {"jsonrpc":"2.0","method":"$/setTrace","params":{"value":"off"}}

I[18:35:11.883] <-- $/setTrace
I[18:35:11.883] unhandled notification $/setTrace
V[18:35:11.943] <<< {"id":6,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[],"triggerKind":2},"range":{"end":{"character":0,"line":6},"start":{"character":0,"line":6}},"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.943] <-- textDocument/codeAction(6)
V[18:35:11.943] ASTWorker running codeAction on version 1 of /home/hrak/foo/main.c
I[18:35:11.943] --> reply:textDocument/codeAction(6) 0 ms
V[18:35:11.943] >>> {"id":6,"jsonrpc":"2.0","result":[]}

I[18:35:11.943] --> textDocument/clangd.fileStatus
V[18:35:11.943] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.944] <<< {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":6}}

I[18:35:11.944] <-- $/cancelRequest
V[18:35:11.945] <<< {"id":7,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[],"triggerKind":2},"range":{"end":{"character":0,"line":6},"start":{"character":0,"line":6}},"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.945] <-- textDocument/codeAction(7)
V[18:35:11.945] ASTWorker running codeAction on version 1 of /home/hrak/foo/main.c
I[18:35:11.945] --> reply:textDocument/codeAction(7) 0 ms
V[18:35:11.945] >>> {"id":7,"jsonrpc":"2.0","result":[]}

I[18:35:11.945] --> textDocument/clangd.fileStatus
V[18:35:11.945] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.954] <<< {"id":8,"jsonrpc":"2.0","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.954] <-- textDocument/documentSymbol(8)
V[18:35:11.954] ASTWorker running DocumentSymbols on version 1 of /home/hrak/foo/main.c
I[18:35:11.954] --> reply:textDocument/documentSymbol(8) 0 ms
V[18:35:11.954] >>> {"id":8,"jsonrpc":"2.0","result":[{"detail":"int (int, const char **)","kind":12,"name":"main","range":{"end":{"character":1,"line":5},"start":{"character":0,"line":2}},"selectionRange":{"end":{"character":4,"line":3},"start":{"character":0,"line":3}}}]}

I[18:35:11.954] --> textDocument/clangd.fileStatus
V[18:35:11.954] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:11.956] <<< {"id":9,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:11.956] <-- textDocument/foldingRange(9)
I[18:35:11.956] --> reply:textDocument/foldingRange(9) 0 ms
V[18:35:11.956] >>> {"id":9,"jsonrpc":"2.0","result":[{"endLine":4,"kind":"region","startCharacter":36,"startLine":3}]}

V[18:35:12.003] <<< {"jsonrpc":"2.0","method":"$/setTrace","params":{"value":"off"}}

I[18:35:12.003] <-- $/setTrace
I[18:35:12.003] unhandled notification $/setTrace
V[18:35:12.110] <<< {"id":10,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[],"triggerKind":2},"range":{"end":{"character":0,"line":6},"start":{"character":0,"line":6}},"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:12.110] <-- textDocument/codeAction(10)
V[18:35:12.110] ASTWorker running codeAction on version 1 of /home/hrak/foo/main.c
I[18:35:12.110] --> reply:textDocument/codeAction(10) 0 ms
V[18:35:12.110] >>> {"id":10,"jsonrpc":"2.0","result":[]}

I[18:35:12.110] --> textDocument/clangd.fileStatus
V[18:35:12.110] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:13.667] <<< {"id":11,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[],"triggerKind":2},"range":{"end":{"character":0,"line":6},"start":{"character":0,"line":6}},"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:13.667] <-- textDocument/codeAction(11)
V[18:35:13.667] ASTWorker running codeAction on version 1 of /home/hrak/foo/main.c
I[18:35:13.667] --> reply:textDocument/codeAction(11) 0 ms
V[18:35:13.667] >>> {"id":11,"jsonrpc":"2.0","result":[]}

I[18:35:13.667] --> textDocument/clangd.fileStatus
V[18:35:13.667] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:13.667] <<< {"id":12,"jsonrpc":"2.0","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:13.667] <-- textDocument/documentSymbol(12)
V[18:35:13.667] ASTWorker running DocumentSymbols on version 1 of /home/hrak/foo/main.c
I[18:35:13.667] --> reply:textDocument/documentSymbol(12) 0 ms
V[18:35:13.667] >>> {"id":12,"jsonrpc":"2.0","result":[{"detail":"int (int, const char **)","kind":12,"name":"main","range":{"end":{"character":1,"line":5},"start":{"character":0,"line":2}},"selectionRange":{"end":{"character":4,"line":3},"start":{"character":0,"line":3}}}]}

I[18:35:13.667] --> textDocument/clangd.fileStatus
V[18:35:13.667] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

V[18:35:13.914] <<< {"id":13,"jsonrpc":"2.0","method":"textDocument/hover","params":{"position":{"character":1,"line":3},"textDocument":{"uri":"file:///home/hrak/foo/main.c"}}}

I[18:35:13.914] <-- textDocument/hover(13)
V[18:35:13.914] ASTWorker running Hover on version 1 of /home/hrak/foo/main.c
I[18:35:13.916] --> reply:textDocument/hover(13) 2 ms
V[18:35:13.916] >>> {"id":13,"jsonrpc":"2.0","result":{"contents":{"kind":"markdown","value":"### function `main`  \n\n---\n→ `int`  \nParameters:  \n- `int argc`\n- `const char ** argv`\n\n---\n```cpp\nint\nmain(int argc, const char *argv[])\n```"},"range":{"end":{"character":4,"line":3},"start":{"character":0,"line":3}}}}

I[18:35:13.916] --> textDocument/clangd.fileStatus
V[18:35:13.916] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///home/hrak/foo/main.c"}}

System information Clangd version (from the log, or clangd --version): 17.0.6 clangd extension version: v0.1.28 Operating system: Arch Linux (AMD64)

HighCommander4 commented 2 months ago

Clangd does not color the output in the hover. This is what clangd sends back to the client:

I[19:22:00.963] --> reply:textDocument/hover(505) 4 ms
V[19:22:00.963] >>> {
  "id": 505,
  "jsonrpc": "2.0",
  "result": {
    "contents": {
      "kind": "markdown",
      "value": "### function `main`  \n\n---\n→ `int`  \nParameters:  \n- `int argc`\n- `const char ** argv`\n\n---\n```cpp\nint main(int argc, const char *argv[])\n```"
    },
    "range": {
      "end": {
        "character": 8,
        "line": 2
      },
      "start": {
        "character": 4,
        "line": 2
      }
    }
  }
}

Any coloring that appears is applied by the client.

HighCommander4 commented 2 months ago

In this case, it looks like vscode is applying its TextMate-based client-side highlighting to the code in the hover contents.

You can see the same effect in the editor itself:

  1. Disable the vscode-clangd plugin
  2. Observe the (now client-side) highlighting of int main(int argc, char const *argv[]) {}
  3. Add a newline before main, and observe the highlighting now

This client-side highlighting is implemented in https://github.com/jeff-hykin/better-cpp-syntax, so you can file an issue there if you'd like. (But note that client-side highlighting is based on regexes and tends to be inaccurate in general, so I wouldn't have high expectations for it.)