Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute completion xsi:schemaLocation / xsi:noNamespaceSchemaLocation even if the other exists #382

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,9 @@ private synchronized void initializeReferencedSchema() {
}
}
if (schemaInstancePrefix != null) {
// DOM document can declared xsi:noNamespaceSchemaLocation and xsi:schemaLocation both even it's not valid
noNamespaceSchemaLocation = createNoNamespaceSchemaLocation(documentElement, schemaInstancePrefix);
if (noNamespaceSchemaLocation == null) {
schemaLocation = createSchemaLocation(documentElement, schemaInstancePrefix);
}
schemaLocation = createSchemaLocation(documentElement, schemaInstancePrefix);
}
}
}
Expand Down Expand Up @@ -862,4 +861,4 @@ else if (noNamespaceSchemaLocation != null) {
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ public static void computeCompletionResponses(ICompletionRequest request,
}

if(inRootElement) {
if(!schemaLocationExists && !noNamespaceSchemaLocationExists) {
if(!schemaLocationExists) {
//The xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes can be used in a document
//to provide hints as to the physical location of schema documents which may be used for ·assessment·.
documentation = SCHEMA_LOCATION_DOC;
name = actualPrefix + ":schemaLocation";
createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response, settings);

}
if(!noNamespaceSchemaLocationExists) {
documentation = NO_NAMESPACE_SCHEMA_LOCATION_DOC;
name = actualPrefix + ":noNamespaceSchemaLocation";
createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,18 @@ public void testUsesSchemaTrueAbsolutePath() {
Assert.assertTrue(d.hasSchemaInstancePrefix());
Assert.assertTrue(d.usesSchema("/home/nikolas/nested/testXSD.xsd")); //bad path
}

@Test
public void testNoNamespaceSchemaLocationAndShemaLocationBoth() {
String text = "<root\n" + //
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + //
" xsi:noNamespaceSchemaLocation=\"/home/nikolas/nested/testXSD.xsd\"" + //
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 testXSD.xsd\"" + //
">" + //
" </root> ";
TextDocument textDocument = new TextDocument(text, "/home/test.xml");
DOMDocument d = DOMParser.getInstance().parse(text, textDocument.getUri(), null);
Assert.assertNotNull(d.getNoNamespaceSchemaLocation());
Assert.assertNotNull(d.getSchemaLocation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.lsp4xml.XMLAssert;
import org.eclipse.lsp4xml.commons.BadLocationException;
import org.eclipse.lsp4xml.services.XMLLanguageService;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand Down Expand Up @@ -345,7 +344,7 @@ public void completionWithXMLSchemaContentChanged() throws Exception {
+ " <xs:attribute name=\"variant\" type=\"xs:string\" use=\"required\"/>\r\n"
+ " </xs:complexType>\r\n" + " </xs:element>\r\n" + "</xs:schema>";
Files.write(Paths.get("target/xsd/resources.xsd"), schema.getBytes());
XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 4, false,
XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 5, false,
c("variant", "variant=\"\""));

// Update resources.xsd, Schema doesn't define variant attribute -> no
Expand All @@ -366,7 +365,7 @@ public void completionWithXMLSchemaContentChanged() throws Exception {
// + " <xs:attribute name=\"variant\" type=\"xs:string\" use=\"required\"/>\r\n"
+ " </xs:complexType>\r\n" + " </xs:element>\r\n" + "</xs:schema>";
Files.write(Paths.get("target/xsd/resources.xsd"), schema.getBytes());
XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 3, false);
XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 4, false);

}

Expand Down Expand Up @@ -448,7 +447,7 @@ public void xsiCompletionNotUsingXSIName() throws BadLocationException {
" <modelVersion></modelVersion>\r\n" +
"</project>";

XMLAssert.testCompletionFor(xml, 3, c("XXY:nil", "XXY:nil=\"true\""), c("XXY:type", "XXY:type=\"\""));
XMLAssert.testCompletionFor(xml, 4, c("XXY:nil", "XXY:nil=\"true\""), c("XXY:type", "XXY:type=\"\""), c("XXY:noNamespaceSchemaLocation", "XXY:noNamespaceSchemaLocation=\"\""));
}

@Test
Expand Down Expand Up @@ -485,7 +484,7 @@ public void xsiCompletionSchemaLocationExists() throws BadLocationException {
" <modelVersion></modelVersion>\r\n" +
"</project>";

XMLAssert.testCompletionFor(xml, 3, c("xsi:nil", "xsi:nil=\"true\""), c("xsi:type", "xsi:type=\"\""));
XMLAssert.testCompletionFor(xml, 4, c("xsi:nil", "xsi:nil=\"true\""), c("xsi:type", "xsi:type=\"\""), c("xsi:noNamespaceSchemaLocation", "xsi:noNamespaceSchemaLocation=\"\""));
}

@Test
Expand All @@ -498,7 +497,7 @@ public void xsiCompletionNoNamespaceSchemaLocationExists() throws BadLocationExc
" <modelVersion></modelVersion>\r\n" +
"</project>";

XMLAssert.testCompletionFor(xml, 2, c("xsi:nil", "xsi:nil=\"true\""), c("xsi:type", "xsi:type=\"\""));
XMLAssert.testCompletionFor(xml, 3, c("xsi:nil", "xsi:nil=\"true\""), c("xsi:type", "xsi:type=\"\""), c("xsi:schemaLocation", "xsi:schemaLocation=\"\""));
}

private void testCompletionFor(String xml, CompletionItem... expectedItems) throws BadLocationException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<zz:yesNS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:zz="http://gotNS" xsi:schemaLocation="http://gotNS xsd2Namespace.xsd" xsi:noNamespaceSchemaLocation="xsdNoNamespace.xsd">
<dog></dog>

</zz:yesNS>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://gotNS">
<xs:element name="yesNS">
<xs:complexType>
<xs:sequence>
<xs:element name="dog"></xs:element>
<xs:any id="other"></xs:any>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="noNS">
<xs:complexType>
<xs:sequence>
<xs:element name="noNSC1"></xs:element>
<xs:element name="noNSC2"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>