Shopify / Shopify/ruby-lsp

Wrong syntax highlighting for `<%==` erb syntax

Open
#2,909 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help-wanted pinned vscode
Dominant language
Ruby
Stars
2k
Forks
281
Avg merge
2h 14m
Merged PRs (30d)
6

Description

Description
Ruby LSP Information
Details

VS Code Version

1.95.1

Ruby LSP Extension Version

0.8.14

Ruby LSP Server Version

0.22.1

Ruby LSP Addons
  • Ruby LSP Rails
Ruby Version

3.3.6

Ruby Version Manager

rbenv

Installed Extensions
Click to expand
  • asciidoctor-vscode (3.4.2)
  • gitlens (16.0.4)
  • go (0.42.1)
  • material-icon-theme (5.14.1)
  • remote-containers (0.388.0)
  • ruby-lsp (0.8.14)
  • sorbet-vscode-extension (0.3.37)
  • vscode-github-actions (0.27.0)
  • vscode-rdbg (0.2.2)
  • vscode-wakatime (24.9.1)
  • vscode-yaml (1.15.0)
Ruby LSP Settings
Click to expand
Workspace
{}
User
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "none",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "useLauncher": false,
  "featureFlags": {}
}

Reproduction steps

A lesser used but valid syntax of erb is <%== which will mark the passed string as html safe. Rails documents it at the bottom of https://guides.rubyonrails.org/active_support_core_extensions.html#safe-strings, although I'm not sure if this is rails specific or not. Could very well be erubi only.

ruby-lsp fails to consider the second equal sign, showing the code like this:

Image

A fix seems rather straightforward but erb highlighting has no tests and I don't really understand these gramar files so I'm not very confident in my change. I can open a PR if it looks reasonable and no tests are fine.

Patch

diff --git a/vscode/grammars/erb.cson.json b/vscode/grammars/erb.cson.json
index 475a9454..fe88bb21 100644
--- a/vscode/grammars/erb.cson.json
+++ b/vscode/grammars/erb.cson.json
@@ -80,7 +80,7 @@
     "tags": {
       "patterns": [
         {
-          "begin": "<%+(?!>)[-=]?(?![^%]*%>)",
+          "begin": "<%+(?!>)[-=]?=?(?![^%]*%>)",
           "beginCaptures": {
             "0": {
               "name": "punctuation.section.embedded.begin.erb"
@@ -113,7 +113,7 @@
           ]
         },
         {
-          "begin": "<%+(?!>)[-=]?",
+          "begin": "<%+(?!>)[-=]?=?",
           "beginCaptures": {
             "0": {
               "name": "punctuation.section.embedded.begin.erb"
diff --git a/vscode/languages/erb.json b/vscode/languages/erb.json
index ae1564fb..f8373735 100644
--- a/vscode/languages/erb.json
+++ b/vscode/languages/erb.json
@@ -5,6 +5,7 @@
   "brackets": [
     ["<%", "%>"],
     ["<%=", "%>"],
+    ["<%==", "%>"],
     ["<%#", "%>"]
   ],
   "autoClosingPairs": [
@@ -35,6 +36,7 @@
   "surroundingPairs": [
     ["<%", "%>"],
     ["<%=", "%>"],
+    ["<%==", "%>"],
     ["<%#", "%>"],
     ["{", "}"],
     ["[", "]"],

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with vscode/grammars/erb.cson.json and vscode/languages/erb.json, using the reproduction of the <%= syntax and the proposed diff as the entry point. Verify that < %== ERB tags receive the correct syntax highlighting and that the language configuration includes the expected bracket and surrounding pairs; the issue notes that no existing ERB highlighting tests are present.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.