-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
textDocument/completion
for xs:element/@name /
xs:extension/@base Fix #451 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
140a8c7
commit c040498
Showing
6 changed files
with
216 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsd/DataType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.eclipse.lsp4xml.extensions.xsd; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.xml.parsers.SAXParser; | ||
import javax.xml.parsers.SAXParserFactory; | ||
|
||
import org.xml.sax.Attributes; | ||
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.helpers.DefaultHandler; | ||
|
||
public class DataType { | ||
|
||
private static final Map<String, DataType> dataTypes; | ||
|
||
static { | ||
dataTypes = loadDataTypes(); | ||
} | ||
|
||
public static DataType getDataType(String name) { | ||
return dataTypes.get(name); | ||
} | ||
|
||
public static Collection<DataType> getDataTypes() { | ||
return dataTypes.values(); | ||
} | ||
|
||
private final String name; | ||
|
||
private final String url; | ||
|
||
private final String description; | ||
|
||
public DataType(String name, String url, String description) { | ||
this.name = name; | ||
this.url = url; | ||
this.description = description; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
private static Map<String, DataType> loadDataTypes() { | ||
try { | ||
SAXParserFactory factory = SAXParserFactory.newInstance(); | ||
SAXParser saxParser = factory.newSAXParser(); | ||
DataTypeHandler handler = new DataTypeHandler(); | ||
saxParser.parse(new InputSource(DataType.class.getResourceAsStream("/schemas/xsd/datatypes.xml")), handler); | ||
return handler.getDataTypes(); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
private static class DataTypeHandler extends DefaultHandler { | ||
|
||
private final Map<String, DataType> dataTypes; | ||
|
||
public DataTypeHandler() { | ||
dataTypes = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void startElement(String uri, String localName, String qName, Attributes attributes) | ||
throws SAXException { | ||
if ("datatype".contentEquals(qName)) { | ||
DataType dataType = new DataType(attributes.getValue("name"), attributes.getValue("url"), | ||
attributes.getValue("description")); | ||
dataTypes.put(dataType.getName(), dataType); | ||
} | ||
super.startElement(uri, localName, qName, attributes); | ||
} | ||
|
||
public Map<String, DataType> getDataTypes() { | ||
return dataTypes; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
org.eclipse.lsp4xml/src/main/resources/schemas/xsd/datatypes.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<datatypes> | ||
<!-- See all built-in datatypes at https://www.w3.org/TR/xmlschema11-2/#built-in-datatypes --> | ||
|
||
<!-- PRIMITIVE DATATYPES -> https://www.w3.org/TR/xmlschema11-2/#built-in-primitive-datatypes --> | ||
<datatype name="string" url="https://www.w3.org/TR/xmlschema11-2/#string" /> | ||
<datatype name="boolean" url="https://www.w3.org/TR/xmlschema11-2/#boolean" /> | ||
<datatype name="decimal" url="https://www.w3.org/TR/xmlschema11-2/#decimal" /> | ||
<datatype name="float" url="https://www.w3.org/TR/xmlschema11-2/#float" /> | ||
<datatype name="double" url="https://www.w3.org/TR/xmlschema11-2/#double" /> | ||
<datatype name="duration" url="https://www.w3.org/TR/xmlschema11-2/#duration" /> | ||
<datatype name="dateTime" url="https://www.w3.org/TR/xmlschema11-2/#dateTime" /> | ||
<datatype name="time" url="https://www.w3.org/TR/xmlschema11-2/#time" /> | ||
<datatype name="date" url="https://www.w3.org/TR/xmlschema11-2/#date" /> | ||
<datatype name="gYearMonth" url="https://www.w3.org/TR/xmlschema11-2/#gYearMonth" /> | ||
<datatype name="gYear" url="https://www.w3.org/TR/xmlschema11-2/#gYear" /> | ||
|
||
</datatypes> |
14 changes: 14 additions & 0 deletions
14
org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/xsd/DataTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.eclipse.lsp4xml.extensions.xsd; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class DataTypeTest { | ||
|
||
@Test | ||
public void xsString() { | ||
DataType string = DataType.getDataType("string"); | ||
Assert.assertNotNull(string); | ||
Assert.assertEquals(string.getName(), "string"); | ||
} | ||
} |