ioeric created this revision. ioeric added a reviewer: ilya-biryukov. Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.
This allows implementations like different symbol indexes to know what the current active file is. For example, some customized index implementation might decide to only return results for some files. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D50446 Files: clangd/ClangdServer.cpp clangd/Context.cpp clangd/Context.h 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<llvm::StringRef> 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<llvm::StringRef> kActiveFile; + } // namespace clangd } // namespace clang 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<std::vector<Location>> CB) { - auto Action = [Pos, this](Callback<std::vector<Location>> CB, - llvm::Expected<InputsAndAST> InpAST) { + std::string ActiveFile = File; + auto Action = [Pos, ActiveFile, this](Callback<std::vector<Location>> CB, + llvm::Expected<InputsAndAST> 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<llvm::StringRef> 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<llvm::StringRef> kActiveFile; + } // namespace clangd } // namespace clang 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<std::vector<Location>> CB) { - auto Action = [Pos, this](Callback<std::vector<Location>> CB, - llvm::Expected<InputsAndAST> InpAST) { + std::string ActiveFile = File; + auto Action = [Pos, ActiveFile, this](Callback<std::vector<Location>> CB, + llvm::Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); + + WithContextValue WithFileName(kActiveFile, ActiveFile); CB(clangd::findDefinitions(InpAST->AST, Pos, Index)); };
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits