TODO...
java -classpath ... org.eclipse.lsp4xml.XMLServerLauncher
To see how current implementations of this language server send configurations, refer to VSCode XML.
- Go to preferences and set
xml.trace.server
toverbose
- With an XML file open, go to View -> Output -> XML Support (top right drop down menu)
- Ctrl + f, and search for 'workspace/didChangeConfiguration'
Settings for didChangeConfiguration and initializationOptions must follow this JSON format:
"settings": {
"xml": {
"trace": {
"server": "verbose"
},
"catalogs": [],
"logs": {
"client": true,
"file": "/home/.../lsp4xml.log"
},
"format": {
"splitAttributes": true,
"joinCDATALines": false,
"joinContentLines": false,
"joinCommentLines": false,
"spaceBeforeEmptyCloseTag": false,
"enabled": true
}
}
}
Here a sample of JSON request message for "initialize":
{
"jsonrpc":"2.0",
"id":"1",
"method":"initialize",
"params":{
"processId":17880,
"rootPath":"test/",
"rootUri":"/test/",
"initializationOptions":{
"settings":{
"xml":{
"trace":{
"server":"verbose"
},
"catalogs":[
],
"logs":{
"client":true,
"file":"/home/.../lsp4xml.log"
},
"format":{
"splitAttributes":true,
"joinCDATALines":false,
"joinContentLines":false,
"joinCommentLines":false,
"spaceBeforeEmptyCloseTag":false,
"enabled":true
}
}
}
}
}
}
- Only send 'file' on initialization
{
...
"logs": {
"client": true,
"file": "path/to/file"
}
}
- client: Should LSP message be sent to the client when logging.
- file: Path to the file for log messages to be output.
{
"catalogs": [
"catalog.xml",
"catalog2.xml"
]
}
You can associate an XML file pattern with a XML Schema to use. It gives you the capability to benefit with validation and completion based on XML Schema without declaring it in your XML file.
Here a sample which associate the Eclipse file .project
file with the XML Schema projectDescription.xsd
{
"fileAssociations": [{
"systemId": "C:\\org.eclipse.lsp4xml\\src\\test\\resources\\xsd\\projectDescription.xsd",
"pattern": ".project"
}]
}
fileAssociations is an array of association:
- systemId: file path of the XML Schema, DTD
- pattern: file name pattern where you can use '*', '?' (it uses Java glob NIO)
With this association, you benefit with validation and completion for file .project
although it doesn't declare DTD or XMl Schema:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.lsp4xml</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
In the LSP, the following options are given by FormattingOptions so it is not necessary to pass these as configurations
- insertSpaces: indent using spaces
- tabSize: amount of spaces to indent by if insertSpaces == true
*It is not necessary to include each option, missing options while be set to a default value shown below.
{
...
"format": {
"enabled": true,
"splitAttributes": false,
"joinCDATALines": false,
"joinCommentLines": false,
"formatComments": true,
"joinContentLines": false,
"spaceBeforeEmptyCloseTag": true
}
}
- enabled: is able to format document
- splitAttributes: each attribute is formatted onto new line
- joinCDATALines: normalize content inside CDATA
- joinCommentLines: normalize content inside comments
- formatComments: keep comment in relative position
- joinContentLines: normalize content inside elements
- spaceBeforeEmptyCloseTag: insert whitespace before self closing tag end bracket
If a capability is sent from the client on 'initialize' indicating it
supports 'dynamicRegistration' then the server can support enabling/disabling
of the capability by the following:
- Note: all dynamicRegistration capabilities are by default, true.
{
...
"capabilities": {
"formatting": true
}
}
Supported enabling/disabling:
- formatting
- Note: all completion settings are by default, true.
{
...
"completion": {
"autoCloseTags": true
}
}
- autoCloseTags: When a start tag is typed the closing tag is automatically inserted as well,
also schema completion will auto close tags if this is enabled.
Determines if schema's are cached on the system
{
...
"useCache": true
}
Ability to enable/disable validation.
{
...
"validation": {
"noGrammar": "hint",
"enabled": true,
"schema": true
}
}
- noGrammar: The message severity when a document has no associated grammar.
Values: ["ignore", "hint", "info", "warning", "error"] - enabled: True to enable all validation/diagnostics. Else false.
- schema: True to enable all schema validation/diagnostics. Else false.