diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/LibertyDiagnosticParticipant.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/LibertyDiagnosticParticipant.java index 5f47709b..a0da04b2 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/LibertyDiagnosticParticipant.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/LibertyDiagnosticParticipant.java @@ -292,15 +292,30 @@ private void validateConfigElements(DOMDocument domDocument, List di } for (Diagnostic tempDiagnostic : tempDiagnosticsList) { String configElement = tempDiagnostic.getSource(); - Set includedFeaturesCopy = new HashSet(includedFeatures); Set compatibleFeaturesList = featureGraph.getAllEnabledBy(configElement); - includedFeaturesCopy.retainAll(compatibleFeaturesList); + Set includedFeaturesCopy = getCompatibleFeatures(includedFeatures, compatibleFeaturesList); if (includedFeaturesCopy.isEmpty()) { diagnosticsList.add(tempDiagnostic); } } } + /** + * get compatible features for both versioned and versionless features + * + * @param includedFeatures ll selected features + * @param compatibleFeaturesList enabled by feature list + * @return any compitable feature list + */ + private Set getCompatibleFeatures(Set includedFeatures, Set compatibleFeaturesList) { + Set versionLessCompatibleFeatureList = compatibleFeaturesList.stream() + .map(f -> LibertyUtils.stripVersion(f)) + .collect(Collectors.toSet()); + return includedFeatures.stream().filter(included -> + compatibleFeaturesList.contains(included) || versionLessCompatibleFeatureList.contains(included) + ).collect(Collectors.toSet()); + } + /** * validate platform element. checks for * 1) if platform is invalid diff --git a/lemminx-liberty/src/test/java/io/openliberty/LibertyDiagnosticTest.java b/lemminx-liberty/src/test/java/io/openliberty/LibertyDiagnosticTest.java index 18f967ab..f785de0e 100644 --- a/lemminx-liberty/src/test/java/io/openliberty/LibertyDiagnosticTest.java +++ b/lemminx-liberty/src/test/java/io/openliberty/LibertyDiagnosticTest.java @@ -665,4 +665,26 @@ public void testValidPlatformDiagnostic() throws BadLocationException { XMLAssert.testDiagnosticsFor(serverXML, null, null, serverXMLURI); } + + @Test + public void testConfigElementVersionLess() throws JAXBException { + assertTrue(featureList.exists()); + FeatureService.getInstance().readFeaturesFromFeatureListFile(new ArrayList(), libWorkspace, featureList); + String serverXML1 = String.join(newLine, + "", + " ", + " servlet", + " jakartaee-9.1", + " ", + " ", + " ", + " ", + "" + ); + Diagnostic configForMissingFeature = new Diagnostic(); + configForMissingFeature.setRange(r(7, 3, 7, 57)); + configForMissingFeature.setCode(LibertyDiagnosticParticipant.MISSING_CONFIGURED_FEATURE_CODE); + configForMissingFeature.setMessage(LibertyDiagnosticParticipant.MISSING_CONFIGURED_FEATURE_MESSAGE); + XMLAssert.testDiagnosticsFor(serverXML1, null, null, serverXMLURI,configForMissingFeature); + } } \ No newline at end of file