Index: unittests/clangd/XRefsTests.cpp =================================================================== --- unittests/clangd/XRefsTests.cpp +++ unittests/clangd/XRefsTests.cpp @@ -335,6 +335,72 @@ SourceAnnotations.range()})); } +TEST(GoToDefinition, TestSimon) { + Annotations FirstHSrc(R"cpp( +static inline void +bob() +{ +} +)cpp"); + Annotations FirstCppSrc(R"cpp( +#include "first.h" + +void bar(); + +void foo() +{ + b^ob(); +} + +int main() +{ + bar(); + foo(); +} +)cpp"); + + StringRef CompileCommandsJson = R"json( +[ + { + "arguments": ["c++", "-c", "-g3", "-O0", "-o", "second.o", "../src/second.cpp"], + "directory": "/home/emaisin/src/ls-interact/cpp-test/build", + "file": "../src/second.cpp" + }, + { + "arguments": ["c++", "-c", "-g3", "-O0", "-o", "first.o", "../src/first.cpp"], + "directory": "/home/emaisin/src/ls-interact/cpp-test/build", + "file": "../src/first.cpp" + } +] + +)json"; + + MockFSProvider FS; + + FS.Files["/home/emaisin/src/ls-interact/cpp-test/src/first.h"] = FirstHSrc.code(); + FS.Files["/home/emaisin/src/ls-interact/cpp-test/src/first.cpp"] = FirstCppSrc.code(); + FS.Files["/home/emaisin/src/ls-interact/cpp-test/build/compile_commands.json"] = CompileCommandsJson; + + DirectoryBasedGlobalCompilationDatabase CDB (Path("/home/emaisin/src/ls-interact/cpp-test/build")); + IgnoreDiagnostics DiagConsumer; + ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest()); + + runAddDocument(Server, "/home/emaisin/src/ls-interact/cpp-test/src/first.cpp", FirstCppSrc.code()); + + llvm::Expected> Locations = runFindDefinitions(Server, "/home/emaisin/src/ls-interact/cpp-test/src/first.cpp", FirstCppSrc.point()); + + EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error"; + + fprintf(stderr, "\n\n"); + + for (const Location &L : *Locations) { + fprintf(stderr, "%s %d:%d to %d:%d", L.uri.file().data(), + L.range.start.line , L.range.start.character, L.range.end.line, L.range.end.character); + } + + fprintf(stderr, "\n\n"); +} + TEST(Hover, All) { struct OneTest { StringRef Input;