[clang] [clang-tools-extra] [clangd] Add InsertReplaceEdit for code completion (PR #187623)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 1 12:19:50 PDT 2026
argothiel wrote:
Hi, @timon-ul,
Thank you for the careful review!
Regarding the `findTokenAfterCompletionPoint` method, I considered it, but the semantics is slightly different, even apart from the Unicode handling. The biggest issues are:
- it ignores whitespaces, so it will keep parsing in cases like `vec.^ abc`.
- if the next token starts with a digit, it will greedily parse it as a number, like `vec.^1abc.def` should be parsed as `vec.[[1abc]]`, not `vec.[[1abc.def]]` (and with an incorrect token kind).
As for the parenthesis suppression, I agree it would make sense to do it. I think I was too cautious about touching the existing `NextTokenKind` detection, but now I believe I can give it a try, and it's not that risky. The change is well-scoped - generalizing the existing `NextTokenKind` lookup to lex past the identifier suffix instead of past the cursor, plus a couple of tests.
Note, that the completed text must be the same for insert and replace, so fixing the replace mode would also change the existing insert behavior, i.e.:
`test^ing(int i)` currently resolves to `testing(int i)ing(int i)` in the insert mode and `testing(int i)(int i)` in the replace mode;
after the change it would resolve to `testinging(int i)` in the insert mode, and `testing(int i)` in the replace mode. So maybe it's worth coding as a follow-up?
https://github.com/llvm/llvm-project/pull/187623
More information about the cfe-commits
mailing list