Index: clangd/ClangdServer.cpp =================================================================== --- clangd/ClangdServer.cpp +++ clangd/ClangdServer.cpp @@ -159,6 +159,7 @@ auto PreambleData = IP->Preamble; + WithContextValue WithFileName(kActiveFile, File); // FIXME(ibiryukov): even if Preamble is non-null, we may want to check // both the old and the new version in case only one of them matches. CodeCompleteResult Result = clangd::codeComplete( @@ -297,10 +298,13 @@ void ClangdServer::findDefinitions(PathRef File, Position Pos, Callback> CB) { - auto Action = [Pos, this](Callback> CB, - llvm::Expected InpAST) { + std::string ActiveFile = File; + auto Action = [Pos, ActiveFile, this](Callback> CB, + llvm::Expected InpAST) { if (!InpAST) return CB(InpAST.takeError()); + + WithContextValue WithFileName(kActiveFile, ActiveFile); CB(clangd::findDefinitions(InpAST->AST, Pos, Index)); }; Index: clangd/Context.h =================================================================== --- clangd/Context.h +++ clangd/Context.h @@ -217,6 +217,11 @@ WithContext Restore; }; +// The active file in a clangd request (e.g. file in which code completion or +// go-to-definition is triggered). This is not always set and has to be set in +// individual requests. +extern const clang::clangd::Key kActiveFile; + } // namespace clangd } // namespace clang Index: clangd/Context.cpp =================================================================== --- clangd/Context.cpp +++ clangd/Context.cpp @@ -32,5 +32,7 @@ return Replacement; } +const clang::clangd::Key kActiveFile; + } // namespace clangd } // namespace clang