Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

What about using LSP4IJ ? #53

Closed
Closed

Description

@angelozerr

Activity

  1. FalsePattern commented on Jun 19, 2024

    @FalsePattern
    Owner

    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.

  2. added
    enhancement
    on Jun 19, 2024
  3. angelozerr commented on Jun 19, 2024

    @angelozerr
    Author

    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

  4. angelozerr commented on Jun 19, 2024

    @angelozerr
    Author

    where I don't need to modify their code to make it work properly

    Lsp4ij is not a library but a plugin that you install.

  5. FalsePattern commented on Jun 19, 2024

    @FalsePattern
    Owner

    The way I use semanticTokens is the following:

    1. A re-highlighting request caused by various events calls into the semantic highlighting wrapper method
    2. The semanic token data is fetched (either full, or deltas)
    3. 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.
    4. Lastly, i just use these range tokens to add/remove highlighter blocks via Editor.getMarkupModel() .getAllHighlighters,removeAllHighlighters,removeHighlighter,addRangeHighlighter
      Relevant code:
      ZLSEditorEventManager.java
      HighlightingUtil.java
      SemaEdit, SemaRange, ZigAttributes
  6. FalsePattern commented on Jun 19, 2024

    @FalsePattern
    Owner

    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.)

  7. angelozerr commented on Jun 19, 2024

    @angelozerr
    Author

    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

  8. FalsePattern commented on Jun 22, 2024

    @FalsePattern
    Owner

    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/didChange via the ConnectionProvider's handleMessage method.

    See the updated HighlightingUtil class for the new implementation of the semantic tokens logic.

  9. angelozerr commented on Jun 22, 2024

    @angelozerr
    Author

    I've successfully migrated to LSP4IJ in this branch: https://github.com/FalsePattern/ZigBrains/tree/lsp4ij

    That is a great news for LSP4IJ !

    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.

    Indeed today we have not this kind of mechanism . I think it is the same request than redhat-developer/lsp4ij#380 (comment)

    See the updated HighlightingUtil class for the new implementation of the semantic tokens logic.

    Thanks! I have started to implement RainbowVisitor and your code will help me a lot!

  10. FalsePattern commented on Jun 22, 2024

    @FalsePattern
    Owner

    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:

    public interface SemanticTokenColorizer {
        /**
         * {@code null} means "use LSP4IJ fallback colorizer"
         * {@code Optional.empty()} means "no color"
         * And if not empty, use the color
         */
        @Nullable Optional<TextAttributesKey> getTokenColor(String tokenType, 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:

    "string" -> STRING
    "keyword" -> KEYWORD
    "function" -> FUNCTION_CALL
    "function", ["declaration"] -> FUNCTION_DECLARATION
    etc.
    

    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.

  11. angelozerr commented on Jun 22, 2024

    @angelozerr
    Author

    I haven't noticed any major regressions, and autocomplete feels much more reliable compared to the old one.

    Great! And now you can enjoy with LSP console https://github.com/redhat-developer/lsp4ij/blob/main/docs%2FUserGuide.md

    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.

    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

    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:

    public interface SemanticTokenColorizer {
        /**
         * {@code null} means "use LSP4IJ fallback colorizer"
         * {@code Optional.empty()} means "no color"
         * And if not empty, use the color
         */
        @Nullable Optional<TextAttributesKey> getTokenColor(String tokenType, 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:

    "string" -> STRING
    "keyword" -> KEYWORD
    "function" -> FUNCTION_CALL
    "function", ["declaration"] -> FUNCTION_DECLARATION
    etc.
    

    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.

  12. FalsePattern commented on Jul 4, 2024

    @FalsePattern
    Owner

    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).

  13. angelozerr commented on Jul 4, 2024

    @angelozerr
    Author

    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.

  14. fbricon commented on Jul 4, 2024

    @fbricon

    @FalsePattern Nightly LSP4IJ 0.3.0-20240704-134935 has been published with your fix

  15. fbricon commented on Jul 4, 2024

    @fbricon

    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?

  16. fbricon commented on Jul 4, 2024

    @fbricon

    @angelozerr looks like no hover for any LS on pycharm now, using latest nightly build 🙃

  17. angelozerr commented on Jul 4, 2024

    @angelozerr
    Author

    I did nothing about hover?

  18. fbricon commented on Jul 5, 2024

    @fbricon

    my bad about hover. For some reason screen reader support got enabled, which disabled hover.
    Screenshot 2024-07-05 at 10 22 54

  19. lppedd commented on Jul 16, 2024

    @lppedd

    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.

  20. FalsePattern commented on Jul 16, 2024

    @FalsePattern
    Owner

    The built in LSP has way less features than lsp4ij at this point, it's not even worth the effort.

  21. lppedd commented on Jul 16, 2024

    @lppedd

    Makes sense! Thanks for the info.

  22. fbricon commented on Jul 16, 2024

    @fbricon

    @FalsePattern I'm curious to know when do you plan on releasing your LSP4IJ-powered ZigBrains version?

  23. FalsePattern commented on Jul 16, 2024

    @FalsePattern
    Owner

    @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.

    https://github.com/redhat-developer/lsp4ij/milestone/3

  24. angelozerr commented on Jul 16, 2024

    @angelozerr
    Author

    @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.

  25. FalsePattern commented on Jul 16, 2024

    @FalsePattern
    Owner

    In the meantime, you can install the nightly versions by:

    1. Adding the zigbrains updater URL to your custom plugin repositories (see: https://github.com/FalsePattern/ZigBrains?tab=readme-ov-file#installing)
    2. Adding the lsp4ij nightlies updater URL to your custom plugin repositories(same way, URL: https://plugins.jetbrains.com/plugins/nightly/23257)
    3. Restart the IDE, and you should be able to download ZB 16.0.0-pre1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions