diff options
author | Eric Liu <ioeric@google.com> | 2018-11-28 10:30:42 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-11-28 10:30:42 +0000 |
commit | 4d814a93e5b9d130097413bc027efca9524b36ce (patch) | |
tree | fca975e18d42da20bf4d863182031186674084d0 /clang-tools-extra/clangd/Protocol.h | |
parent | 613c80d22f2428fb7e70754340c6a515e8e8d9c9 (diff) | |
download | bcm5719-llvm-4d814a93e5b9d130097413bc027efca9524b36ce.tar.gz bcm5719-llvm-4d814a93e5b9d130097413bc027efca9524b36ce.zip |
[clangd] Canonicalize file path in URIForFile.
Summary:
File paths in URIForFile can come from index or local AST. Path from
index goes through URI transformation and the final path is resolved by URI
scheme and could be potentially different from the original path. Hence, we
should do the same transformation for all paths. We do this in URIForFile, which
now converts a path to URI and back to a canonicalized path.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54845
llvm-svn: 347739
Diffstat (limited to 'clang-tools-extra/clangd/Protocol.h')
-rw-r--r-- | clang-tools-extra/clangd/Protocol.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h index 692f206edfa..76dcf52a87e 100644 --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -67,9 +67,25 @@ public: } }; +// URI in "file" scheme for a file. struct URIForFile { URIForFile() = default; - explicit URIForFile(std::string AbsPath); + + /// Canonicalizes \p AbsPath via URI. + /// + /// File paths in URIForFile can come from index or local AST. Path from + /// index goes through URI transformation, and the final path is resolved by + /// URI scheme and could potentially be different from the original path. + /// Hence, we do the same transformation for all paths. + /// + /// Files can be referred to by several paths (e.g. in the presence of links). + /// Which one we prefer may depend on where we're coming from. \p TUPath is a + /// hint, and should usually be the main entrypoint file we're processing. + static URIForFile canonicalize(llvm::StringRef AbsPath, + llvm::StringRef TUPath); + + static llvm::Expected<URIForFile> fromURI(const URI &U, + llvm::StringRef HintPath); /// Retrieves absolute path to the file. llvm::StringRef file() const { return File; } @@ -90,6 +106,8 @@ struct URIForFile { } private: + explicit URIForFile(std::string &&File) : File(std::move(File)) {} + std::string File; }; |