forked from OSchip/llvm-project
[clangd] Add a filename parameter to FileSystemProvider.
Reviewers: krasimir Reviewed By: krasimir Subscribers: klimek, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D34151 llvm-svn: 305376
This commit is contained in:
parent
ad270ec314
commit
af0c04b30b
|
@ -59,7 +59,7 @@ Position clangd::offsetToPosition(StringRef Code, size_t Offset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
|
Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
|
||||||
RealFileSystemProvider::getTaggedFileSystem() {
|
RealFileSystemProvider::getTaggedFileSystem(PathRef File) {
|
||||||
return make_tagged(vfs::getRealFileSystem(), VFSTag());
|
return make_tagged(vfs::getRealFileSystem(), VFSTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ void ClangdServer::addDocument(PathRef File, StringRef Contents) {
|
||||||
|
|
||||||
assert(FileContents.Draft &&
|
assert(FileContents.Draft &&
|
||||||
"No contents inside a file that was scheduled for reparse");
|
"No contents inside a file that was scheduled for reparse");
|
||||||
auto TaggedFS = FSProvider.getTaggedFileSystem();
|
auto TaggedFS = FSProvider.getTaggedFileSystem(FileStr);
|
||||||
Units.runOnUnit(
|
Units.runOnUnit(
|
||||||
FileStr, *FileContents.Draft, CDB, PCHs, TaggedFS.Value,
|
FileStr, *FileContents.Draft, CDB, PCHs, TaggedFS.Value,
|
||||||
[&](ClangdUnit const &Unit) {
|
[&](ClangdUnit const &Unit) {
|
||||||
|
@ -197,7 +197,7 @@ ClangdServer::codeComplete(PathRef File, Position Pos,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CompletionItem> Result;
|
std::vector<CompletionItem> Result;
|
||||||
auto TaggedFS = FSProvider.getTaggedFileSystem();
|
auto TaggedFS = FSProvider.getTaggedFileSystem(File);
|
||||||
// It would be nice to use runOnUnitWithoutReparse here, but we can't
|
// It would be nice to use runOnUnitWithoutReparse here, but we can't
|
||||||
// guarantee the correctness of code completion cache here if we don't do the
|
// guarantee the correctness of code completion cache here if we don't do the
|
||||||
// reparse.
|
// reparse.
|
||||||
|
|
|
@ -82,16 +82,21 @@ public:
|
||||||
class FileSystemProvider {
|
class FileSystemProvider {
|
||||||
public:
|
public:
|
||||||
virtual ~FileSystemProvider() = default;
|
virtual ~FileSystemProvider() = default;
|
||||||
|
/// Called by ClangdServer to obtain a vfs::FileSystem to be used for parsing.
|
||||||
|
/// Name of the file that will be parsed is passed in \p File.
|
||||||
|
///
|
||||||
/// \return A filesystem that will be used for all file accesses in clangd.
|
/// \return A filesystem that will be used for all file accesses in clangd.
|
||||||
/// A Tag returned by this method will be propagated to all results of clangd
|
/// A Tag returned by this method will be propagated to all results of clangd
|
||||||
/// that will use this filesystem.
|
/// that will use this filesystem.
|
||||||
virtual Tagged<IntrusiveRefCntPtr<vfs::FileSystem>> getTaggedFileSystem() = 0;
|
virtual Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
|
||||||
|
getTaggedFileSystem(PathRef File) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RealFileSystemProvider : public FileSystemProvider {
|
class RealFileSystemProvider : public FileSystemProvider {
|
||||||
public:
|
public:
|
||||||
/// \return getRealFileSystem() tagged with default tag, i.e. VFSTag()
|
/// \return getRealFileSystem() tagged with default tag, i.e. VFSTag()
|
||||||
Tagged<IntrusiveRefCntPtr<vfs::FileSystem>> getTaggedFileSystem() override;
|
Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
|
||||||
|
getTaggedFileSystem(PathRef File) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClangdServer;
|
class ClangdServer;
|
||||||
|
|
|
@ -172,9 +172,13 @@ public:
|
||||||
|
|
||||||
class MockFSProvider : public FileSystemProvider {
|
class MockFSProvider : public FileSystemProvider {
|
||||||
public:
|
public:
|
||||||
Tagged<IntrusiveRefCntPtr<vfs::FileSystem>> getTaggedFileSystem() override {
|
Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
|
||||||
|
getTaggedFileSystem(PathRef File) override {
|
||||||
IntrusiveRefCntPtr<vfs::InMemoryFileSystem> MemFS(
|
IntrusiveRefCntPtr<vfs::InMemoryFileSystem> MemFS(
|
||||||
new vfs::InMemoryFileSystem);
|
new vfs::InMemoryFileSystem);
|
||||||
|
if (ExpectedFile)
|
||||||
|
EXPECT_EQ(*ExpectedFile, File);
|
||||||
|
|
||||||
for (auto &FileAndContents : Files)
|
for (auto &FileAndContents : Files)
|
||||||
MemFS->addFile(FileAndContents.first(), time_t(),
|
MemFS->addFile(FileAndContents.first(), time_t(),
|
||||||
llvm::MemoryBuffer::getMemBuffer(FileAndContents.second,
|
llvm::MemoryBuffer::getMemBuffer(FileAndContents.second,
|
||||||
|
@ -186,6 +190,7 @@ public:
|
||||||
return make_tagged(OverlayFS, Tag);
|
return make_tagged(OverlayFS, Tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::Optional<SmallString<32>> ExpectedFile;
|
||||||
llvm::StringMap<std::string> Files;
|
llvm::StringMap<std::string> Files;
|
||||||
VFSTag Tag = VFSTag();
|
VFSTag Tag = VFSTag();
|
||||||
};
|
};
|
||||||
|
@ -248,7 +253,10 @@ protected:
|
||||||
FileWithContents.second;
|
FileWithContents.second;
|
||||||
|
|
||||||
auto SourceFilename = getVirtualTestFilePath(SourceFileRelPath);
|
auto SourceFilename = getVirtualTestFilePath(SourceFileRelPath);
|
||||||
|
|
||||||
|
FS.ExpectedFile = SourceFilename;
|
||||||
Server.addDocument(SourceFilename, SourceContents);
|
Server.addDocument(SourceFilename, SourceContents);
|
||||||
|
|
||||||
auto Result = dumpASTWithoutMemoryLocs(Server, SourceFilename);
|
auto Result = dumpASTWithoutMemoryLocs(Server, SourceFilename);
|
||||||
EXPECT_EQ(ExpectErrors, DiagConsumer.hadErrorInLastDiags());
|
EXPECT_EQ(ExpectErrors, DiagConsumer.hadErrorInLastDiags());
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -307,6 +315,7 @@ int b = a;
|
||||||
|
|
||||||
FS.Files[FooH] = "int a;";
|
FS.Files[FooH] = "int a;";
|
||||||
FS.Files[FooCpp] = SourceContents;
|
FS.Files[FooCpp] = SourceContents;
|
||||||
|
FS.ExpectedFile = FooCpp;
|
||||||
|
|
||||||
Server.addDocument(FooCpp, SourceContents);
|
Server.addDocument(FooCpp, SourceContents);
|
||||||
auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
|
auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
|
||||||
|
@ -342,6 +351,7 @@ int b = a;
|
||||||
|
|
||||||
FS.Files[FooH] = "int a;";
|
FS.Files[FooH] = "int a;";
|
||||||
FS.Files[FooCpp] = SourceContents;
|
FS.Files[FooCpp] = SourceContents;
|
||||||
|
FS.ExpectedFile = FooCpp;
|
||||||
|
|
||||||
Server.addDocument(FooCpp, SourceContents);
|
Server.addDocument(FooCpp, SourceContents);
|
||||||
auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
|
auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
|
||||||
|
@ -371,8 +381,9 @@ TEST_F(ClangdVFSTest, CheckVersions) {
|
||||||
auto FooCpp = getVirtualTestFilePath("foo.cpp");
|
auto FooCpp = getVirtualTestFilePath("foo.cpp");
|
||||||
const auto SourceContents = "int a;";
|
const auto SourceContents = "int a;";
|
||||||
FS.Files[FooCpp] = SourceContents;
|
FS.Files[FooCpp] = SourceContents;
|
||||||
FS.Tag = "123";
|
FS.ExpectedFile = FooCpp;
|
||||||
|
|
||||||
|
FS.Tag = "123";
|
||||||
Server.addDocument(FooCpp, SourceContents);
|
Server.addDocument(FooCpp, SourceContents);
|
||||||
EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag);
|
EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag);
|
||||||
EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS.Tag);
|
EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS.Tag);
|
||||||
|
@ -419,6 +430,7 @@ int b = ;
|
||||||
// miss).
|
// miss).
|
||||||
Position CompletePos = {2, 8};
|
Position CompletePos = {2, 8};
|
||||||
FS.Files[FooCpp] = SourceContents;
|
FS.Files[FooCpp] = SourceContents;
|
||||||
|
FS.ExpectedFile = FooCpp;
|
||||||
|
|
||||||
Server.addDocument(FooCpp, SourceContents);
|
Server.addDocument(FooCpp, SourceContents);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue