-
Notifications
You must be signed in to change notification settings - Fork 92
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
23b2105
commit bcc4233
Showing
8 changed files
with
305 additions
and
34 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
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
129 changes: 129 additions & 0 deletions
129
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,129 @@ | ||
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.eclipse.lsp4xml.utils.StringUtils; | ||
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 String lineSeparator = System.lineSeparator(); | ||
|
||
public enum DataTypeType { | ||
PRIMITIVE | ||
} | ||
|
||
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; | ||
|
||
private final DataTypeType type; | ||
|
||
private String documentation; | ||
|
||
public DataType(String name, String url, String description, DataTypeType type) { | ||
this.name = name; | ||
this.url = url; | ||
this.description = description; | ||
this.type = type; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public DataTypeType getType() { | ||
return type; | ||
} | ||
|
||
public String getDocumentation() { | ||
if (documentation == null) { | ||
documentation = createDocumentation(); | ||
} | ||
return documentation; | ||
} | ||
|
||
private String createDocumentation() { | ||
StringBuilder doc = new StringBuilder(); | ||
doc.append("**"); | ||
doc.append(getName()); | ||
doc.append("**"); | ||
if (!StringUtils.isEmpty(url)) { | ||
doc.append(lineSeparator); | ||
doc.append("See [documentation]("); | ||
doc.append(getUrl()); | ||
doc.append(") for more informations."); | ||
} | ||
return doc.toString(); | ||
} | ||
|
||
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"), DataTypeType.valueOf(attributes.getValue("type"))); | ||
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
Oops, something went wrong.