Skip to content

Commit

Permalink
changes to resolve config element problem (#341)
Browse files Browse the repository at this point in the history
* changes to resolve config element problem

Signed-off-by: Arun Venmany <[email protected]>

* fixing platform quickfix code completion not working (#340)

Signed-off-by: Arun Venmany <[email protected]>

* adding comments and splitting tests + code optimization

Signed-off-by: Arun Venmany <[email protected]>

---------

Signed-off-by: Arun Venmany <[email protected]>
  • Loading branch information
arunvenmany-ibm authored Jan 31, 2025
1 parent bb10e15 commit a61f68b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 IBM Corporation and others.
* Copyright (c) 2023, 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 @@ -55,7 +55,12 @@ public FeatureListNode addFeature(String nodeName, String description) {
}
FeatureListNode node = new FeatureListNode(nodeName, description);
featureNodes.put(nodeName, node);
nodes.put(nodeName, node);
// in case of versionless features,
// there are some config elements with same name as version less feature
// such as mpMetrics, currently only one
// use putIfAbsent because there might be already a configElement with enabledBy added
// for version less features, config elements are not present in xsd
nodes.putIfAbsent(nodeName, node);
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,4 +1062,74 @@ public void testMultipleVariablesInSameAttributeDiagnostic() {
dup1.setData("testVar1");
XMLAssert.testDiagnosticsFor(serverXML, null, null, serverXMLURI, false, dup1);
}

@Test
public void testConfigElementSameNameAsVersionlessFeatureNoDiagnostics() throws BadLocationException {
String configElement = "<mpMetrics authentication=\"false\"></mpMetrics>";

String serverXML = String.join(newLine,
"<server description=\"Sample Liberty server\">",
" <featureManager>",
" <feature>mpMetrics</feature>",
" <platform>microProfile-2.2</platform>",
" </featureManager>",
configElement,
"</server>"
);
// no diagnostics expected, as we have the correct feature
XMLAssert.testDiagnosticsFor(serverXML, null, null, sampleserverXMLURI);
}

@Test
public void testConfigElementSameNameAsVersionlessFeatureWithDiagnosticsAndCodeAction() throws BadLocationException {
String configElement = "<mpMetrics authentication=\"false\"></mpMetrics>";
String serverXML = String.join(newLine,
"<server description=\"Sample Liberty server\">",
" <featureManager>",
" <platform>microProfile-2.2</platform>",
" </featureManager>",
configElement,
"</server>"
);
Diagnostic diagnostic = new Diagnostic();
diagnostic.setRange(r(4, 0, 4, 46));
diagnostic.setCode(LibertyDiagnosticParticipant.MISSING_CONFIGURED_FEATURE_CODE);
diagnostic.setMessage(LibertyDiagnosticParticipant.MISSING_CONFIGURED_FEATURE_MESSAGE);

XMLAssert.testDiagnosticsFor(serverXML, null, null, sampleserverXMLURI,diagnostic);
diagnostic.setSource("mpMetrics");

List<String> featuresToAdd = new ArrayList<String>();
featuresToAdd.add("mpMetrics-1.0");
featuresToAdd.add("mpMetrics-1.1");
featuresToAdd.add("mpMetrics-2.0");
featuresToAdd.add("mpMetrics-2.2");
featuresToAdd.add("mpMetrics-2.3");
featuresToAdd.add("mpMetrics-3.0");
featuresToAdd.add("mpMetrics-4.0");
featuresToAdd.add("mpMetrics-5.0");
featuresToAdd.add("mpMetrics-5.1");

Collections.sort(featuresToAdd);

List<CodeAction> codeActions = new ArrayList<>();
for (String nextFeature: featuresToAdd) {
String addFeature = String.format("%s<feature>%s</feature>",System.lineSeparator(),nextFeature);
TextEdit texted = te(2, 45, 2, 45, addFeature);
CodeAction invalidCodeAction = ca(diagnostic, texted);

TextDocumentEdit textDoc = tde(sampleserverXMLURI, 0, texted);
WorkspaceEdit workspaceEdit = new WorkspaceEdit(Collections.singletonList(Either.forLeft(textDoc)));

invalidCodeAction.setEdit(workspaceEdit);
codeActions.add(invalidCodeAction);
}

// diagnostic with code action expected
XMLAssert.testCodeActionsFor(serverXML, sampleserverXMLURI, diagnostic, (String) null,
codeActions.get(0), codeActions.get(1), codeActions.get(2),
codeActions.get(3), codeActions.get(4), codeActions.get(5),
codeActions.get(6), codeActions.get(7), codeActions.get(8)
);
}
}

0 comments on commit a61f68b

Please sign in to comment.