diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h --- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h +++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h @@ -95,8 +95,8 @@ /// of them can be missing (if the machines are different they don't know each /// other's specifics and will only do one-way translation), but both can not /// be missing at the same time. - llvm::Optional RemoteIndexRoot; - llvm::Optional LocalIndexRoot; + std::string RemoteIndexRoot; + std::string LocalIndexRoot; llvm::BumpPtrAllocator Arena; llvm::UniqueStringSaver Strings; }; diff --git a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp --- a/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp +++ b/clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp @@ -56,17 +56,19 @@ assert(llvm::sys::path::is_absolute(RemoteIndexRoot)); this->RemoteIndexRoot = llvm::sys::path::convert_to_slash( RemoteIndexRoot, llvm::sys::path::Style::windows); - llvm::StringRef Path(*this->RemoteIndexRoot); - if (!Path.endswith(PosixSeparator)) - *this->RemoteIndexRoot += PosixSeparator; + llvm::StringRef Path(this->RemoteIndexRoot); + if (!is_separator(this->RemoteIndexRoot.back(), + llvm::sys::path::Style::posix)) + this->RemoteIndexRoot += PosixSeparator; } if (!LocalIndexRoot.empty()) { assert(llvm::sys::path::is_absolute(LocalIndexRoot)); this->LocalIndexRoot = llvm::sys::path::convert_to_slash( LocalIndexRoot, llvm::sys::path::Style::windows); - llvm::StringRef Path(*this->LocalIndexRoot); - if (!Path.endswith(PosixSeparator)) - *this->LocalIndexRoot += PosixSeparator; + llvm::StringRef Path(this->LocalIndexRoot); + if (!is_separator(this->LocalIndexRoot.back(), + llvm::sys::path::Style::posix)) + this->LocalIndexRoot += PosixSeparator; } assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty()); } @@ -83,7 +85,7 @@ llvm::Expected Marshaller::fromProtobuf(const FuzzyFindRequest *Message) { - assert(RemoteIndexRoot); + assert(!RemoteIndexRoot.empty()); clangd::FuzzyFindRequest Result; Result.Query = Message->query(); for (const auto &Scope : Message->scopes()) @@ -93,7 +95,7 @@ Result.Limit = Message->limit(); Result.RestrictForCodeCompletion = Message->restricted_for_code_completion(); for (const auto &Path : Message->proximity_paths()) { - llvm::SmallString<256> LocalPath = llvm::StringRef(*RemoteIndexRoot); + llvm::SmallString<256> LocalPath = llvm::StringRef(RemoteIndexRoot); llvm::sys::path::append(LocalPath, Path); // FuzzyFindRequest requires proximity paths to have platform-native format // in order for SymbolIndex to process the query correctly. @@ -202,7 +204,7 @@ } FuzzyFindRequest Marshaller::toProtobuf(const clangd::FuzzyFindRequest &From) { - assert(LocalIndexRoot); + assert(!LocalIndexRoot.empty()); FuzzyFindRequest RPCRequest; RPCRequest.set_query(From.Query); for (const auto &Scope : From.Scopes) @@ -213,7 +215,7 @@ RPCRequest.set_restricted_for_code_completion(From.RestrictForCodeCompletion); for (const auto &Path : From.ProximityPaths) { llvm::SmallString<256> RelativePath = llvm::StringRef(Path); - if (llvm::sys::path::replace_path_prefix(RelativePath, *LocalIndexRoot, "")) + if (llvm::sys::path::replace_path_prefix(RelativePath, LocalIndexRoot, "")) RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash( RelativePath, llvm::sys::path::Style::windows)); } @@ -301,20 +303,20 @@ llvm::Expected Marshaller::relativePathToURI(llvm::StringRef RelativePath) { - assert(LocalIndexRoot); + assert(!LocalIndexRoot.empty()); assert(RelativePath == llvm::sys::path::convert_to_slash(RelativePath)); if (RelativePath.empty()) return error("Empty relative path."); if (llvm::sys::path::is_absolute(RelativePath, llvm::sys::path::Style::posix)) return error("RelativePath '{0}' is absolute.", RelativePath); - llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot); + llvm::SmallString<256> FullPath = llvm::StringRef(LocalIndexRoot); llvm::sys::path::append(FullPath, RelativePath); auto Result = URI::createFile(FullPath); return Result.toString(); } llvm::Expected Marshaller::uriToRelativePath(llvm::StringRef URI) { - assert(RemoteIndexRoot); + assert(!RemoteIndexRoot.empty()); auto ParsedURI = URI::parse(URI); if (!ParsedURI) return ParsedURI.takeError(); @@ -326,9 +328,9 @@ if (llvm::sys::path::is_absolute(Path.substr(1), llvm::sys::path::Style::windows)) Result = Path.drop_front(); - if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, "")) + if (!llvm::sys::path::replace_path_prefix(Result, RemoteIndexRoot, "")) return error("File path '{0}' doesn't start with '{1}'.", Result.str(), - *RemoteIndexRoot); + RemoteIndexRoot); assert(Result == llvm::sys::path::convert_to_slash( Result, llvm::sys::path::Style::windows)); return std::string(Result);