Skip to content

Clangd LSP set incorrect root and missing arguments #11617

@wangzw

Description

@wangzw

Description

Currently clangd root directory is detected by NearestRoot(["compile_commands.json", "compile_flags.txt", ".clangd", "CMakeLists.txt", "Makefile"]), which is usually result in the up directory which contains "CMakeLists.txt" or "Makefile" of active file, and is not the root directory of project. Instead, clangd should run in the root directory.

clangd will search from active file directory up to root directory to find .clangd or compile_flags.txt. We do not need to do the search again in LSPServer.

compile_commands.json is important to clangd, clangd will look in the parent directories of active file looking for it, and also in subdirectories named "build/". But it usually fails if one build project out of source tree. Argument of clangd (--compile-commands-dir) can be used to pass the location.

So all we need to do:

  1. set root directory of the project correctly.
  2. pass compile_commands.json using argument.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions