summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/SourceCode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd/SourceCode.cpp')
-rw-r--r--clang-tools-extra/clangd/SourceCode.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp
index 1d8ceb2cad2..1f89ad6a6e4 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -141,6 +141,16 @@ Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc) {
return P;
}
+llvm::Expected<SourceLocation> sourceLocationInMainFile(const SourceManager &SM,
+ Position P) {
+ llvm::StringRef Code = SM.getBuffer(SM.getMainFileID())->getBuffer();
+ auto Offset =
+ positionToOffset(Code, P, /*AllowColumnBeyondLineLength=*/false);
+ if (!Offset)
+ return Offset.takeError();
+ return SM.getLocForStartOfFile(SM.getMainFileID()).getLocWithOffset(*Offset);
+}
+
Range halfOpenToRange(const SourceManager &SM, CharSourceRange R) {
// Clang is 1-based, LSP uses 0-based indexes.
Position Begin = sourceLocToPosition(SM, R.getBegin());
OpenPOWER on IntegriCloud