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

fixing completion issues for features when no input is provided #332

Merged
Show file tree
Hide file tree
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
Expand Up @@ -87,7 +87,7 @@ public void testGetFeatures() throws BadLocationException {

// this is using a beta runtime which does not have any features.json in Maven Central
// this causes the featurelist xml file to get generated in the .libertyls folder
final int TOTAL_ITEMS = 264; // total number of available completion items
final int TOTAL_ITEMS = 261; // total number of available completion items excluding all servlet versions

XMLAssert.testCompletionFor(serverXML, null, serverXmlFile.toURI().toString(), TOTAL_ITEMS, batchCompletion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testGetFeatures() throws BadLocationException {

CompletionItem jaxrsCompletion = c("jaxrs-2.1", "jaxrs-2.1");

final int TOTAL_ITEMS = 352; // total number of available completion items
final int TOTAL_ITEMS = 345; // total number of available completion items excluding all mpConfig versions

XMLAssert.testCompletionFor(serverXML, null, serverXmlFile.toURI().toString(), TOTAL_ITEMS, jaxrsCompletion);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2024 IBM Corporation and others.
* Copyright (c) 2020, 2025 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 @@ -108,7 +108,7 @@ public void onAttributeValue(String valuePrefix, ICompletionRequest request, ICo
public void onXMLContent(ICompletionRequest request, ICompletionResponse response, CancelChecker cancelChecker)
throws IOException, BadLocationException {
if (!LibertyUtils.isConfigXMLFile(request.getXMLDocument()))
return;
return;

LibertyUtils.getLibertyRuntimeInfo(request.getXMLDocument());

Expand Down Expand Up @@ -209,7 +209,7 @@ private List<CompletionItem> buildCompletionItems(DOMElement featureElement, DOM
final int requestDelay = SettingsService.getInstance().getRequestDelay();

boolean checkFeatureName = featureName != null && !featureName.isBlank();

if (checkFeatureName) {
String featureNameLowerCase = featureName.toLowerCase();

Expand Down Expand Up @@ -237,10 +237,18 @@ private List<CompletionItem> getFeatureCompletionItems(DOMElement featureElement

private List<CompletionItem> getUniqueFeatureCompletionItems(DOMElement featureElement, DOMDocument domDocument, List<Feature> allFeatures, List<String> existingFeatureNames) {
List<CompletionItem> uniqueFeatureCompletionItems = new ArrayList<CompletionItem>();
// collect features without version
// existing features are already in lower case
Set<String> existingFeatureNamesWithoutVersion = existingFeatureNames.stream()
.map(s->LibertyUtils.stripVersion(s).toLowerCase())
.collect(Collectors.toSet());

for (Feature nextFeature : allFeatures) {
String nextFeatureName = nextFeature.getWlpInformation().getShortName().toLowerCase();
if (!existingFeatureNames.contains(nextFeatureName)) {
String nextFeatureNameWithoutVersion = LibertyUtils.stripVersion(nextFeatureName);
// exclude other versions of all included features
if (!existingFeatureNames.contains(nextFeatureName)
&& !existingFeatureNamesWithoutVersion.contains(nextFeatureNameWithoutVersion)) {
CompletionItem ci = buildFeatureCompletionItem(nextFeature, featureElement, domDocument);
uniqueFeatureCompletionItems.add(ci);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,22 @@ public void testFeatureCompletionItem() throws BadLocationException {
CompletionItem websocket = c("websocket-1.1", "websocket-1.1");
CompletionItem microProfileCompletion = c("microProfile-2.2", "microProfile-2.2");

final int TOTAL_ITEMS = 352; // total number of available completion items
final int TOTAL_ITEMS = 345; // total number of available completion items excluding all mpConfig versions

XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, TOTAL_ITEMS, jaxrsCompletion, websocket,
microProfileCompletion);
// tests for lowercase
serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <feature>|</feature>", //
" <feature>mpconfig</feature>", //
" </featureManager>", //
"</server>" //
);

XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, TOTAL_ITEMS, jaxrsCompletion, websocket,
microProfileCompletion);
}

// Tests the
Expand Down
Loading