eclipse-lsp4j / lsp4j

A Java implementation of the language server protocol intended to be consumed by tools and language servers implemented in Java.
https://eclipse.org/lsp4j
Other
582 stars 141 forks source link

Are there any examples of color provider? #745

Closed javaduke closed 1 year ago

javaduke commented 1 year ago

I'm working on implementing a language server using LSP4J for a custom language, and I couldn't find any example of how to create a color provider. I understand I have to have res.getCapabilities().setColorProvider(Boolean.TRUE); but then it's not quite clear to me what information should I return in documentColor method. Any example or tutorial would help.

nixel2007 commented 1 year ago

Hi. You can check bsl language server:

https://github.com/1c-syntax/bsl-language-server/blob/develop/src/main/java/com/github/_1c_syntax/bsl/languageserver/providers/ColorProvider.java

https://github.com/1c-syntax/bsl-language-server/tree/develop/src/main/java/com/github/_1c_syntax/bsl/languageserver/color

angelozerr commented 1 year ago

LemMinx, the XML language server used in Eclipse IDE and vscode provides color support https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLColorsFeatures.md

LemMinx which is extensible works with participant, here the participant which support colors https://github.com/eclipse/lemminx/blob/main/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/colors/participants/XMLDocumentColorParticipant.java

You can see some test at

https://github.com/eclipse/lemminx/blob/main/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/colors/XMLColorsExtensionsTest.java

javaduke commented 1 year ago

Perfect, exactly what I was looking for.