Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit 9ada854

Browse files
LeszekSwirskijacobdufault
authored andcommitted
Use textEdit for completions
Rather than just inserting text for completions, use textEdit to insert text which replaces the entire identifier, including text after the cursor. Does not remove insertText, so that LSP clients without textEdit support can fall-back to the old behaviour -- otherwise, insertText should be ignored.
1 parent 5f56e5d commit 9ada854

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/messages/text_document_completion.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ struct Handler_TextDocumentCompletion : MessageHandler {
390390
QueueManager::WriteStdout(kMethodType, out);
391391
} else {
392392
ClangCompleteManager::OnComplete callback =
393-
[this, request, existing_completion, is_global_completion,
393+
[this, request, existing_completion, end_pos, is_global_completion,
394394
has_open_paren](const lsRequestId& id,
395395
std::vector<lsCompletionItem> results,
396396
bool is_cached_result) {
@@ -402,6 +402,13 @@ struct Handler_TextDocumentCompletion : MessageHandler {
402402
FilterAndSortCompletionResponse(&out, existing_completion,
403403
has_open_paren,
404404
g_config->completion.filterAndSort);
405+
// Add text edits with the same text, but whose ranges include the
406+
// whole token from start to end.
407+
for (auto& item : out.result.items) {
408+
item.textEdit = lsTextEdit{
409+
lsRange(request->params.position, end_pos), item.insertText};
410+
}
411+
405412
QueueManager::WriteStdout(kMethodType, out);
406413

407414
// Cache completion results.

0 commit comments

Comments
 (0)