[clang] [clang-tools-extra] [clangd] Add InsertReplaceEdit for code completion (PR #187623)
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 28 22:49:51 PDT 2026
HighCommander4 wrote:
> your current changes break every client as far as I can tell (and indeed my vscode stopped giving me code completion when I use the changes). I am not really surprised by this since you change the type in the `CodeCompletion` object of `textEdit`. I am just wondering as of now if there isn't maybe some nicer way of doing this that does not break old clients that have not yet adapted to the new functionality, but for this I do not know if we can change anything in `CodeCompletion` without it breaking.
The intended mechanism here is explained in [this comment](https://github.com/clangd/clangd/issues/2190#issuecomment-2428308260) and the part of the LSP specification referenced there.
Basically, the client has to indicate support for `InsertReplaceEdit` in the client capabilities (done via the `insertReplaceSupport` flag), and the server should only send an `InsertReplacedEdit` in `CompletionItem.textEdit` for clients that indicated this support; for other clients, it should continue sending a `TextEdit`.
This is represented in the LSP spec by the type of `CompletionItem.textEdit` being `TextEdit | InsertReplaceEdit`. I haven't looked at the patch in detail, but using a `std::variant` as the C++ representation seems like barking up the right tree.
https://github.com/llvm/llvm-project/pull/187623
More information about the cfe-commits
mailing list