ilya-biryukov added inline comments.
================ Comment at: clang-tools-extra/clangd/SourceCode.cpp:286 - Before = Lexer::GetBeginningOfToken(Before, SM, LangOpts); - Token Tok; - if (Before.isValid() && - !Lexer::getRawToken(Before, Tok, SM, LangOpts, false) && - Tok.is(tok::raw_identifier)) - return Before; // Case 2. - return InputLoc; // Case 1 or 3. + Token CurrentTok; + SourceLocation CurrentTokBeginning = ---------------- If we use `IgnoreWhitespace = false`, I think we can simplify to: ``` // Location in the middle of some token. if (BeforeLoc == CurrentLoc) return CurrentLoc; // Whitespace is not interesting. if (CurrentTok.Kind == tok::whitespace) return BeforeTok; if (BeforeTok.Kind == tok::whitespace) return CurrentTok; // The cursor is at token boundary, i.e. `Before^Current`. // Prefer identifiers to other tokens. if (CurrentTok.Kind == tok::raw_identifier) return CurrentLoc; if (BeforeTok.Kind == tok::raw_identifier) return BeforeLoc; // And overloaded operators to other tokens. if (isOperator(CurrentTok.Kind)) return CurrentLoc; if (isOperator(BeforeTok.Kind)) return BeforeLoc; return CurrentLoc; ``` That would have the same semantics, but is arguably simpler. WDYT? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67695/new/ https://reviews.llvm.org/D67695 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits