Git Product home page Git Product logo

lemminx's Introduction

XML Language Server (LemMinX)

Maven Eclipse Site Build Status CodeQL Status LICENSE

LemMinX is a XML language specific implementation of the Language Server Protocol and can be used with any editor that supports the protocol, to offer good support for the XML Language. The server is based on:

  • Eclipse LSP4J, the Java binding for the Language Server Protocol.
  • Xerces to manage XML Schema validation, completion and hover

Features

See screenshots in the Features docs.

See the changelog for the latest release.

Demo

XML Language Server Demo

Get started

  • Clone this repository
  • Open the folder in your terminal / command line
  • Run ./mvnw clean verify (OSX, Linux) or mvnw.cmd clean verify (Windows)
  • After successful compilation you can find the resulting org.eclipse.lemminx-uber.jar in the folder org.eclipse.lemminx/target

Developer

To debug the XML LS you can use XMLServerSocketLauncher:

  1. Run the XMLServerSocketLauncher in debug mode (e.g. in eclipse)
  2. Connect your client via socket port. Default port is 5008, but you can change it with start argument --port in step 1

Client connection example using Theia and TypeScript:

let socketPort = '5008'
console.log(`Connecting via port ${socketPort}`)
const socket = new net.Socket()
const serverConnection = createSocketConnection(socket,
    socket, () => {
        socket.destroy()
    });
this.forward(clientConnection, serverConnection)
socket.connect(socketPort)

Generating a native binary:

To generate a native binary:

  • Install GraalVM 20.2.0
  • In a terminal, run gu install native-image
  • Execute a Maven build that sets the flag native: ./mvnw clean package -Dnative -DskipTests
    • On Linux, compile with ./mvnw clean package -Dnative -DskipTests -Dgraalvm.static=--static in order to support distributions that don't use glibc, such as Alpine Linux
  • It will generate a native binary in org.eclipse.lemminx/target/lemminx-{os.name}-{architecture}-{version}

OS specific instructions:

  • Linux:
    • Make sure that you have installed the static versions of the C++ standard library
      • For instance, on Fedora Linux, install glibc-static, libstdc++-static, and zlib-static
  • Windows:
    • When installing native-image, please note that gu is an existing alias in PowerShell. Remove the alias with Remove-Item alias:gu -Force, refer to gu with the absolute path, or use gu under cmd.exe.
    • Make sure to run the Maven wrapper in the "Native Tools Command Prompt". This command prompt can be obtained through installing the Windows SDK or Visual Studio, as mentioned in the GraalVM installation instructions.

native-image Development Instructions:

  • Reflection:
    • If you need to use reflection to access a private field/method, simply register the field/methods that you access in reflect-config.json
    • If you need to parse some JSON using Gson, make sure to register the fields and methods of the class that you are parsing into in reflect-config.json
      • This needs to be done recursively, for all classes that it has member variables of, including enums
      • Settings are all deserialized, so whenever a setting is added, make sure to register the classes
    • Manually test the binary and check the logs for reflection errors/NPEs

Maven coordinates:

Here are the Maven coordinates for lemminx (replace the X.Y.Z version with the latest release):

<dependency>
    <groupId>org.eclipse.lemminx</groupId>
    <artifactId>org.eclipse.lemminx</artifactId>
    <version>X.Y.Z</version>
    <!-- classifier:uber includes all dependencies -->
    <classifier>uber</classifier>
</dependency>

for Gradle:

compile(group: 'org.lemminx', name: 'org.eclipse.lemminx', version: 'X.Y.Z', classifier: 'uber')

You will have to reference the Maven repository hosting the dependency you need. E.g. for Maven, add this repository to your pom.xml or settings.xml :

<repository>
  <id>lemminx-releases</id>
  <url>https://repo.eclipse.org/content/repositories/lemminx-releases/</url>
  <snapshots>
    <enabled>false</enabled>
  </snapshots>
  <releases>
    <enabled>true</enabled>
  </releases>
</repository>

And if you want to consume the SNAPSHOT builds instead:

<repository>
  <id>lemminx-snapshots</id>
  <url>https://repo.eclipse.org/content/repositories/lemminx-snapshots/</url>
  <releases>
    <enabled>false</enabled>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>

Verify 3rd Party Libraries

Currently generating the IP Log report requires a Java Runtime Environment (JRE) >= 11.

Run ./mvnw clean verify -Pverify-iplog to generate a report for the 3rd party libraries used by this project. See the Eclipse Project Handbook for further details.

Clients

Here are some clients consuming this XML Language Server:

Extensions

The XML Language Server can be extended to provide additional validation and assistance. Read the LemMinX-Extensions docs for more information

lemminx's People

Contributors

akurtakov avatar angelozerr avatar aobuchow avatar balduinlandolt avatar datho7561 avatar dependabot[bot] avatar dhuebner avatar dkwon17 avatar eclipse-lemminx-bot avatar fbricon avatar gitmensch avatar jdneo avatar jessicajhee avatar jonburs avatar lacinoire avatar martinlippert avatar mattbsox avatar mickaelistria avatar nikolaskomonen avatar o-farag avatar rgrunber avatar rzgry avatar seiphon avatar snjeza avatar vrubezhny avatar w6et avatar yashtef avatar yatli avatar yeikel avatar zewa666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lemminx's Issues

Parser doesn't consider CDATA

It looks like the parser does not handle CDATA, I'm currently working on implementing this. Let me know if there is anything you would like to discuss.

[Request] Document Formatting

It should be nice to have a formatting XML support. Format should be done:

  • for the whole XML document
  • for selected content of XML document

There are 2 strategies to do that:

We need too defines formatting preferences. Here the WTP/ XML Editor preferences:

image

You can find it at https://github.com/eclipse/webtools.sourceediting/blob/master/xml/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java

Emmet Extension

It should be cool if we could have Emmet support by providing a new Emmet Extension like it exists for teh vscode html language server:

emmetdemo

Guys, it's just an idea, please vote if you like it. Thanks!

Adjust range for XML syntax errors

@NikolasKomonen if you wish to work on adjust range for XML syntax errors, please do that in https://github.com/angelozerr/lsp4xml/blob/master/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/contentmodel/participants/diagnostics/XMLSyntaxErrorCode.java

You can find XML Syntax/Schema error code list at https://wiki.xmldation.com/Support/Validator/. You must filter thoses codes and keep just XML Syntax error code. Me I'm working on XML Schema error code in #72

Please update tests at https://github.com/angelozerr/lsp4xml/blob/master/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/contentmodel/XMLSyntaxDiagnosticsTest.java

To check the adjust to do, I suggest you to consume the lsp4xml language server inside vscode and see if it highlights attributes value, name, elements, etc according the XML syntax error code.

Good luck!

Add support for `textDocument/documentLink`

Add support for textDocument/documentLink https://microsoft.github.io/language-server-protocol/specification#textDocument_documentLink for extension.

One extension for web (web.xml) could manage hyperlink for welcome-file to open it:

<welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
     <welcome-file>index.html</welcome-file>
</welcome-file-list>

One extension for String could manage hyperlink for class to open the Java class:

<bean class="MyClass" />

Split XMLDocument into XMLDocument and TextDocument

XMLDocument provides usefull method like Position positionAt(int position). Some support (like folding, format) doesn't requires the use of XML node, so we parse XML document although we don't need it.

The idea of this issue is to have 2 structures:

  • a TextDocument which provides positionAt, etc
  • XMLDocument which maintains Node structure (and could be initalized with TextDocument to keep positionAt methods)

Support for XML associations

Gives the capability to assocoiate a give file (ex : .project, .classpath) with a XML Schema to benefit with compeltion and validatioin. Indeed Eclispe files .project, .classpath doesn't define an XML Schema in their root. Associate a XMl Schema with a given file name pattern could be helpful.

The question is about file pattern. We could manage at hand '*' pattern like https://github.com/microclimate-devops/xml-language-server/blob/master/server/xml-server/src/com/ibm/ctools/ls/xml/XMLLanguageServer.java#L119 does but I find it's a little limitaed.

My idea @fbricon @NikolasKomonen is to support minimatch pattern with my Minimatch port in Java https://github.com/angelozerr/minimatch.java

Are you OK with this new dependency?

Use another package name than `org.eclipse.xml`

The package name is org.eclipse.xml.... Typical Eclipse projects use an org.eclipse.<projectName> as root package. To avoid necessary further refactoring when moving to Eclipse.org, we should consider deciding of a projectName already and adopt this in package name asap.

Completion settings

Add completion settings (like client snippet support) when completion is done.

Give more settings for Format

It should be cool to give the capability to customize formatting. We need to collect which settings we need and implement the formatting with thoses settings.

Here settings for WTP/XML Editor:

image

Here the HTML formatting option for vscode html language service https://github.com/Microsoft/vscode-html-languageservice/blob/master/src/services/htmlFormatter.ts#L55

let htmlOptions: IBeautifyHTMLOptions = {
		indent_size: options.insertSpaces ? tabSize : 1,
		indent_char: options.insertSpaces ? ' ' : '\t',
		wrap_line_length: getFormatOption(options, 'wrapLineLength', 120),
		unformatted: getTagsFormatOption(options, 'unformatted', void 0),
		content_unformatted: getTagsFormatOption(options, 'contentUnformatted', void 0),
		indent_inner_html: getFormatOption(options, 'indentInnerHtml', false),
		preserve_newlines: getFormatOption(options, 'preserveNewLines', true),
		max_preserve_newlines: getFormatOption(options, 'maxPreserveNewLines', 32786),
		indent_handlebars: getFormatOption(options, 'indentHandlebars', false),
		end_with_newline: includesEnd && getFormatOption(options, 'endWithNewline', false),
		extra_liners: getTagsFormatOption(options, 'extraLiners', void 0),
		wrap_attributes: getFormatOption(options, 'wrapAttributes', 'auto'),
		wrap_attributes_indent_size: getFormatOption(options, 'wrapAttributesIndentSize', void 0),
		eol: '\n'
	};

@NikolasKomonen do you want to work on this issue?

Enable ClientLogHandler with param

Today ClientLogHandler is every time enabled. I don't know if it is the wished behaviour.

If we see the code of LogHelper, the initializationObject cannot be never null (empty but not null)

	public static void initializeRootLogger(LanguageClient newLanguageClient, Map<?, ?> initializationObject) {
		if(newLanguageClient == null || initializationObject == null) {
			return;
		}

So the following code which enable )ClientHandler is done evry time.


	Logger logger = Logger.getLogger("");
		unregisterAllHandlers(logger.getHandlers());
		logger.setLevel(Level.SEVERE);
		logger.setUseParentHandlers(false);// Stops output to console

		try {
			logger.addHandler(LogHelper.getClientHandler(newLanguageClient));
		} catch (Exception e) {
			// TODO: handle exception
		}

To fix that, I think we should:

  • check like this:

if(newLanguageClient == null || initializationObject == null || initializationObject.isEmpty()) {

  • use property

    • lsp4xml.logs.client.enabled to know if client must be enabled or not
    • lsp4xml.logPath should be perhaps replaced with lsp4xml.logs.file.path

What do you think about that?

Add delay for didChange

When modifying the document textDocument/didChange will trigger on each keystroke even if done together quickly. This also ends up triggering validation each time.

A fix, similar to jdtls, should help speed everything up. Unless this whole issue is already handled by something I missed.

Interaction with Eclipse WTP.XML

I see as part of this project tries to implement it's own parser. I think it's a really hard task from short to long term!
Have you consider re-using Eclipse WTP parser or some other parser (like the one used by IntelliJ) to build the server upon?

Don't log to System.err/out

... or call exception.printStackTrace();

stdio is used to exchange messages with the client. Logging to standard streams will break the client/server communication.

Either log messages via a logging facade (slf4j?) to a log file, and/or log messages to the client

Maven wrapper breaks the build

Build failed every time https://travis-ci.org/angelozerr/lsp4xml/builds/422519278?utm_source=email&utm_medium=notification because of

3.45s$ ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
--2018-08-30 12:05:36--  https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar
Resolving repo.maven.apache.org (repo.maven.apache.org)... 151.101.20.215
Connecting to repo.maven.apache.org (repo.maven.apache.org)|151.101.20.215|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2018-08-30 12:05:36 ERROR 403: Forbidden.

@fbricon have you an idea about this problem?

Basic XML validation for no well XML

I don't know if it's an hard task, but I tell me if we could use our XML scanner to validate XML files for no well XML (XML which doesn't end an element tag, etc).

Today, I'm using Xerces to do that, but the main problem is that SAXParserException contains only a start line/character and not the end.

I have studied WTP XML validator and they do like this:

The benefit to do that is that you can highlight the element tag when there is an error.

For the XML Schema error, WTP adjust the start/end location according error message like https://github.com/microclimate-devops/xml-language-server does too.

I would like to follow the same idea than WTP/XML Editor:

  • manage basic XML validation with our XML Scanner tokens. This feature will be managed in the core.
  • manage validation based on XML Schema, DTD, etc with Xerces. Those features will be move to contentmodel extension project.

IMHO, if we can do that, we will have a clean validation mean and it will be easy to extend too validation to valiudate other things (ex: validate java class defines in @Class attribute, etc)

@fbricon @NikolasKomonen what do you think about that?

LoggerTest fails on Windows OS

In Windows OS, when I execute it, I have this error:

Running org.eclipse.lsp4xml.utils.LoggerTest
août 09, 2018 4:52:10 PM org.eclipse.lsp4xml.utils.LoggerTest testLogCreated
GRAVE: @@Log Message@@
Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec <<< FAILURE!
assertTestFormatting(org.eclipse.lsp4xml.utils.LoggerTest)  Time elapsed: 0.001 sec  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[Sep 16, 1997 04:05:05 org.my.test.Class mySourceMethod()
Message: Formatting Log Message
	at declaringClass.methodName(fileName.java:1)
	at declaringClass2.methodName2.drl.java(fileName2.java:2)
	at declaringClass.methodName.apk.java(fileName:3)]
> but was:<[sept. 16, 1997 04:05:05 org.my.test.Class mySourceMethod()
Message: Formatting Log Message
	at declaringClass.methodName(fileName.java:1)
	at declaringClass2.methodName2.drl.java(fileName2.java:2)
	at declaringClass.methodName.apk.java(fileName:3)
]
>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at org.eclipse.lsp4xml.utils.LoggerTest.assertTestFormatting(LoggerTest.java:131)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

@fbricon @NikolasKomonen could you fix this problem please? It seems that date are hard coded in the JUnit test. Thanks!

Add JUnit for tolerant XMLParser

Add JUnit for tolerant XMLParser

@NikolasKomonen please follow this issue to track JUnit that I will do. Once I will push my work, please give me feedback to know if you will like tests and do the same thing for CDATA #5

Comments are not considered in Formatting

The XMLScanner is setup for comments, but it is not handled in XMLFormatting, formatting will remove the comments.

To fix add consideration of comments in XMLParser

Add support for `textDocument/references` for XML Schema types

Add support for textDocument/references https://microsoft.github.io/language-server-protocol/specification#textDocument_references for extension

One extension for XSD could find the references of xs:complexType (references by xs:element, etc) :

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns="http://maven.apache.org/POM/4.0.0" targetNamespace="http://maven.apache.org/POM/4.0.0">
  <xs:element name="project" type="Model">
...
  </xs:element>
  <xs:complexType name="Model">

A Find References did in the "Model" of txs:complexType shoudl return xs:element

Here a references demo with XMLSchema.xsd

XSDReferenceDemo

The references should work with other element like:

  • xs:complexType
  • xs:simpleType
  • xs:element
  • xs:group

Scanner does not handle unclosed tags well

If a tag is not properly closed eg <tag </tag> the scanner will not be smart enough to recognise the start of a new tag.

The scanner should search for the closing tag, while also checking if it sees a new opening tag.
This will be helpful since it will indicate and un-closed tag to every service that uses the Scanner and will prevent incorrect Node structures, Incorrect Document Validations, Formatting...

At most the Scanner will return the new opening bracket Token (eg '<') instead of the wrong closing bracket Token.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.