clangd / vscode-clangd

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

Failed to create connection to server with version 0.1.30 #725

Closed Carryme1899 closed 1 week ago

Carryme1899 commented 1 week ago

As described in https://github.com/clangd/vscode-clangd/issues/722#issuecomment-2475708195, it seems that the --clang-tidy-checks argument causing the issue.

Removing the argument or updating to 0.1.31 resolves the problem.

clangd output:

The flag `-clang-tidy-checks` is obsolete and ignored.
clangd: Unknown command line argument 'bugprone-*,'.  Try: '/usr/bin/clangd --help'
clangd: Unknown command line argument 'misc-*,'.  Try: '/usr/bin/clangd --help'
clangd: Unknown command line argument 'google-*,'.  Try: '/usr/bin/clangd --help'
clangd: Unknown command line argument 'modernize-*,'.  Try: '/usr/bin/clangd --help'
clangd: Unknown command line argument 'readability-*,'.  Try: '/usr/bin/clangd --help'
clangd: Unknown command line argument 'portability-*'.  Try: '/usr/bin/clangd --help'
[Info  - 4:08:33 PM] Connection to server got closed. Server will restart.
[Error - 4:08:33 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 4:08:33 PM] Clang Language Server client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 

Settings in .vscode/settings.json:

"clangd.arguments": [
    "--all-scopes-completion",
    "--background-index",
    "--clang-tidy",
    "--clang-tidy-checks=performance-*, bugprone-*, misc-*, google-*, modernize-*, readability-*, portability-*",
    "--compile-commands-dir=${workspaceFolder}/.vscode",
    "--completion-parse=auto",
    "--completion-style=detailed",
    "--enable-config",
    "--fallback-style=Microsoft",
    "--function-arg-placeholders=true",
    "--header-insertion-decorators",
    "--header-insertion=never",
    "--log=verbose",
    "--pch-storage=memory",
    "--pretty",
    "--ranking-model=decision_forest",
    "-j=8"
],
HighCommander4 commented 1 week ago

I can reproduce this with 0.1.30, but not with 0.1.29.

I believe the underlying cause is the same as https://github.com/clangd/vscode-clangd/issues/722, which was regressed in 0.1.30 and fixed in 0.1.31.


That said, please note the following in the output:

The flag -clang-tidy-checks is obsolete and ignored.

Even with 0.1.31, the clangd server is going to ignore this flag.

Clang-tidy checks can be enabled using the config file instead, e.g.

Diagnostics:
  ClangTidy:
    Add: [
      performance-*,
      bugprone-*,
      misc-*,
      google-*,
      modernize-*,
      readability-*,
      portability-*
    ]
Carryme1899 commented 1 week ago

Oops! Sorry for the mix-up. This issue’s in version 0.1.30. I have a .clang-tidy file for diagnostics. The flag in settings.json was just left over from an old setup I forgot to remove.

HighCommander4 commented 1 week ago

Great! Then this is just a dupe of #722.

JVApen commented 1 week ago

The problem seems to be with the spaces in the command line option. These are not needed and if you remove them, this also works with version 0.1.30

HighCommander4 commented 6 days ago

The problem seems to be with the spaces in the command line option. These are not needed and if you remove them, this also works with version 0.1.30

Note that there are legitimate use cases for having spaces in command line options, e.g.:

  "clangd.arguments": [
    "--query-driver=C:/Program Files/MinGW/bin/gcc.exe"
  ]

There are users who have things like this in their settings today, and we don't want to break them, so it's important that a revised fix for https://github.com/clangd/vscode-clangd/issues/683 keeps things like this working.