Skip to content

Commit

Permalink
[clangd] Allow to get vfs::FileSystem used inside codeComplete.
Browse files Browse the repository at this point in the history
Summary: This is useful for managing lifetime of VFS-based caches.

Reviewers: bkramer, krasimir

Reviewed By: bkramer

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D36095

llvm-svn: 309585
  • Loading branch information
ilya-biryukov committed Jul 31, 2017
1 parent 7b89ab5 commit ed99e4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions clang-tools-extra/clangd/ClangdServer.cpp
Expand Up @@ -192,7 +192,8 @@ void ClangdServer::forceReparse(PathRef File) {

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);
Expand All @@ -203,8 +204,11 @@ ClangdServer::codeComplete(PathRef File, Position Pos,
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(
Expand Down
8 changes: 6 additions & 2 deletions clang-tools-extra/clangd/ClangdServer.h
Expand Up @@ -175,10 +175,14 @@ class ClangdServer {
/// 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);

Expand Down

0 comments on commit ed99e4c

Please sign in to comment.