diff options
Diffstat (limited to 'clang-tools-extra/clangd/SourceCode.cpp')
-rw-r--r-- | clang-tools-extra/clangd/SourceCode.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 6c52ca6c01c..2dcf3d4070f 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -196,6 +196,17 @@ Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc) { return P; } +llvm::Optional<Range> getTokenRange(const SourceManager &SM, + const LangOptions &LangOpts, + SourceLocation TokLoc) { + if (!TokLoc.isValid()) + return llvm::None; + SourceLocation End = Lexer::getLocForEndOfToken(TokLoc, 0, SM, LangOpts); + if (!End.isValid()) + return llvm::None; + return halfOpenToRange(SM, CharSourceRange::getCharRange(TokLoc, End)); +} + bool isValidFileRange(const SourceManager &Mgr, SourceRange R) { if (!R.getBegin().isValid() || !R.getEnd().isValid()) return false; |