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

Commit

Permalink
Use textEdit for completions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LeszekSwirski authored and jacobdufault committed Apr 21, 2018
1 parent 5f56e5d commit 9ada854
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/messages/text_document_completion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ struct Handler_TextDocumentCompletion : MessageHandler {
QueueManager::WriteStdout(kMethodType, out);
} else {
ClangCompleteManager::OnComplete callback =
[this, request, existing_completion, is_global_completion,
[this, request, existing_completion, end_pos, is_global_completion,
has_open_paren](const lsRequestId& id,
std::vector<lsCompletionItem> results,
bool is_cached_result) {
Expand All @@ -402,6 +402,13 @@ struct Handler_TextDocumentCompletion : MessageHandler {
FilterAndSortCompletionResponse(&out, existing_completion,
has_open_paren,
g_config->completion.filterAndSort);
// Add text edits with the same text, but whose ranges include the
// whole token from start to end.
for (auto& item : out.result.items) {
item.textEdit = lsTextEdit{
lsRange(request->params.position, end_pos), item.insertText};
}

QueueManager::WriteStdout(kMethodType, out);

// Cache completion results.
Expand Down

0 comments on commit 9ada854

Please sign in to comment.