aboutsummaryrefslogtreecommitdiff
path: root/clangd/SourceCode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clangd/SourceCode.cpp')
-rw-r--r--clangd/SourceCode.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/clangd/SourceCode.cpp b/clangd/SourceCode.cpp
index 50a7f4e6..88ec2c95 100644
--- a/clangd/SourceCode.cpp
+++ b/clangd/SourceCode.cpp
@@ -8,9 +8,13 @@
//===----------------------------------------------------------------------===//
#include "SourceCode.h"
+#include "Logger.h"
+#include "clang/AST/ASTContext.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
namespace clang {
namespace clangd {
@@ -181,5 +185,28 @@ std::vector<TextEdit> replacementsToEdits(StringRef Code,
return Edits;
}
+llvm::Optional<std::string>
+getAbsoluteFilePath(const FileEntry *F, const SourceManager &SourceMgr) {
+ SmallString<64> FilePath = F->tryGetRealPathName();
+ if (FilePath.empty())
+ FilePath = F->getName();
+ if (!llvm::sys::path::is_absolute(FilePath)) {
+ if (!SourceMgr.getFileManager().makeAbsolutePath(FilePath)) {
+ log("Could not turn relative path to absolute: {0}", FilePath);
+ return llvm::None;
+ }
+ }
+ return FilePath.str().str();
+}
+
+TextEdit toTextEdit(const FixItHint &FixIt, const SourceManager &M,
+ const LangOptions &L) {
+ TextEdit Result;
+ Result.range =
+ halfOpenToRange(M, Lexer::makeFileCharRange(FixIt.RemoveRange, M, L));
+ Result.newText = FixIt.CodeToInsert;
+ return Result;
+}
+
} // namespace clangd
} // namespace clang