Skip to content

Commit

Permalink
Property value completion fix (#316)
Browse files Browse the repository at this point in the history
* correcting copyrights

Signed-off-by: Arun Venmany <Arun.Kumar.V.N@ibm.com>

* For server.env and bootstrap.properties, fixing auto completion for value based on user input

Signed-off-by: Arun Venmany <Arun.Kumar.V.N@ibm.com>

---------

Signed-off-by: Arun Venmany <Arun.Kumar.V.N@ibm.com>
  • Loading branch information
arunvenmany-ibm authored Oct 23, 2024
1 parent d79adf1 commit 2cebdcd
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 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 Down Expand Up @@ -102,7 +102,7 @@ public CompletableFuture<Hover> getHover(Position position) {
public CompletableFuture<List<CompletionItem>> getCompletions(Position position) {
if (!isComment) {
if (propertyValueInstance.toString() != null && !isOnEntryKey(position)) {
return propertyValueInstance.getCompletions(position);
return propertyValueInstance.getCompletions(propertyValueInstance.toString(), position);
}
return propertyKeyInstance.getCompletions(this.getKey(), position);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,21 @@ protected void setDetailsOnCompletionItems(List<CompletionItem> items, String ke
}
}

public List<CompletionItem> getValidValues() {
public List<CompletionItem> getValidValues(String enteredValue, Position position) {
List<String> values = ServerPropertyValues.getValidValues(textDocumentItem, propertyKey);
List<CompletionItem> results = values.stream().map(s -> new CompletionItem(s)).collect(Collectors.toList());
List<CompletionItem> results = values.stream()
.filter(s -> s.toLowerCase().contains(enteredValue.trim().toLowerCase()))
.map(s -> {
int line = position.getLine();
Position rangeStart = new Position(line, getEndPosition() + 2);
Position rangeEnd = new Position(line, getEndPosition() + 2 + 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();
// Preselect the default.
// This uses the first item in the List as default.
// (Check ServerPropertyValues.java) Currently sorted to have confirmed/sensible values as default.
Expand Down
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 Down Expand Up @@ -41,8 +41,8 @@ public CompletableFuture<Hover> getHover() {
return CompletableFuture.completedFuture(hover);
}

public CompletableFuture<List<CompletionItem>> getCompletions(Position position) {
return CompletableFuture.completedFuture(key.getValidValues());
public CompletableFuture<List<CompletionItem>> getCompletions(String enteredValue, Position position) {
return CompletableFuture.completedFuture(key.getValidValues(enteredValue, position));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ public void testValueCompletionLogProvider() throws Exception {
checkCompletionsContainAllStrings(completionItems, "binaryLogging-1.0");
}

@Test
public void testValueCompletionForTraceLoggingFormatWithValidUserInput() throws Exception {
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletion("com.ibm.ws.logging.trace.format= CE ", new Position(0, 41));
List<CompletionItem> completionItems = completions.get().getLeft();
assertEquals(2, completionItems.size());

checkCompletionsContainAllStrings(completionItems, "ENHANCED", "ADVANCED");
}

@Test
public void testValueCompletionLogProviderUserEnteredInvalidValue() throws Exception {
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletion("websphere.log.provider=bb", new Position(0, 24));
List<CompletionItem> completionItems = completions.get().getLeft();
assertEquals(0, completionItems.size());
}

protected CompletableFuture<Either<List<CompletionItem>, CompletionList>> getCompletion(String enteredText, Position position) throws URISyntaxException, InterruptedException, ExecutionException {
String filename = "bootstrap.properties";
File file = new File(resourcesDir, filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@ public void testValueCompletionForBoolean() throws Exception {
checkCompletionsContainAllStrings(completionItems, ServerPropertyValues.BOOLEAN_VALUES_DEFAULT_TRUE);
}

@Test
public void testValueCompletionForConsoleLoggingFormatForUserEnteredKey() throws Exception {
// also testing user entered value with trailing spaces. spaces are trimmed in code
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletion("WLP_LOGGING_CONSOLE_FORMAT= S", new Position(0, 28));
List<CompletionItem> completionItems = completions.get().getLeft();
assertEquals(3, completionItems.size());

checkCompletionsContainAllStrings(completionItems, "SIMPLE", "JSON", "TBASIC");

checkCompletionContainsDetail(completionItems, null, "This setting specifies the required format for the console. Valid values are `dev`, `simple`, or `json` format. By default, consoleFormat is set to `dev`.");
}

@Test
public void testValueCompletionForConsoleLoggingFormatForUserEnteredInvalidKey() throws Exception {
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletion("WLP_LOGGING_CONSOLE_FORMAT=Asd", new Position(0, 30));
List<CompletionItem> completionItems = completions.get().getLeft();
assertEquals(0, completionItems.size());
}

@Test
public void testValueCompletionForYesNoWhenUserEnteredY() throws Exception {
//providing input in UPPERCASE to verify code is working case insensitive
//also checking ending spaces
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletion("WLP_DEBUG_SUSPEND=Y ", new Position(0, 21));
List<CompletionItem> completionItems = completions.get().getLeft();
assertEquals(1, completionItems.size());

checkCompletionsContainAllStrings(completionItems, "y");

}

protected CompletableFuture<Either<List<CompletionItem>, CompletionList>> getCompletion(String enteredText, Position position) throws URISyntaxException, InterruptedException, ExecutionException, IOException {
String filename = "server.env";
File file = new File(resourcesDir, filename);
Expand Down

0 comments on commit 2cebdcd

Please sign in to comment.