Skip to content

Commit

Permalink
Versionless feature 1.0 (#296)
Browse files Browse the repository at this point in the history
* Versionless feature changes. Added platform component

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

* Versionless feature changes. Added hover for platform component

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

* Versionless feature changes. modified diagnostics

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

* Versionless feature changes. modified diagnostics

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

* Versionless feature changes. adding more diagnostic scenarios

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 Aug 21, 2024
1 parent 656e5a8 commit 7f6375b
Show file tree
Hide file tree
Showing 18 changed files with 184,520 additions and 55 deletions.
2 changes: 1 addition & 1 deletion lemminx-liberty/src/it/schema-gen-ol-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<runtimeArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-runtime</artifactId>
<version>22.0.0.12</version>
<version>24.0.0.8</version>
</runtimeArtifact>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testWorkspace() throws BadLocationException, IOException, URISyntaxE
testWorkspaceFolders.add(testWorkspace);
LibertyProjectsManager.getInstance().setWorkspaceFolders(testWorkspaceFolders);

String schemaFileName = "ol-22.0.0.12.xsd";
String schemaFileName = "ol-24.0.0.8.xsd";
File schemaFile = new File(LibertyUtils.getTempDir(LibertyProjectsManager.getInstance().getWorkspaceFolder(serverXmlFile.toURI().toString())), schemaFileName);
String serverGenXSDURI = schemaFile.toPath().toUri().toString().replace("///", "/");

Expand Down Expand Up @@ -79,8 +79,8 @@ public void testGetFeatures() throws BadLocationException {

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

// would be 228 if mpConfig-1.4 was not already specified - this is using ol-22.0.0.12
final int TOTAL_ITEMS = 227; // total number of available completion items
// would be 337 if mpConfig-1.4 was not already specified - this is using ol-24.0.0.8
final int TOTAL_ITEMS = 337; // total number of available completion items

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

Expand All @@ -89,7 +89,7 @@ public void testGetFeatures() throws BadLocationException {
XMLAssert.testCompletionFor(serverXML, null, serverXmlFile.toURI().toString(), TOTAL_ITEMS, websocket);

// Verify that a feature list was NOT generated. It should have downloaded the features.json from Maven Central.
String featureListName = "featurelist-ol-22.0.0.12.xml";
String featureListName = "featurelist-ol-24.0.0.8.xml";
File featurelistFile = new File(LibertyUtils.getTempDir(LibertyProjectsManager.getInstance().getWorkspaceFolder(serverXmlFile.toURI().toString())), featureListName);

org.junit.jupiter.api.Assertions.assertFalse(featurelistFile.exists(), "Found unexpected generated featurelist file: "+featureListName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 IBM Corporation and others.
* Copyright (c) 2023, 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 @@ -15,6 +15,8 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.eclipse.lemminx.commons.BadLocationException;
import org.eclipse.lemminx.dom.DOMDocument;
Expand Down Expand Up @@ -72,6 +74,38 @@ public void onXMLContent(ICompletionRequest request, ICompletionResponse respons
existingFeatures, featureName, featureMgrNode);
featureCompletionItems.stream().forEach(item -> response.addCompletionItem(item));
}
if (parentElement.getTagName().equals(LibertyConstants.PLATFORM_ELEMENT)) {
buildPlatformCompletionItems(request, response, parentElement);
}
}

/**
* build completion items for platforms
* @param request request
* @param response response
* @param parentElement parent element xml dom
*/
private static void buildPlatformCompletionItems(ICompletionRequest request, ICompletionResponse response, DOMElement parentElement) {
DOMNode platformTextNode = (DOMNode) parentElement.getChildNodes().item(0);
String platformName = platformTextNode != null ? platformTextNode.getTextContent() : null;
LibertyRuntime runtimeInfo = LibertyUtils.getLibertyRuntimeInfo(request.getXMLDocument());
String libertyVersion = runtimeInfo == null ? null : runtimeInfo.getRuntimeVersion();
String libertyRuntime = runtimeInfo == null ? null : runtimeInfo.getRuntimeType();

final int requestDelay = SettingsService.getInstance().getRequestDelay();
//get all platforms
Set<String> platforms = FeatureService.getInstance().getAllPlatforms(libertyVersion, libertyRuntime, requestDelay,
request.getXMLDocument().getDocumentURI());
platforms.stream().filter(it->(Objects.isNull(platformName) || it.contains(platformName)))
.forEach(item -> {
Range range = XMLPositionUtility.createRange(parentElement.getStartTagCloseOffset() + 1,
parentElement.getEndTagOpenOffset(), request.getXMLDocument());
Either<TextEdit, InsertReplaceEdit> edit = Either.forLeft(new TextEdit(range, item));
CompletionItem completionItem = new CompletionItem();
completionItem.setLabel(item);
completionItem.setTextEdit(edit);
response.addCompletionItem(completionItem);
});
}

private CompletionItem buildFeatureCompletionItem(Feature feature, DOMElement featureElement,
Expand Down
Loading

0 comments on commit 7f6375b

Please sign in to comment.