Skip to content

Commit

Permalink
Feature completion fix (#315)
Browse files Browse the repository at this point in the history
* correcting copyrights

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

* fixing feature completion issue for repeating same feature

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

* fixing feature completion issue for repeating same feature

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 22, 2024
1 parent d0c888e commit d79adf1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private List<CompletionItem> buildCompletionItems(DOMElement featureElement, DOM
String featureNameLowerCase = featureName.toLowerCase();

// strip off version number after the - so that we can provide all possible valid versions of a feature for completion
String featureNameToCompare = LibertyUtils.stripVersion(featureNameLowerCase);
String featureNameToCompare = featureNameLowerCase.contains("-") ? featureNameLowerCase.substring(0, featureNameLowerCase.lastIndexOf("-")+1) : featureNameLowerCase;

List<Feature> completionFeatures = FeatureService.getInstance().getFeatureReplacements(featureNameToCompare, featureMgrNode, libertyVersion, libertyRuntime, requestDelay, domDocument.getDocumentURI());
return getFeatureCompletionItems(featureElement, domDocument, completionFeatures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public List<Feature> getFeatureReplacements(String featureName, DOMNode featureM
*/
public List<String> collectExistingFeatures(DOMNode featureManager, String currentFeatureName) {
List<String> includedFeatures = new ArrayList<>();

boolean alreadyIgnoredOnce = false;
if (featureManager == null) {
return includedFeatures;
}
Expand All @@ -311,7 +311,10 @@ public List<String> collectExistingFeatures(DOMNode featureManager, String curre
if (featureNode.getNodeName().equals(LibertyConstants.FEATURE_ELEMENT) && featureTextNode != null) {
String featureName = featureTextNode.getTextContent();
String featureNameLowerCase = featureName.toLowerCase();
if (currentFeatureName == null || (currentFeatureName != null && !featureNameLowerCase.equalsIgnoreCase(currentFeatureName))) {
// if same feature is repeated, ignore it first time, but add for second time onwards
if (featureNameLowerCase.equalsIgnoreCase(currentFeatureName) && !alreadyIgnoredOnce) {
alreadyIgnoredOnce = true;
} else {
includedFeatures.add(featureNameLowerCase);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,69 @@ public void testPlatformCompletionItem() throws BadLocationException {
XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, 8);
}

// Tests the feature completion for same feature repetition
@Test
public void testFeatureRepetitionCompletionItem() throws BadLocationException {
String serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <feature>servlet</feature>", //
" <feature>servlet|</feature>", //
" </featureManager>", //
"</server>" //
);

// total number of available completion items
// 1 for sipServlet-1.1
// one for CDATA and one for <-
CompletionItem sipServletCompletionItem = c("sipServlet-1.1", "sipServlet-1.1");
XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, 3, sipServletCompletionItem);

serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <feature>servlet-|</feature>", //
" <feature>servlet</feature>", //
" </featureManager>", //
"</server>" //
);

// total number of available completion items
// 1 for sipServlet-1.1
// one for CDATA and one for <-
sipServletCompletionItem = c("sipServlet-1.1", "sipServlet-1.1");
XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, 3, sipServletCompletionItem);

serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <feature>servlet-3.1</feature>", //
" <feature>servlet|</feature>", //
" </featureManager>", //
"</server>" //
);

// total number of available completion items
// 1 for sipServlet-1.1
// one for CDATA and one for <-
sipServletCompletionItem = c("sipServlet-1.1", "sipServlet-1.1");
XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, 3, sipServletCompletionItem);

serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <feature>servlet-</feature>", //
" <feature>servlet</feature>", //
" <feature>servlet|</feature>", //
" </featureManager>", //
"</server>" //
);

// total number of available completion items
// 1 for sipServlet-1.1
// one for CDATA and one for <-
sipServletCompletionItem = c("sipServlet-1.1", "sipServlet-1.1");
XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, 3, sipServletCompletionItem);
}

}

0 comments on commit d79adf1

Please sign in to comment.