Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for bootstrap properties code completion replacing existing line #306

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 IBM Corporation and others.
* Copyright (c) 2022, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -16,6 +16,7 @@
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionItemKind;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.InsertReplaceEdit;
cherylking marked this conversation as resolved.
Show resolved Hide resolved
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
Loading