- Fixed diagnostics where zero width inserted ranges were being used instead of the whole token
- Added unit tests
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Mostly LG, just a few re-orderings to make code more readable and get rid of redundant Lexer calls.
clang-tools-extra/clangd/Diagnostics.cpp | ||
---|---|---|
108 ↗ | (On Diff #204351) | since we are going to lex again in case of R.isValid(), you can get rid of this lexer call. |
109 ↗ | (On Diff #204351) | let's change this condition to rather check for Lexer::getRawToken succeeded and underlying token isNot(tok::comment). |
111 ↗ | (On Diff #204351) | LLVM style uses UpperCammelCase for variable names. so this should be something like, Token Tok;, same for the bool below. |
119 ↗ | (On Diff #204351) | the FallbackRange(if set) and CharSourceRange::getCharRange(Loc); are the same. So you can get rid of FallbackRange and merge the last two branches of this conditional. |
LGTM, thanks!
Also please make sure you've clang-formatted the code before you land this.
clang-tools-extra/clangd/Diagnostics.cpp | ||
---|---|---|
94 ↗ | (On Diff #204467) | FallbackRange is not returned anymore, you can safely delete it. |
110 ↗ | (On Diff #204467) | I think you can simply it further by: // Fallback to zero-width range at diagnostic location. auto R = CharSourceRange::getCharRange(Loc); Token Tok; // For non-comment tokens, use token at the location. if (!Lexer::getRawToken(Loc, Tok, M, L, true) && Tok.isNot(tok::comment)) R = CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getEndLoc()); return halfOpenToRange(M, R); |