Skip to content

Commit

Permalink
Handle replaceStart/replaceEnd in completion proposal
Browse files Browse the repository at this point in the history
Fixes microsoft#524
Ensures completion text can be appended by clients

E.g.

For `com.|` the completion proposal has:

    completion: com.sun.jndi.ldap.pool
    completionLocation: 3
    replaceEnd: 4
    replaceStart: 0

`insertText` will be `sun.jndi.ldap.pool`

For `List.|` the completion proposal has:

    completion: of()
    completionLocation: 4
    replaceStart: 5
    replaceEnd: 5

`insertText` will be `of()`
  • Loading branch information
mfussenegger committed Dec 8, 2023
1 parent 7303dcd commit c343437
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ public CompletionItem toCompletionItem(CompletionProposal proposal, int index) {
data.put(CompletionResolveHandler.DATA_FIELD_REQUEST_ID, String.valueOf(response.getId()));
data.put(CompletionResolveHandler.DATA_FIELD_PROPOSAL_ID, String.valueOf(index));
$.setData(data);

this.descriptionProvider.updateDescription(proposal, $);
// Use fully qualified name as needed.
$.setInsertText(String.valueOf(proposal.getCompletion()));
String insertText = String.valueOf(proposal.getCompletion());
int suffix = proposal.getReplaceEnd() - proposal.getReplaceStart();
if (suffix > 0) {
$.setInsertText(insertText.substring(suffix));
} else {
$.setInsertText(insertText);
}
adjustCompleteItem($);
$.setSortText(SortTextHelper.computeSortText(proposal));
return $;
Expand Down

0 comments on commit c343437

Please sign in to comment.