You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 25, 2026. It is now read-only.
My current LSP integration is based on a personalized/ZLS-specialized derivative of LSP4IntelliJ.
Unfortunately, it doesn't seem like LSP4IJ support core functionality that ZigBrains/ZLS depends on, such as textDocument/semanticTokens (for really good code coloring), so migrating over would be a downgrade compared to the fork of lsp4intellij integrated into ZigBrains.
Additionally, LSP4IJ is licensed under Eclipse Public License 2.0, so I cannot integrate it as deeply into ZigBrains without it affecting the license of the plugin, which I intend on keeping as Apache 2.0 for the foreseeable future.
I'll look at it later once they make progress and actually deliver something that's superior to what I currently have, in a way where I don't need to modify their code to make it work properly.
A re-highlighting request caused by various events calls into the semantic highlighting wrapper method
The semanic token data is fetched (either full, or deltas)
For each semantic token edit, it's decoded using TokenDecoder, which uses the color values from ZigAttributes, which are exposed in the language color settings gui. This is a hardcoded set of semantic tokens, so any change in ZLS's tokens needs a ZigBrains update to compensate.
In the initial versions of ZigBrains, I was completely avoiding the PSI system because it felt overwhelming to try to glue it together with LSP4IntelliJ, which used its own purely text-based system, so I had to rely on non-PSI apis for the semantic token highlighting, and I just never got around to porting it over to the correct PSI-based highlighter once I eventually gave in and implemented a proper PSI parser for zig.
(This is also the biggest reason why i would gladly migrate to LSP4IJ, the ballerina lsp adapter is just a maintenance nightmare at this point.)
In the initial versions of ZigBrains, I was completely avoiding the PSI system because it felt overwhelming to try to glue it together with LSP4IntelliJ, which used its own purely text-based system, so I had to rely on non-PSI apis for the semantic token highlighting, and I just never got around to porting it over to the correct PSI-based highlighter once I eventually gave in and implemented a proper PSI parser for zig.
(This is also the biggest reason why i would gladly migrate to LSP4IJ, the ballerina lsp adapter is just a maintenance nightmare at this point.)
I see totally what you mean and it was very hard to implement lsp feature without having a PsiFile parsed with the proper tokens.
LSP4IJ uses only extension point to implement feature like hover or go to declaration compare to ballerina lsp which implement those features at hand.
For lsp semantic tokens I would like to use too an extension point to be sure that in the future it will continue to work again.
Perhaps semantic highlighting is a bad idea, so if it that we could perhaps implement a syntaxic highlighter like textmate does and it is not linked to PsiElement
One main difference I've noticed between LSP4IJ and the ballerina LSP adapter, is that there is no simple way of attaching custom "hooks" to LanguageServer events, so I had to hook my semantic tokens refresh logic to didOpen/didChange via the ConnectionProvider's handleMessage method.
See the updated HighlightingUtil class for the new implementation of the semantic tokens logic.
What is your first feeling? Do you see some improvement or regression in term in feature?
One main difference I've noticed between LSP4IJ and the ballerina LSP adapter, is that there is no simple way of attaching custom "hooks" to LanguageServer events, so I had to hook my semantic tokens refresh logic to didOpen/didChange via the ConnectionProvider's handleMessage method.
I haven't noticed any major regressions, and autocomplete feels much more reliable compared to the old one.
The only blocker issues at this point is jumping to links in documentations causing an external editor to open, but I can see that there's already an open issue for it, so I will just wait until the next LSP4IJ update, then I will also push an update for ZB.
As for the semantic tokens, the best way to implement it in upstream, in my opinion, could be via a custom extension point, where a specific language server + language pair could have a "color provider" interface, such as:
publicinterfaceSemanticTokenColorizer {
/** * {@code null} means "use LSP4IJ fallback colorizer" * {@code Optional.empty()} means "no color" * And if not empty, use the color */@NullableOptional<TextAttributesKey> getTokenColor(StringtokenType, Set<String> tokenModifiers);
}
If no colorizer extension is specified for a server+language pair, use the previously mentioned fallback colorizer, which would map the predefined LSP semantic token types to DefaultLanguageHighlighterColors, for example:
com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter and com.falsepattern.zigbrains.zig.ide.ZigAttributes contain a pretty extensive mapping for various token + modifier combinations used by ZLS+Zig, but most of them should also apply for any language.
The only blocker issues at this point is jumping to links in documentations causing an external editor to open, but I can see that there's already an open issue for it, so I will just wait until the next LSP4IJ update, then I will also push an update for ZB.
Indeed I have created a PR with tests that my team will review next week. The fix should be available soon in 0.0.3 but it will be available only in nightly build not in release.
Tests for LSP features like completion should be easy to read and write it since it uses LSP trace console. If you want to add tests with your ls to be sure that LSP4IJ will not break your ls please create PRs.
As for the semantic tokens, the best way to implement it in upstream, in my opinion, could be via a custom extension point, where a specific language server + language pair could have a "color provider" interface, such as:
publicinterfaceSemanticTokenColorizer {
/** * {@code null} means "use LSP4IJ fallback colorizer" * {@code Optional.empty()} means "no color" * And if not empty, use the color */@NullableOptional<TextAttributesKey> getTokenColor(StringtokenType, Set<String> tokenModifiers);
}
If no colorizer extension is specified for a server+language pair, use the previously mentioned fallback colorizer, which would map the predefined LSP semantic token types to DefaultLanguageHighlighterColors, for example:
com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighter and com.falsepattern.zigbrains.zig.ide.ZigAttributes contain a pretty extensive mapping for various token + modifier combinations used by ZLS+Zig, but most of them should also apply for any language.
My first goal is to have a semanticTokens support in a PR. If it works correctly we could discuss again to customize it with your suggestion.
The cancel support will work too since LSP4IJ support it.
I've began testing the lsp4ij semantic tokens on a local dev branch, the only blocker now is just a typo that suppresses semanticTokensColorsProvider (redhat-developer/lsp4ij#405), but aside from that, the semantic tokens seem to be working perfectly (with the default color scheme from lsp4ij).
I've began testing the lsp4ij semantic tokens on a local dev branch, the only blocker now is just a typo that suppresses semanticTokensColorsProvider (redhat-developer/lsp4ij#405), but aside from that, the semantic tokens seem to be working perfectly (with the default color scheme from lsp4ij).
It is a great news! And thanks for your PR, I have merged it.
Tried it on PyCharm 2024.1.4. It didn't detect my zls on the path (installed from homebrew), I had to set the full path manually.
It seems to work fine except for some reason, no hover requests are sent to the server. @angelozerr?
Injecting myself into this discussion to ask if integration with the built-in LSP support has been considered for Ultimate (and other paid IDEs) users. See here.
Not that it's important since the free alternatives work nicely, but just wondering if it would be feasible.
@FalsePattern I'm curious to know when do you plan on releasing your LSP4IJ-powered ZigBrains version?
Once LSP4IJ 0.3.0 is released. The 16.0.0 preview of zigbrains depends on APIs added in that version, but it's still in just nightly releases, so i can't publish it on the marketplace.
Adding the lsp4ij nightlies updater URL to your custom plugin repositories(same way, URL: https://plugins.jetbrains.com/plugins/nightly/23257)
Restart the IDE, and you should be able to download ZB 16.0.0-pre1
Activity
FalsePattern commentedon Jun 19, 2024
My current LSP integration is based on a personalized/ZLS-specialized derivative of LSP4IntelliJ.
Unfortunately, it doesn't seem like LSP4IJ support core functionality that ZigBrains/ZLS depends on, such as
textDocument/semanticTokens(for really good code coloring), so migrating over would be a downgrade compared to the fork of lsp4intellij integrated into ZigBrains.Additionally, LSP4IJ is licensed under Eclipse Public License 2.0, so I cannot integrate it as deeply into ZigBrains without it affecting the license of the plugin, which I intend on keeping as Apache 2.0 for the foreseeable future.
I'll look at it later once they make progress and actually deliver something that's superior to what I currently have, in a way where I don't need to modify their code to make it work properly.
angelozerr commentedon Jun 19, 2024
Thanks @FalsePattern for your answer and I understand that you can use LSP4IJ for now.
The issue exists redhat-developer/lsp4ij#238
It is amazing that you have implemented this semanticTokens. I will see your code to try to implement the feature.
Is there any other support which misses in LSP4IJ ?
/cc @fbricon
angelozerr commentedon Jun 19, 2024
Lsp4ij is not a library but a plugin that you install.
FalsePattern commentedon Jun 19, 2024
The way I use semanticTokens is the following:
TokenDecoder, which uses the color values from ZigAttributes, which are exposed in the language color settings gui. This is a hardcoded set of semantic tokens, so any change in ZLS's tokens needs a ZigBrains update to compensate.Editor.getMarkupModel() .getAllHighlighters,removeAllHighlighters,removeHighlighter,addRangeHighlighterRelevant code:
ZLSEditorEventManager.java
HighlightingUtil.java
SemaEdit, SemaRange, ZigAttributes
angelozerr commentedon Jun 19, 2024
Thanks for your feedback.
I wonder if it should be cleaner to provide an implementation of semantic highlighting https://github.com/JetBrains/intellij-community/tree/idea/241.17890.1/platform/analysis-impl/src/com/intellij/codeInsight/daemon/RainbowVisitor.java like explained at https://plugins.jetbrains.com/docs/intellij/syntax-highlighting-and-error-highlighting.html ?
FalsePattern commentedon Jun 19, 2024
In the initial versions of ZigBrains, I was completely avoiding the PSI system because it felt overwhelming to try to glue it together with LSP4IntelliJ, which used its own purely text-based system, so I had to rely on non-PSI apis for the semantic token highlighting, and I just never got around to porting it over to the correct PSI-based highlighter once I eventually gave in and implemented a proper PSI parser for zig.
(This is also the biggest reason why i would gladly migrate to LSP4IJ, the ballerina lsp adapter is just a maintenance nightmare at this point.)
angelozerr commentedon Jun 19, 2024
I see totally what you mean and it was very hard to implement lsp feature without having a PsiFile parsed with the proper tokens.
LSP4IJ uses only extension point to implement feature like hover or go to declaration compare to ballerina lsp which implement those features at hand.
For lsp semantic tokens I would like to use too an extension point to be sure that in the future it will continue to work again.
Perhaps semantic highlighting is a bad idea, so if it that we could perhaps implement a syntaxic highlighter like textmate does and it is not linked to PsiElement
FalsePattern commentedon Jun 22, 2024
I've successfully migrated to LSP4IJ in this branch: https://github.com/FalsePattern/ZigBrains/tree/lsp4ij
One main difference I've noticed between LSP4IJ and the ballerina LSP adapter, is that there is no simple way of attaching custom "hooks" to LanguageServer events, so I had to hook my semantic tokens refresh logic to
didOpen/didChangevia the ConnectionProvider's handleMessage method.See the updated HighlightingUtil class for the new implementation of the semantic tokens logic.
angelozerr commentedon Jun 22, 2024
That is a great news for LSP4IJ !
What is your first feeling? Do you see some improvement or regression in term in feature?
Indeed today we have not this kind of mechanism . I think it is the same request than redhat-developer/lsp4ij#380 (comment)
Thanks! I have started to implement RainbowVisitor and your code will help me a lot!
FalsePattern commentedon Jun 22, 2024
I haven't noticed any major regressions, and autocomplete feels much more reliable compared to the old one.
The only blocker issues at this point is jumping to links in documentations causing an external editor to open, but I can see that there's already an open issue for it, so I will just wait until the next LSP4IJ update, then I will also push an update for ZB.
As for the semantic tokens, the best way to implement it in upstream, in my opinion, could be via a custom extension point, where a specific language server + language pair could have a "color provider" interface, such as:
If no colorizer extension is specified for a server+language pair, use the previously mentioned fallback colorizer, which would map the predefined LSP semantic token types to
DefaultLanguageHighlighterColors, for example:com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighterandcom.falsepattern.zigbrains.zig.ide.ZigAttributescontain a pretty extensive mapping for various token + modifier combinations used by ZLS+Zig, but most of them should also apply for any language.angelozerr commentedon Jun 22, 2024
Great! And now you can enjoy with LSP console https://github.com/redhat-developer/lsp4ij/blob/main/docs%2FUserGuide.md
Indeed I have created a PR with tests that my team will review next week. The fix should be available soon in 0.0.3 but it will be available only in nightly build not in release.
Please note we start having a lot tests in https://github.com/redhat-developer/lsp4ij/tree/main/src%2Ftest%2Fjava%2Fcom%2Fredhat%2Fdevtools%2Flsp4ij to avoid having regressions.
Tests for LSP features like completion should be easy to read and write it since it uses LSP trace console. If you want to add tests with your ls to be sure that LSP4IJ will not break your ls please create PRs.
Here a sample with GO language server https://github.com/redhat-developer/lsp4ij/blob/main/src%2Ftest%2Fjava%2Fcom%2Fredhat%2Fdevtools%2Flsp4ij%2Ffeatures%2Fcompletion%2FGoCompletionTest.java
My first goal is to have a semanticTokens support in a PR. If it works correctly we could discuss again to customize it with your suggestion.
The cancel support will work too since LSP4IJ support it.
FalsePattern commentedon Jul 4, 2024
I've began testing the lsp4ij semantic tokens on a local dev branch, the only blocker now is just a typo that suppresses
semanticTokensColorsProvider(redhat-developer/lsp4ij#405), but aside from that, the semantic tokens seem to be working perfectly (with the default color scheme from lsp4ij).angelozerr commentedon Jul 4, 2024
It is a great news! And thanks for your PR, I have merged it.
fbricon commentedon Jul 4, 2024
@FalsePattern Nightly LSP4IJ 0.3.0-20240704-134935 has been published with your fix
FalsePattern commentedon Jul 4, 2024
Preview build published here:
https://github.com/FalsePattern/ZigBrains/releases/tag/16.0.0-pre1
fbricon commentedon Jul 4, 2024
Tried it on PyCharm 2024.1.4. It didn't detect my zls on the path (installed from homebrew), I had to set the full path manually.
It seems to work fine except for some reason, no hover requests are sent to the server. @angelozerr?
fbricon commentedon Jul 4, 2024
@angelozerr looks like no hover for any LS on pycharm now, using latest nightly build 🙃
angelozerr commentedon Jul 4, 2024
I did nothing about hover?
fbricon commentedon Jul 5, 2024
my bad about hover. For some reason screen reader support got enabled, which disabled hover.

lppedd commentedon Jul 16, 2024
Injecting myself into this discussion to ask if integration with the built-in LSP support has been considered for Ultimate (and other paid IDEs) users. See here.
Not that it's important since the free alternatives work nicely, but just wondering if it would be feasible.
FalsePattern commentedon Jul 16, 2024
The built in LSP has way less features than lsp4ij at this point, it's not even worth the effort.
lppedd commentedon Jul 16, 2024
Makes sense! Thanks for the info.
fbricon commentedon Jul 16, 2024
@FalsePattern I'm curious to know when do you plan on releasing your LSP4IJ-powered ZigBrains version?
FalsePattern commentedon Jul 16, 2024
Once LSP4IJ 0.3.0 is released. The 16.0.0 preview of zigbrains depends on APIs added in that version, but it's still in just nightly releases, so i can't publish it on the marketplace.
https://github.com/redhat-developer/lsp4ij/milestone/3
angelozerr commentedon Jul 16, 2024
@fbricon I think we can release LSP4IJ 0.3.0.
Badly I will not have time to do that, if you can do that it should be very cool.
FalsePattern commentedon Jul 16, 2024
In the meantime, you can install the nightly versions by:
https://plugins.jetbrains.com/plugins/nightly/23257)