diff options
| author | Eric Liu <ioeric@google.com> | 2018-06-15 08:55:00 +0000 |
|---|---|---|
| committer | Eric Liu <ioeric@google.com> | 2018-06-15 08:55:00 +0000 |
| commit | 13e503f68a0ec42807c46aa76540b3eb06450b9d (patch) | |
| tree | a4ad95a19d776794ffa1226b0ffc76fe70548b1f /clang-tools-extra/unittests/clangd/TestFS.cpp | |
| parent | 0651eb1b31ce0ab3e2dd88947f38de7e3ebc8bc9 (diff) | |
| download | bcm5719-llvm-13e503f68a0ec42807c46aa76540b3eb06450b9d.tar.gz bcm5719-llvm-13e503f68a0ec42807c46aa76540b3eb06450b9d.zip | |
[clangd] Customizable URI schemes for dynamic index.
Summary:
This allows dynamic index to have consistent URI schemes with the
static index which can have customized URI schemes, which would make file
proximity scoring based on URIs easier.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47931
llvm-svn: 334809
Diffstat (limited to 'clang-tools-extra/unittests/clangd/TestFS.cpp')
| -rw-r--r-- | clang-tools-extra/unittests/clangd/TestFS.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clang-tools-extra/unittests/clangd/TestFS.cpp b/clang-tools-extra/unittests/clangd/TestFS.cpp index 9020c6da63b..000d55854dc 100644 --- a/clang-tools-extra/unittests/clangd/TestFS.cpp +++ b/clang-tools-extra/unittests/clangd/TestFS.cpp @@ -7,7 +7,11 @@ // //===----------------------------------------------------------------------===// #include "TestFS.h" +#include "URI.h" +#include "clang/AST/DeclCXX.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Errc.h" +#include "llvm/Support/Path.h" #include "gtest/gtest.h" namespace clang { @@ -62,5 +66,38 @@ std::string testPath(PathRef File) { return Path.str(); } +/// unittest: is a scheme that refers to files relative to testRoot() +class TestScheme : public URIScheme { +public: + static const char *Scheme; + + llvm::Expected<std::string> + getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body, + llvm::StringRef HintPath) const override { + assert(HintPath.startswith(testRoot())); + llvm::SmallString<16> Path(Body.begin(), Body.end()); + llvm::sys::path::native(Path); + return testPath(Path); + } + + llvm::Expected<URI> + uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override { + llvm::StringRef Body = AbsolutePath; + if (!Body.consume_front(testRoot())) + return llvm::make_error<llvm::StringError>( + AbsolutePath + "does not start with " + testRoot(), + llvm::inconvertibleErrorCode()); + + return URI(Scheme, /*Authority=*/"", + llvm::sys::path::convert_to_slash(Body)); + } +}; + +const char *TestScheme::Scheme = "unittest"; + +static URISchemeRegistry::Add<TestScheme> X(TestScheme::Scheme, "Test schema"); + +volatile int UnittestSchemeAnchorSource = 0; + } // namespace clangd } // namespace clang |

