GH-1163: fixed problem with content-assist not showing up for fully qualified beans root element

This commit is contained in:
Martin Lippert
2024-01-18 14:55:33 +01:00
parent 9784b2a195
commit b6d5e89e70
2 changed files with 24 additions and 2 deletions

View File

@@ -184,7 +184,7 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
case AttributeName:
if (scanner.getTokenOffset() <= offset && offset < scanner.getTokenEnd()) {
if (node.getParentNode() != null && node.getParentNode() instanceof DOMDocument
&& namespace.equals("http://www.springframework.org/schema/beans") && node.getNodeName().equals("beans")) {
&& namespace.equals("http://www.springframework.org/schema/beans") && node.getLocalName().equals("beans")) {
return NamespaceCompletionProvider.createNamespaceCompletionProposals(doc, offset, token, node);
}
}
@@ -192,7 +192,7 @@ public class SpringXMLCompletionEngine implements ICompletionEngine, LanguageSpe
case Whitespace:
if (scanner.getTokenOffset() <= offset && offset < scanner.getTokenEnd()) {
if (node.getParentNode() != null && node.getParentNode() instanceof DOMDocument
&& namespace.equals("http://www.springframework.org/schema/beans") && node.getNodeName().equals("beans")) {
&& namespace.equals("http://www.springframework.org/schema/beans") && node.getLocalName().equals("beans")) {
return NamespaceCompletionProvider.createNamespaceCompletionProposals(doc, offset, token, node);
}
}

View File

@@ -324,7 +324,29 @@ public class XMLContentAssistTest {
editorContent);
}
@Test
void testAddNamespaceCompletionWhenBeansElementFullyQualified() throws Exception {
Editor editor = new Editor(harness, """
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
<*>
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="simpleObj" class="u.t.r.SimpleObj"></bean>
</beans>
""",
LanguageId.XML);
List<CompletionItem> completions = editor.getCompletions();
assertEquals(ALL_NAMESPACE_COMPLETIONS, completions.size());
}
@Test
void testNoNamespaceCompletionOutsideOfMainElement1() throws Exception {