diff options
| author | Haojian Wu <hokein@google.com> | 2019-06-25 08:01:46 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2019-06-25 08:01:46 +0000 |
| commit | 92c32574771465606807dea77c928c4d7768bbe9 (patch) | |
| tree | 15d3417ce93b218d9382d50677b4cd797f79b2c3 /clang-tools-extra/clangd/SourceCode.cpp | |
| parent | 303c9861e90cb9a15b15d31fab06d0374d42c9af (diff) | |
[clangd] Cleanup the duplicated getTokenRange.
Summary:
Also lift it to SourceCode.h, so that it can be used in other places
(semantic code highlighting).
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63714
llvm-svn: 364280
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 6c52ca6c01c9..2dcf3d4070ff 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; |
