Skip to content

Commit 94dcce9

Browse files
committed
fix order of snippets
1 parent c485b11 commit 94dcce9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CodeActionResolveHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.ArrayList;
1717
import java.util.Iterator;
1818
import java.util.List;
19+
import java.util.ListIterator;
1920
import java.util.Map;
2021

2122
import org.eclipse.core.runtime.CoreException;
@@ -95,8 +96,6 @@ private static final void addSnippetsIfApplicable(LinkedCorrectionProposalCore p
9596
ProposalCore[] proposalList = group.getProposals();
9697
PositionInformation[] positionList = group.getPositions();
9798
StringBuilder snippet = new StringBuilder();
98-
snippet.append(SNIPPET_PREFIX);
99-
snippet.append(snippetNumber);
10099
snippet.append(SNIPPET_CHOICE_INDICATOR);
101100
if (proposalList.length > 1) {
102101
for (int i = 0; i < positionList.length; i++) {
@@ -115,11 +114,10 @@ private static final void addSnippetsIfApplicable(LinkedCorrectionProposalCore p
115114
}
116115
}
117116
// If snippet is empty or only has one choice, ignore this group
118-
if (snippet.toString().equals(SNIPPET_PREFIX) || snippet.indexOf(SNIPPET_CHOICE_DELIMITER) == -1) {
117+
if (snippet.toString().equals(String.valueOf(SNIPPET_CHOICE_INDICATOR)) || snippet.indexOf(SNIPPET_CHOICE_DELIMITER) == -1) {
119118
break;
120119
}
121120
snippet.append(SNIPPET_CHOICE_POSTFIX);
122-
snippetNumber++;
123121
}
124122
snippets.add(new Triple(snippet.toString(), offset, length));
125123
}
@@ -128,6 +126,12 @@ private static final void addSnippetsIfApplicable(LinkedCorrectionProposalCore p
128126
if (!snippets.isEmpty()) {
129127
// Sort snippets in descending order based on offset, so that the edits are applied in an order that does not alter the offset of later edits
130128
snippets.sort(null);
129+
ListIterator<Triple> li = snippets.listIterator(snippets.size());
130+
while (li.hasPrevious()) {
131+
Triple element = li.previous();
132+
element.snippet = SNIPPET_PREFIX + snippetNumber + element.snippet;
133+
snippetNumber++;
134+
}
131135
for (int i = 0; i < edit.getDocumentChanges().size(); i++) {
132136
if (edit.getDocumentChanges().get(i).isLeft()) {
133137
List<TextEdit> edits = edit.getDocumentChanges().get(i).getLeft().getEdits();

0 commit comments

Comments
 (0)