[PATCH] D36095: [clangd] Allow to get vfs::FileSystem used inside codeComplete.

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 31 09:58:18 PDT 2017


ilya-biryukov created this revision.

This is useful for managing lifetime of VFS-based caches.


https://reviews.llvm.org/D36095

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h


Index: clangd/ClangdServer.h
===================================================================
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -175,10 +175,14 @@
   /// will be scheduled and a draft for \p File will not be updated.
   /// If \p OverridenContents is None, contents of the current draft for \p File
   /// will be used.
-  /// This method should only be called for currently tracked files.
+  /// If \p UsedFS is non-null, it will be overwritten by vfs::FileSystem used
+  /// for completion.
+  /// This method should only be called for currently tracked
+  /// files.
   Tagged<std::vector<CompletionItem>>
   codeComplete(PathRef File, Position Pos,
-               llvm::Optional<StringRef> OverridenContents = llvm::None);
+               llvm::Optional<StringRef> OverridenContents = llvm::None,
+               IntrusiveRefCntPtr<vfs::FileSystem> *UsedFS = nullptr);
   /// Get definition of symbol at a specified \p Line and \p Column in \p File.
   Tagged<std::vector<Location>> findDefinitions(PathRef File, Position Pos);
 
Index: clangd/ClangdServer.cpp
===================================================================
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -192,7 +192,8 @@
 
 Tagged<std::vector<CompletionItem>>
 ClangdServer::codeComplete(PathRef File, Position Pos,
-                           llvm::Optional<StringRef> OverridenContents) {
+                           llvm::Optional<StringRef> OverridenContents,
+                           IntrusiveRefCntPtr<vfs::FileSystem> *UsedFS) {
   std::string DraftStorage;
   if (!OverridenContents) {
     auto FileContents = DraftMgr.getDraft(File);
@@ -203,8 +204,11 @@
     OverridenContents = DraftStorage;
   }
 
-  std::vector<CompletionItem> Result;
   auto TaggedFS = FSProvider.getTaggedFileSystem(File);
+  if (UsedFS)
+    *UsedFS = TaggedFS.Value;
+
+  std::vector<CompletionItem> Result;
   Units.runOnUnitWithoutReparse(File, *OverridenContents, ResourceDir, CDB,
                                 PCHs, TaggedFS.Value, [&](ClangdUnit &Unit) {
                                   Result = Unit.codeComplete(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36095.108945.patch
Type: text/x-patch
Size: 2129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170731/47c5211a/attachment.bin>


More information about the cfe-commits mailing list