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

fix(grammar): Fix syntax highlighting for Kernel.` method in Ruby grammar #2493

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

Sean0628
Copy link
Contributor

Motivation

Closes #1470

The issue was that syntax highlighting breaks when using the Kernel.\` method in Ruby code. The grammar was incorrectly treating the backtick in this context as the start of an interpolated string literal, leading to incorrect tokenization and highlighting.

Implementation

To address this, the Ruby grammar was updated to properly distinguish between backtick string literals and the Kernel.` method calls. Specifically, the begin pattern for backticks was modified to include a negative lookbehind (?<!\\.), ensuring that only standalone backticks are treated as string delimiters.

(?<!…) — Negative Lookbehind. Matches if the provided pattern would not match the preceding characters, but does not advance the current position. The pattern must have a fixed length (unbounded quantifiers are not permitted).

ref. https://rbuckton.github.io/regexp-features/engines/oniguruma.html

Additionally, I added new test cases to cover both standard backtick strings and Kernel.\` method calls. These tests verify that the grammar correctly tokenizes each scenario, ensuring that backtick strings are recognized as interpolated strings, while Kernel.\` methods are handled without string interpretation.

Automated Tests

Unit tests were added as part of this change to ensure that both scenarios (standard backtick strings and Kernel.\` method calls) are correctly handled by the grammar.

Manual Tests

Before

Screenshot 2024-08-27 at 00 37 02

After

Screenshot 2024-08-27 at 00 36 27

- Updated the Ruby grammar to properly differentiate between backtick string literals and Kernel backtick method calls by modifying the `begin` pattern to use a negative lookbehind `(?<!\\.)`.
- Added tests to ensure correct tokenization of standard backtick strings and Kernel backtick method calls.
@Sean0628 Sean0628 requested a review from a team as a code owner August 27, 2024 04:52
@Sean0628 Sean0628 requested review from andyw8 and st0012 August 27, 2024 04:52
@Sean0628
Copy link
Contributor Author

I have signed the CLA!

@andyw8 andyw8 added bugfix This PR will fix an existing bug vscode This pull request should be included in the VS Code extension's release notes labels Aug 27, 2024
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.

Nice. Thank you for the contribution!

@vinistock vinistock merged commit 1891baa into Shopify:main Aug 27, 2024
20 of 21 checks passed
@Sean0628 Sean0628 deleted the fix_syntax_highlight_kernel branch August 27, 2024 16:35
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 vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syntax highlight breaks on Kernel.` method
3 participants