From 3ee36163228c3664b2058c270cb20686fda4a1e8 Mon Sep 17 00:00:00 2001 From: domingo2000 Date: Tue, 11 Mar 2025 14:17:20 -0300 Subject: [PATCH] Add support for ERB syntax highlighting in Heredoc sections --- vscode/grammars/ruby.cson.json | 38 ++++++++++++++++++++++++++ vscode/src/test/suite/grammars.test.ts | 4 +++ 2 files changed, 42 insertions(+) diff --git a/vscode/grammars/ruby.cson.json b/vscode/grammars/ruby.cson.json index 9e1a94e0b4..ffec84c418 100644 --- a/vscode/grammars/ruby.cson.json +++ b/vscode/grammars/ruby.cson.json @@ -1691,6 +1691,44 @@ } ] }, + { + "begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)ERB)\\b\\1))", + "comment": "Heredoc with embedded ERB", + "end": "(?!\\G)", + "name": "meta.embedded.block.erb", + "patterns": [ + { + "begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)ERB)\\b\\1)", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.ruby" + } + }, + "contentName": "text.html.erb", + "end": "^\\s*\\2$\\n?", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.ruby" + } + }, + "name": "string.unquoted.heredoc.ruby", + "patterns": [ + { + "include": "#heredoc" + }, + { + "include": "#interpolated_ruby" + }, + { + "include": "text.html.erb" + }, + { + "include": "#escaped_char" + } + ] + } + ] + }, { "begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)XML)\\b\\1))", "comment": "Heredoc with embedded XML", diff --git a/vscode/src/test/suite/grammars.test.ts b/vscode/src/test/suite/grammars.test.ts index 29e3395ca6..81b1d69b4d 100644 --- a/vscode/src/test/suite/grammars.test.ts +++ b/vscode/src/test/suite/grammars.test.ts @@ -36,6 +36,10 @@ const EMBEDDED_HEREDOC_LANGUAGES: InferrableLanguageConfigOrLabel[] = [ id: "cpp", label: "C++", }, + { + label: "ERB", + contentName: "text.html.erb", + }, { label: "GraphQL", delimiters: ["GRAPHQL", "GQL"],