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

Minimize semantic tokens returned for constants and method calls #2479

Merged
merged 3 commits into from
Aug 23, 2024

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Aug 23, 2024

Motivation

Another step for #2461

This PR minimizes the number of semantic tokens returned for constants and method calls.

After this PR, in a ~4k file where we used to find ~20k tokens, we now find about ~8k tokens. In terms of round-trip response time for semantic highlighting, on my machine it brings it down to 4 seconds from 12 seconds.

While it doesn't solve the problem completely for these super large files, the performance will be significantly better across the board.

Implementation

No constant references are ambiguous, so I stopped returning tokens for all of them.

For method calls, there's only one ambiguous syntax, which is method calls with no receiver and no parenthesis. I stopped returning tokens for the cases that are not needed.

# Unambiguous
call()
something.call
something.call()
self.call

# Ambiguous (can be confused with local var)
call

Only the first commit has implementation. The rest is just updating expectations to reflect the reduced number of tokens.

Automated Tests

Updated existing ones. Removed some that no longer made sense.

@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Aug 23, 2024
@vinistock vinistock self-assigned this Aug 23, 2024
@vinistock vinistock requested a review from a team as a code owner August 23, 2024 16:00
@vinistock vinistock requested review from andyw8 and st0012 August 23, 2024 16:00
@vinistock vinistock force-pushed the vs-support-semantic-tokens-delta branch 4 times, most recently from 02e77cc to 3547038 Compare August 23, 2024 18:42
@vinistock vinistock force-pushed the vs-minimize-semantic-tokens branch from b4e6206 to 10ac664 Compare August 23, 2024 18:49
Base automatically changed from vs-support-semantic-tokens-delta to main August 23, 2024 19:06
@vinistock vinistock force-pushed the vs-minimize-semantic-tokens branch from 10ac664 to ab1f104 Compare August 23, 2024 19:06
@andyw8
Copy link
Contributor

andyw8 commented Aug 23, 2024

Do you know of any other LSP servers that use this approach of providing only partial semantic highlighting? Just wondering if there's any downsides we may be missing.

@vinistock
Copy link
Member Author

I think that's the standard approach. I've never seen a language server that returns all tokens available. Typically, you only return what cannot be determined using Text Mate grammars.

Copy link
Contributor

@andyw8 andyw8 left a comment

Choose a reason for hiding this comment

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

Worth also updating requests/semantic_highlighting.rb to explain the new approach?

@vinistock
Copy link
Member Author

Worth also updating requests/semantic_highlighting.rb to explain the new approach?

Added an explanation.

@vinistock vinistock merged commit 697b32a into main Aug 23, 2024
35 checks passed
@vinistock vinistock deleted the vs-minimize-semantic-tokens branch August 23, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants