Repository navigation
Semantic tokens from LS available in the Java editor - #1161
Conversation
2a87bc2 to
347e9d1
Compare
|
@rubenporras I've rebased this PR on the latest from main however I still get the pesky Null Annotations compiler error: I have added JDT UI into eclipse platform with the new |
|
@sebthom Can you please help regarding this null analysis error? |
@BoykoAlex I can reproduce this. It is a limitation of the Eclipse compiler's null analysis. In this case the |
ad75116 to
a2ca2f3
Compare
|
@sebthom many thanks for helping with Null Annotations issue and a code review. Looks like everything is in order to merge this PR now!-) |
I haven't looked at the functionality provided by this PR, but is it reasonable to expect third parties to globally enable/disable this, given there's no UI option to turn it off? Considering potential side effects, wouldn’t it make more sense to have the feature disabled by default (and expect 3rd party plugins to enable it) or to directly provide a UI option to enable/disable it? |
|
@sebthom I was wondering about the same: #1161 (comment) |
| import org.eclipse.lsp4j.Position; | ||
| import org.eclipse.lsp4j.SemanticTokensLegend; | ||
|
|
||
| class JavaSemanticTokensProcessor { |
There was a problem hiding this comment.
This class has a lot of common code with org.eclipse.lsp4e.operations.semanticTokens.SemanticTokensDataStreamProcessor, could we have a common implementation?
| return null; | ||
| } | ||
|
|
||
| private @Nullable SemanticTokensLegend getSemanticTokensLegend(final LanguageServerWrapper wrapper) { |
There was a problem hiding this comment.
This method (and others) is an exact copy of org.eclipse.lsp4e.operations.semanticTokens.SemanticHighlightReconcilerStrategy.getSemanticTokensLegend(LanguageServerWrapper).
Others are very similar. Do you think we could refactor the code to avoid the redundancy?
|
@sebthom @rubenporras Thank you for the review comments. Indeed the code needed quite bit of tidy up! Hopefully looks better now. The build fails because there is something off with the HighlightJS style fetching... host server is down it seems... |
@BoykoAlex @rubenporras Maybe it would make sense to add a "Features" preferences page under "Language Servers" where one can enable/disable semantic tokens and in future other features. |
|
I have added the Java preference page under Language Servers preferences. It's contributed via the LSP4E JDT plugin hence would only be shown for those having the LSP4E JDT plugin... |
e419d09 to
dceec6d
Compare
|
Rebased and squashed commits |
|
@rubenporras @sebthom shall we fold this in? More feedback on the PR is welcomed... |
| return SemanticHighlightReconcilerStrategy.requestFullSemanticTokens(theDocument, (legend, semanticTokens) -> convertTokens(legend, theDocument, semanticTokens)) | ||
| .thenApply(o -> o.orElse(Collections.emptyList())).get(300, TimeUnit.MILLISECONDS); | ||
| } catch (InterruptedException | ExecutionException | TimeoutException e) { | ||
| LanguageServerPlugin.logError("Failed to fetch semantic tokens for '%s' from Language Servers".formatted(resource.getLocation()), e); |
There was a problem hiding this comment.
So far we log TimeoutException as a warning that includes the timeout value, could we do that?
| try { | ||
| return SemanticHighlightReconcilerStrategy.requestFullSemanticTokens(theDocument, (legend, semanticTokens) -> convertTokens(legend, theDocument, semanticTokens)) | ||
| .thenApply(o -> o.orElse(Collections.emptyList())).get(300, TimeUnit.MILLISECONDS); | ||
| } catch (InterruptedException | ExecutionException | TimeoutException e) { |
There was a problem hiding this comment.
Should we not call Thread.currentThread().interrupt() for InterruptedException?
There was a problem hiding this comment.
I suppose we should. Will make this change.
| final var styleRangeHolder = this.styleRangeHolder; | ||
| if (!dataStream.isEmpty() && semanticTokensDataStreamProcessor != null && styleRangeHolder != null) { | ||
| List<StyleRange> styleRanges = semanticTokensDataStreamProcessor.getStyleRanges(dataStream, | ||
| List<StyleRange> styleRanges = semanticTokensDataStreamProcessor.getTokens(dataStream, |
There was a problem hiding this comment.
to call getTokens and to save it into a variable of type StyleRange is a bit awkward, but I do not have a suggestion for a better name at this moment, do you have a better idea?
There was a problem hiding this comment.
getVisualTokens()?
There was a problem hiding this comment.
since it is an ...TokensDataStreamProcessor, maybe getTokensData?
After that I would be happy to merge.
There was a problem hiding this comment.
Sounds good to me - made this change.
| } | ||
|
|
||
| private SemanticTokensParams getSemanticTokensParams() { | ||
| private static SemanticTokensParams getSemanticTokensParams(IDocument document) { |
There was a problem hiding this comment.
I see that the document is still a class field, even though many methods are now static and take it as an argument. Should we maybe split the class so that we do not have methods which take a variable as an argument that hides a field in the class?
There was a problem hiding this comment.
I see, let me look into this...
|
@BoykoAlex , thanks for the reminder, I was very busy the last days and completely forgot this PR. A have made a new round of comments, all but the last one are very minor, thanks for the changes! |
|
@rubenporras I addressed your comments with the exception of the method renaming, i.e. |
02e9c1e to
13cb746
Compare
|
Made requested changes and squashed commits |
|
@rubenporras @sebthom Thank you for the feedback on this PR - much appreciated!-) |

Based on the latest addition of semantic tokens extension for Java editor the support is added for having semantic tokens from the language server in the Java editor.
There is a preference add to turn off semantic tokens support in the Java editor. The preference is defined but the UI is not and is expected to come from 3rd party plugins using this functionality (i.e. spring boot ls plugin) otherwise it's unclear where to fit this preference in the UI at the moment