Repository navigation
Description
First, thank you for your great work!!!
And now:
I have written my own parser for my RobotCode plugin based on LSP4IJ. Actually, I extended the TextMate parser from IntelliJ to adapt it to the requirements of the Robot Framework language and to provide it with its own settings page for coloring and so on, but also to use the VSCode tmLanguage file.
Robot Framework is not a programming language in the traditional sense but rather a documentation language for business test cases. Therefore, many of the predefined token types like Keyword/Class/Method in the predefined TextMate scopes as well as the predefined types of the LSP Semantic Tokens don't really fit. This is no big thing in VSCode, because you can define your editor.tokenColorCustomizations in your vscode package, but in the Intellij platform this is not really possible and you have to define your TextAttributes by hand in code.
Most of the work is handled by my extended TextMate parser, and then the semantic tokens just add a few extensions, such as embedded arguments in keywords or specific scopes like built-ins, test templates or i18n things etc.
Robot Framework/TextMate coloring works, but my problem now is that the semantic token highlights are not displayed in PyCharm since LSP4IJ Version 0.12 or maybe 0.11, with 0.10 it is working.
The reason why they are not displayed is quite simple: in
Line 89 in 481bf4f
| if (lazyInfos == null || !(element instanceof LeafElement)) |
LeafElement. This may make sense in some cases, but in my case, it is not appropriate because there are no LeafElements in the TextMate parser. However, I am not sure if it is really necessary, as no methods of LeafElement are used in the visit method.
So, I thought, okay, then I'll write my own HighlightVisitor for Robot Framework by deriving it from LSPSemanticTokensHighlightVisitor in LSP4IJ and overriding the relevant methods.
That doesn't work either, as the internals like holder and lazyInfos, as well as the highlightSemanticTokens method, are private.
Then I thought I would write my own HighlightVisitor here and reimplement the logic in Kotlin, which I find quite valid. This works, but my plugin no longer passes the Plugin Approval process because I use internal APIs since the LSPFileSupport class in LSP4IJ is marked as Internal.
Now, my questions are:
- Does
LSPFileSupportreally need to beinternal? - Could
LSPSemanticTokensHighlightVisitorbe modified to not check forLeafElement? - Or could
LSPSemanticTokensHighlightVisitorbe implemented in such a way that it is easier to derive from and perhaps also provides access to the internals, e.g., by making themprotected? - Maybe a version of
LSPSemanticTokensHighlightVisitorthat just highlights without checking whether the file is of a certain type or whether the element is derived fromLeafElementcould be provided. This could then be used for custom implementations. - What other options are there to make this work?
Hope that is understandable, and thanks in advance for a response! ;-)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
angelozerr commentedon May 13, 2025
Thanks so much for your great feedback. I have set a lot of code in internal because I do a lot of refactoring, so it is not possible for instance to provide LSPFileSupport as non internal.
To customize LSP behaviour in LSP4IJ iq to use LSP-API.
For instance to customize LSP semantic features, see https://github.com/redhat-developer/lsp4ij/blob/main/docs/LSPApi.md#lsp-semanticTokens-feature to add for instance your own TextAttribute key.
TextAttributesKey getTextAttributesKey(@NotNull String tokenType, List tokenModifiers, PsiFile file)You can do that with
LSPSemanticTokensFeature#TextAttributesKey getTextAttributesKey(@NotNull String tokenType, List tokenModifiers, PsiFile file)right?
No please do not that because
will return true and you will have 2 LSP semantic highlight visitor which will be processed
If I understand you:
Is only that?
I don't want to provide access to LSPFileSupport because I spend my time to do some refactoring.
Yes, because it the core of LSP feature which change every time.
Yes we could do that with a new methode API like LSPSemanticFeatures#canVisit(PsiElement element, boolean hasLazyInfos) for instance.
But what about the order of action.run()?
Just one question you PsiFile is not a TextMate PsiFile?
No because you will have several LSP semantic tokens which will be processed.
LSPSemanticFeatures#canVisit(PsiElement element, boolean hasLazyInfos)is the best idea I think.feat: Make LSPSemanticTokensHighlightVisitor More Extensible and
feat: Make LSPSemanticTokensHighlightVisitor More Extensible and
feat: Make LSPSemanticTokensHighlightVisitor More Extensible and
feat: Make LSPSemanticTokensHighlightVisitor More Extensible and
feat: Make LSPSemanticTokensHighlightVisitor More Extensible and
feat: Make LSPSemanticTokensHighlightVisitor More Extensible and
feat: Make LSPSemanticTokensHighlightVisitor More Extensible and
angelozerr commentedon May 14, 2025
@d-biehl see doc at https://github.com/redhat-developer/lsp4ij/blob/main/docs/LSPApi.md#lsp-semanticTokens-feature
If I understand your need you need to override shouldVisitPsiElement to return false.
angelozerr commentedon May 14, 2025
@d-biehl please install LSP4IJ 0.13.0 which should be available on marketplace.
d-biehl commentedon May 14, 2025
I started writing a longer response last night, but since it was already so late, I decided to get some sleep and continue today... And what do I find?
Yeah: You got me, and that's exactly what I needed!!! That saves me a lot of work and unnecessary code. Thanks!!!
angelozerr commentedon May 14, 2025
That's super great that LSP API can help you. Thanks for your feedback.
If you like LSP4IJ don't hesitate to add a review in JetBrains marketplace to help us to promote LSP4IJ.
feat: a semantic token with the modifier deprecated is struck through…
feat: a semantic token with the modifier deprecated is struck through…