[clangd] Add more error details on the remote index server side

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D85502
This commit is contained in:
Kirill Bobyrev 2020-08-09 22:07:26 +02:00
parent 86cc722687
commit 836f937a1f
No known key found for this signature in database
GPG Key ID: 2307C055C8384FA0
1 changed files with 11 additions and 3 deletions

View File

@ -23,6 +23,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/StringSaver.h"
@ -303,7 +304,8 @@ Marshaller::relativePathToURI(llvm::StringRef RelativePath) {
if (RelativePath.empty())
return makeStringError("Empty relative path.");
if (llvm::sys::path::is_absolute(RelativePath))
return makeStringError("RelativePath is absolute.");
return makeStringError(
llvm::formatv("RelativePath '{0}' is absolute.", RelativePath).str());
llvm::SmallString<256> FullPath = llvm::StringRef(*LocalIndexRoot);
llvm::sys::path::append(FullPath, RelativePath);
auto Result = URI::createFile(FullPath);
@ -316,10 +318,16 @@ llvm::Expected<std::string> Marshaller::uriToRelativePath(llvm::StringRef URI) {
if (!ParsedURI)
return ParsedURI.takeError();
if (ParsedURI->scheme() != "file")
return makeStringError("Can not use URI schemes other than file.");
return makeStringError(
llvm::formatv("Can not use URI schemes other than file, given: '{0}'.",
URI)
.str());
llvm::SmallString<256> Result = ParsedURI->body();
if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
return makeStringError("File path doesn't start with RemoteIndexRoot.");
return makeStringError(
llvm::formatv("File path '{0}' doesn't start with '{1}'.", Result.str(),
*RemoteIndexRoot)
.str());
// Make sure the result has UNIX slashes.
return llvm::sys::path::convert_to_slash(Result,
llvm::sys::path::Style::posix);