Skip to content

Fix semantic token defaultLibrary modifier casing#4005

Merged
vinistock merged 1 commit intoShopify:mainfrom
a-lavis:fix-semantic-default-library-modifier
Mar 17, 2026
Merged

Fix semantic token defaultLibrary modifier casing#4005
vinistock merged 1 commit intoShopify:mainfrom
a-lavis:fix-semantic-default-library-modifier

Conversation

@a-lavis
Copy link
Contributor

@a-lavis a-lavis commented Mar 13, 2026

Motivation

Ruby LSP currently emits the semantic token modifier as default_library, but the LSP standard modifier name is defaultLibrary (camelCase). From the LSP specification:

export enum SemanticTokenModifiers {
	...
	defaultLibrary = 'defaultLibrary'
}

The Ruby LSP docs state:

Currently, the Ruby LSP does not contribute any new semantic tokens and only uses the ones contained in the default list.

But default_library is not in the default list.

I noticed this because I was using Ruby LSP with Zed, which has default semantic token rules to map semantic token types and modifiers to syntax theme styles. But these default semantic token rules do not support default_library; they only support defaultLibrary.

This means that, when using Zed, in order to get semantic token syntax highlighting for self, you need to define your own custom semantic token rules for default_library.

This would also apply to any other clients or themes expecting the semantic token types/modifiers from the specification in order to determine syntax theme styles.

In short - using the non-standard modifier default_library breaks protocol compatibility for clients/themes expecting the standard modifier defaultLibrary.

Related PR

See: Shopify/vscode-shopify-ruby#754

That PR updates the Spinel themes to apply the same formatting to variable.defaultLibrary as it does to variable.default_library.
That PR should ideally be merged and released before this PR, so that VSCode users of the Spinel theme don't notice any changes.

Implementation

  • Updated semantic token modifier key from default_library to defaultLibrary in:
    • lib/ruby_lsp/response_builders/semantic_highlighting.rb
  • Updated the self token emission to use the new modifier symbol:
    • lib/ruby_lsp/listeners/semantic_highlighting.rb
  • Updated documentation to reflect the correct selector:
    • jekyll/semantic-highlighting.markdown (variable.defaultLibrary)
  • Added a regression test to verify provider legend serialization uses defaultLibrary and not default_library:
    • test/requests/semantic_highlighting_expectations_test.rb

Automated Tests

Yes, I added tests!

Manual Tests

  1. In VSCode, open a Ruby file containing self, for example:

    class Post
      def title
        self
      end
    end
  2. Run Developer: Inspect Editor Tokens and Scopes.

  3. Place cursor on self.

  4. Verify semantic token shows:

    • semantic token type: variable
    • modifiers: defaultLibrary
    • and does not show default_library.

@a-lavis
Copy link
Contributor Author

a-lavis commented Mar 13, 2026

Just signed the CLA!

@vinistock vinistock added bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes labels Mar 17, 2026
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

Thank you for the fix!

@vinistock vinistock merged commit e492623 into Shopify:main Mar 17, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR will fix an existing bug 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.

2 participants