Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for semanticTokens #446

Merged
merged 4 commits into from
Oct 7, 2020
Merged

Add support for semanticTokens #446

merged 4 commits into from
Oct 7, 2020

Conversation

ericdallo
Copy link
Contributor

@ericdallo ericdallo commented Aug 30, 2020

Closes #430

Add support for textDocument/semanticTokens

Signed-off-by: Eric Dallo [email protected]

@ericdallo
Copy link
Contributor Author

ericdallo commented Aug 30, 2020

Given this, should we remove or deprecate semantic highlights as semantic tokens replace it?

@eclipse-lsp4j-bot
Copy link

Can one of the admins verify this patch?

@kdbeall
Copy link

kdbeall commented Sep 4, 2020

Looks like you beat me to it! Excited to see this. 👍

@ericdallo
Copy link
Contributor Author

@spoenemann Could you take a look? I don't know who to ping here 😅

@spoenemann
Copy link
Contributor

I have little time this week, maybe next one. If anyone else would like to review, go for it.

Copy link
Contributor

@Dufgui Dufgui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this huge works ! It's really a good job !

@ericdallo
Copy link
Contributor Author

Thanks for the review, I'll take a look tomorrow!

@ericdallo
Copy link
Contributor Author

Done @Dufgui

Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Two remarks below.

@ericdallo
Copy link
Contributor Author

Could you review it again @spoenemann ?

Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there.

this.range = range
}

new(@NonNull SemanticTokensLegend legend, SemanticTokensServerFull full, Boolean range, List<DocumentFilter> documentSelector) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specification says it's either a SemanticTokensOptions (with legend) or a SemanticTokensRegistrationOptions (with documentSelector), but not both.

Please also add a no-arguments constructor. In some contexts it's easier to construct the protocol classes with setters, e.g. with Xtend:

options = new SemanticTokensWithRegistrationOptions => [
    legend = ...
    range = ...
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it, what do you suggest?
I thought that this comment suggested merging both classes

Copy link
Contributor

@KamasamaK KamasamaK Oct 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SemanticTokensRegistrationOptions extends SemanticTokensOptions in the spec, so legend would be in both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SemanticTokensRegistrationOptions extends TextDocumentRegistrationOptions, which has a documentSelector, but no legend.

https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#textDocument_semanticTokens

I thought that this comment suggested merging both classes

Yes, but merging the classes is just a workaround because Java's type system is not as flexible as TypeScript. We use a single class to parse / serialize both alternatives of SemanticTokensOptions | SemanticTokensRegistrationOptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, I didn't realize that SemanticTokensRegistrationOptions is actually meant to extend SemanticTokensOptions. Then the current constructors can be kept, but please add one without arguments:

new() {
}

Copy link
Contributor Author

@ericdallo ericdallo Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done @spoenemann. I didn't add an empty constructor before because both SemanticTokensOptions and SemanticTokensRegistrationOptions have non-null legend filed, so I thought that it didn't make sense to add a constructor that doesn't initialize the legend field.

org.eclipse.lsp4j/src/test/xtend-gen/.gitignore Outdated Show resolved Hide resolved
Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@spoenemann spoenemann merged commit 64c5643 into eclipse-lsp4j:master Oct 7, 2020
@ericdallo ericdallo deleted the semantic-tokens-support branch October 7, 2020 13:45
@nixel2007
Copy link
Contributor

nixel2007 commented Oct 7, 2020

woohoo, good news! gonna implement semanticTokens in next release of our ls. thanks!

@nixel2007
Copy link
Contributor

nixel2007 commented Oct 7, 2020

One small question... I can't find any method for textDocument/semanticTokens/* requests in TextDocumentService interface. Like TextDocumentService#completion() for textDocument/completion and so on. Are they missing from current implementation or should I implement some other new interface?

@ericdallo
Copy link
Contributor Author

Yeah, I think I forgot about that @nixel2007
I opened this: #450

* The actual tokens.
*/
@NonNull
private List<Integer> data;
Copy link
Contributor

@nixel2007 nixel2007 Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for pinging closed PR, but shouldn't we migrate List<Integer> to int[]? It's a huge list/array with a lot of Integer boxing/unboxing operations. Yes, List is more comfortable class with all its Collection methods. But is it fast enough?

@ericdallo @spoenemann WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it makes sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do some profiling before optimizing something like that. Java ArrayList and Integer boxing/unboxing is super optimized in the JVM, I don't know whether you'll notice any difference for real-world array sizes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for semantic tokens from LSP 3.16
7 participants