[PATCH] D64305: [clangd] Add path mappings functionality
William Wagner via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 18 21:05:51 PST 2019
wwagner19 updated this revision to Diff 229969.
wwagner19 marked 2 inline comments as done.
wwagner19 added a comment.
Awesome! I am not an LLVM committer, so if you could commit on my behalf that'd be great- although I'm not sure how LLVM handles squashing/merging, continuous integration, etc., so please let me know if I need to do anything else (aside from the code of course).
Once again, thanks for all the help - I learned a lot!
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D64305/new/
https://reviews.llvm.org/D64305
Files:
clang-tools-extra/clangd/PathMapping.cpp
Index: clang-tools-extra/clangd/PathMapping.cpp
===================================================================
--- clang-tools-extra/clangd/PathMapping.cpp
+++ clang-tools-extra/clangd/PathMapping.cpp
@@ -128,21 +128,6 @@
llvm::inconvertibleErrorCode());
}
-// Returns whether a path mapping should take place for OrigPath
-// i.e. MappingPath is a proper sub-path of OrigPath
-bool mappingMatches(llvm::StringRef OrigPath, llvm::StringRef MappingPath) {
- namespace path = llvm::sys::path;
- auto OrigPathItr = path::begin(OrigPath, path::Style::posix);
- auto OrigPathEnd = path::end(OrigPath);
- auto MappingPathItr = path::begin(MappingPath, path::Style::posix);
- auto MappingPathEnd = path::end(MappingPath);
- if (std::distance(OrigPathItr, OrigPathEnd) <
- std::distance(MappingPathItr, MappingPathEnd)) {
- return false;
- }
- return std::equal(MappingPathItr, MappingPathEnd, OrigPathItr);
-}
-
// Converts a unix/windows path to the path portion of a file URI
// e.g. "C:\foo" -> "/C:/foo"
llvm::Expected<std::string> parsePath(llvm::StringRef Path) {
@@ -207,11 +192,11 @@
const std::string &To = Dir == PathMapping::Direction::ClientToServer
? Mapping.ServerPath
: Mapping.ClientPath;
- if (mappingMatches(Uri->body(), From)) {
- std::string MappedBody = std::move(Uri->body());
- MappedBody.replace(MappedBody.find(From), From.length(), To);
- auto MappedUri = URI(Uri->scheme(), Uri->authority(), MappedBody.c_str());
- return MappedUri.toString();
+ llvm::StringRef Body = Uri->body();
+ if (Body.consume_front(From) && (Body.empty() || Body.front() == '/')) {
+ std::string MappedBody = (To + Body).str();
+ return URI(Uri->scheme(), Uri->authority(), MappedBody.c_str())
+ .toString();
}
}
return llvm::None;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64305.229969.patch
Type: text/x-patch
Size: 1931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191119/e3c1908e/attachment.bin>
More information about the cfe-commits
mailing list