ccls
ccls copied to clipboard
ccls jumps to definitions outside of translation unit with compile_commands.json present
Observed behavior
When multiple files (here .cpp files) are present and are mentioned in the compile_commands.json
file, the `go-to-definition´ will jump into files with objects with equal name (tested here with classes), even though they are completely separate.
Minimal testcase
create a directory called test_case
with the following files:
CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(file1
file1.cpp
)
add_executable(file2
file2.cpp
)
set_target_properties(
file1
file2
PROPERTIES
FOLDER "test_case"
)
file1.cpp
class A {};
int main() {
A a;
}
file2.cpp
class A {};
Compile with cmake .
to get the compile_commands.json
.
Expected behavior
When jumping from A a
via the go to definition
, I would expect it to only jump to the above declaration of the class. However for me (using neovim + native LSP), it opens a quickfix list with both files. Clangd on the other hand only jumps to the declaration in the same file (in my opinion the expected behaviour).
Deleting the entry with file2
in the compile_commands.json
gives the expected behaviour.
System information
- ccls version 0.20210330-12-g74458915
- clang version: 13.0.1
- OS: Arch Linux
- Editor: NVIM v0.8.0-dev+41-g2caf5bbbc
- Language client (and version):