Skip to content

Fix semantic token defaultLibrary modifier casing#4005

Open
a-lavis wants to merge 1 commit intoShopify:mainfrom
a-lavis:fix-semantic-default-library-modifier
Open

Fix semantic token defaultLibrary modifier casing#4005
a-lavis wants to merge 1 commit intoShopify:mainfrom
a-lavis:fix-semantic-default-library-modifier

Conversation

@a-lavis
Copy link

@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
Author

a-lavis commented Mar 13, 2026

Just signed the CLA!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant