MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.73k stars 254 forks source link

ccls jumps to definitions outside of translation unit with compile_commands.json present #881

Open jhossbach opened 2 years ago

jhossbach commented 2 years ago

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