From c343437aea1db5bc7cb80132b56cd0f92233e4f4 Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Fri, 8 Dec 2023 11:32:08 +0100 Subject: [PATCH] Handle replaceStart/replaceEnd in completion proposal Fixes https://github.com/microsoft/java-debug/issues/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()` --- .../plugin/internal/CompletionProposalRequestor.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/CompletionProposalRequestor.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/CompletionProposalRequestor.java index 1df752f24..0f2a0bf54 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/CompletionProposalRequestor.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/CompletionProposalRequestor.java @@ -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 $;