[PATCH] D50446: [clangd] Record the currently active file in context for codeCompletion and findDefinitions.

Eric Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 8 06:17:55 PDT 2018


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));
   };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50446.159701.patch
Type: text/x-patch
Size: 1922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180808/bbce31be/attachment-0001.bin>


More information about the cfe-commits mailing list