clangd / vscode-clangd

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

'Error: command 'clangd.applyFix' already exists' when restarting language server #637

Open joe-noel-dev opened 5 months ago

joe-noel-dev commented 5 months ago

I noticed that clang errors are accumulating as I type and not being cleared.

When I try to restart the language server, I get an error:

Clang Language Server client: couln't create connection to server.

When I look in the logs, I see:

Error: command 'clangd.applyFix' already exists

Logs

I[13:03:15.524] Apple clangd version 15.0.0 (clang-1500.3.9.4)
I[13:03:15.524] Features: mac+xpc
I[13:03:15.524] PID: 34117
I[13:03:15.524] Working directory: /Users/[user]/dev/[project]
I[13:03:15.524] argv[0]: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clangd
I[13:03:15.524] argv[1]: -background-index
I[13:03:15.524] argv[2]: -header-insertion=iwyu
I[13:03:15.524] argv[3]: -header-insertion-decorators
I[13:03:15.524] argv[4]: --function-arg-placeholders
I[13:03:15.524] argv[5]: --log=verbose
V[13:03:15.524] User config file is /Users/[user]/Library/Preferences/clangd/config.yaml
I[13:03:15.524] Starting LSP over stdin/stdout
V[13:03:15.524] <<< {"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.90.0"},"initializationOptions":{"clangdFileStatus":true,"fallbackFlags":[]},"locale":"en-gb","processId":31787,"rootPath":"/Users/[user]/dev/[project]","rootUri":"file:///Users/[user]/dev/[project]","trace":"off","workspaceFolders":[{"name":"[project]","uri":"file:///Users/[user]/dev/[project]"}]}}

I[13:03:15.524] <-- initialize(0)
V[13:03:15.525] Invoking /usr/bin/xcrun to find clang installation
I[13:03:15.533] --> reply:initialize(0) 8 ms
V[13:03:15.533] >>> {"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,"inlayHintProvider":true,"memoryUsageProvider":true,"referencesProvider":true,"renameProvider":{"prepareProvider":true},"selectionRangeProvider":true,"semanticTokensProvider":{"full":{"delta":true},"legend":{"tokenModifiers":["declaration","deprecated","deduced","readonly","static","abstract","virtual","dependentName","defaultLibrary","usedAsMutableReference","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","comment"]},"range":false},"signatureHelpProvider":{"triggerCharacters":["(",")","{","}","<",">",","]},"standardTypeHierarchyProvider":true,"textDocumentSync":{"change":2,"openClose":true,"save":true},"typeDefinitionProvider":true,"typeHierarchyProvider":true,"workspaceSymbolProvider":true},"serverInfo":{"name":"clangd","version":"Apple clangd version 15.0.0 (clang-1500.3.9.4) mac+xpc x86_64-apple-darwin23.4.0; target=arm64-apple-darwin23.4.0"}}}

[Error - 13:03:15] Server initialization failed.
Error: command 'clangd.applyFix' already exists
    at h.registerCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:153:199082)
    at Object.registerCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:163:21945)
    at ip.register (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:37:71984)
    at ip.initialize (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:37:71547)
    at ac.initializeFeatures (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:19220)
    at ac.doInitialize (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:7588)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ac.start (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:4617)
[Error - 13:03:15] Clang Language Server client: couldn't create connection to server.
Error: command 'clangd.applyFix' already exists
    at h.registerCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:153:199082)
    at Object.registerCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:163:21945)
    at ip.register (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:37:71984)
    at ip.initialize (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:37:71547)
    at ac.initializeFeatures (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:19220)
    at ac.doInitialize (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:7588)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ac.start (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:4617)
[Error - 13:03:15] Sending notification textDocument/didOpen failed.
Error: command 'clangd.applyFix' already exists
    at h.registerCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:153:199082)
    at Object.registerCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:163:21945)
    at ip.register (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:37:71984)
    at ip.initialize (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:37:71547)
    at ac.initializeFeatures (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:19220)
    at ac.doInitialize (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:7588)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ac.start (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:4617)
[Error - 13:03:15] Sending document notification textDocument/didOpen failed
Error: command 'clangd.applyFix' already exists
    at h.registerCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:153:199082)
    at Object.registerCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:163:21945)
    at ip.register (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:37:71984)
    at ip.initialize (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:37:71547)
    at ac.initializeFeatures (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:19220)
    at ac.doInitialize (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:7588)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ac.start (/Users/[user]/.vscode/extensions/llvm-vs-code-extensions.vscode-clangd-0.1.28/out/bundle.js:39:4617)
V[13:03:15.534] <<< {"jsonrpc":"2.0","method":"initialized","params":{}}

I[13:03:15.534] <-- initialized
V[13:03:15.535] <<< {"id":1,"jsonrpc":"2.0","method":"shutdown"}

I[13:03:15.535] <-- shutdown(1)
I[13:03:15.535] --> reply:shutdown(1) 0 ms
V[13:03:15.535] >>> {"id":1,"jsonrpc":"2.0","result":null}

V[13:03:15.536] <<< {"jsonrpc":"2.0","method":"exit"}

I[13:03:15.536] <-- exit
I[13:03:15.536] LSP finished, exiting with status 0

System information

clangd version: Apple clangd version 15.0.0 (clang-1500.3.9.4) Extension version: v0.1.28 OS version: macOS 14.4.1

VSCode version:

Version: 1.90.0 (Universal) Commit: 89de5a8d4d6205e5b11647eb6a74844ca23d2573 Date: 2024-06-04T19:34:44.157Z (5 days ago) Electron: 29.4.0 ElectronBuildId: 9593362 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Darwin arm64 23.4.0

joe-noel-dev commented 5 months ago

I think this may have been caused by a conflict with the sswg.swift-lang extension. After disabling that extension, I no longer had problems with 'sticky' errors and no longer have the 'applyFix' error.

I will leave this open just in case the problem is with this extension, otherwise this can be closed.

HighCommander4 commented 5 months ago

An instance of the `command 'clangd.applyFix' already exists' error was fixed in https://github.com/clangd/vscode-clangd/issues/502, but the version of vscode-clangd that you're running (0.1.28) already contains that fix. So maybe the error can occur another way?

If you have a way to reproduce the error reliably, that would be helpful so it can be investigated further.

joe-noel-dev commented 5 months ago

I think my repro steps were as follows:

I have since retried today and I see all the same problems I was seeing except the last one. I can no longer repro the 'clangd.applyFix' error.

If I disable the Swift extension, it fixes the 'sticky' errors that I was seeing.

HighCommander4 commented 5 months ago

Thanks.

I have not been able to reproduce this. But then again I'm not on Mac, and I don't have a Swift toolchain installed, maybe those are needed to reproduce.

I'm going to leave this bug open, in case someone else is able to reproduce the issue and would like to investigate it.

junbujianwpl commented 4 months ago

I think this may have been caused by a conflict with the sswg.swift-lang extension. After disabling that extension, I no longer had problems with 'sticky' errors and no longer have the 'applyFix' error.

I will leave this open just in case the problem is with this extension, otherwise this can be closed.

Yeah, this did the job for me.

PBK-B commented 2 months ago

I also reproduced the issue and was able to get it back to normal by disabling sswg.swift-lang

yuygfgg commented 2 weeks ago

I'm having the same problem, but the simple solution of disabling sswg.swift-lang does not work for me because I'm working on a swift-C++ mixed project.