Skip to content

Commit

Permalink
fix for bootstrap properties code completion replacing existing line
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvenmany-ibm committed Oct 7, 2024
1 parent c8dc268 commit d513825
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionItemKind;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.InsertReplaceEdit;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.MarkupKind;
import org.eclipse.lsp4j.Position;
Expand All @@ -24,6 +25,8 @@
import io.openliberty.tools.langserver.ls.LibertyTextDocument;
import io.openliberty.tools.langserver.utils.Messages;
import io.openliberty.tools.langserver.utils.ServerPropertyValues;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

public class PropertiesKeyInstance {

Expand Down Expand Up @@ -61,7 +64,17 @@ public CompletableFuture<Hover> getHover(Position position) {

public CompletableFuture<List<CompletionItem>> getCompletions(String enteredText, Position position) {
List<String> matches = Messages.getMatchingKeys(enteredText, textDocumentItem);
List<CompletionItem> results = matches.stream().map(s -> new CompletionItem(s)).collect(Collectors.toList());
List<CompletionItem> results = matches.stream().map(s ->{
int line = position.getLine();
Position rangeStart = new Position(line, 0);
Position rangeEnd = new Position(line, s.length());
Range range = new Range(rangeStart, rangeEnd);
Either<TextEdit, InsertReplaceEdit> edit = Either.forLeft(new TextEdit(range, s));
CompletionItem completionItem=new CompletionItem();
completionItem.setTextEdit(edit);
completionItem.setLabel(s);
return completionItem;
}).toList();
// set hover description as the 'detail' on the CompletionItem
setDetailsOnCompletionItems(results, null, false);
return CompletableFuture.completedFuture(results);
Expand Down

0 comments on commit d513825

Please sign in to comment.