From acd7ef3e140c9a2175b5f232cd85e960032e9b44 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Tue, 19 Nov 2024 11:42:44 +0100 Subject: [PATCH 1/4] Fix script/style/template indentation This commit backports https://github.com/sublimehq/Packages/pull/4020 to ensure related indentation rules are correctly applied for ST4181+. Scope changes are backported primarily due to their effect on syntax tests and the goal to avoid a need to ship dedicated ST4181+ releases just due to failing syntax tests, which do otherwise not have any significant effect on highlighting. --- Vue Component.sublime-syntax | 39 +++++-- tests/syntax_test_script.vue | 161 +++++++++++++++----------- tests/syntax_test_style.vue | 201 +++++++++++++++++++++------------ tests/syntax_test_template.vue | 16 +-- 4 files changed, 263 insertions(+), 154 deletions(-) diff --git a/Vue Component.sublime-syntax b/Vue Component.sublime-syntax index a234cb2..065a859 100644 --- a/Vue Component.sublime-syntax +++ b/Vue Component.sublime-syntax @@ -12,6 +12,9 @@ file_extensions: - wpy variables: + # CSS specific variables + # ====================== + # Embedded script and style syntaxes may be wrapped into html comments for # historical reasons. The following patterns match them, while maintaining # correct boundaries of embedded source scopes. That's required to enable @@ -20,10 +23,14 @@ variables: # see: # - https://github.com/sublimehq/Packages/issues/2322 # - https://github.com/sublimehq/sublime_text/issues/4701 + # + # Patterns backported from (required until ST4180): + # - https://github.com/sublimehq/Packages/pull/4020 script_content_begin: |- (?x: - # whitespace followed by opening html comment begin punctuation - \s*() \s* )? (?= tag + (?: (?: ^ \s* | (\s*) ) (-->) \s* | ^ \s* )? (?=) \s* $ + # note: Keep empty capture group for compatibility with existing 3rd-party syntaxes! + | ^ \s* () (-->) \s* $ ) style_content_begin: '{{script_content_begin}}' style_content_end: |- (?x: - # optional html comment end punctuation followed by tag - (?: (\s*) (-->) \s* )? (?= tag + (?: (?: ^ \s* | (\s*) ) (-->) \s* | ^ \s* )? (?=) \s* $ + # note: Keep empty capture group for compatibility with existing 3rd-party syntaxes! + | ^ \s* () (-->) \s* $ ) + + # Vue specific variables + # ====================== + template_content_begin: '{{script_content_begin}}' template_content_end: |- (?x: - # optional html comment end punctuation followed by tag - (?: (\s*) (-->) \s* )? (?= tag + (?: (?: ^ \s* | (\s*) ) (-->) \s* | ^ \s* )? (?=) \s* $ + # note: Keep empty capture group for compatibility with existing 3rd-party syntaxes! + | ^ \s* () (-->) \s* $ ) contexts: diff --git a/tests/syntax_test_script.vue b/tests/syntax_test_script.vue index 7c23c8f..92c0549 100644 --- a/tests/syntax_test_script.vue +++ b/tests/syntax_test_script.vue @@ -38,37 +38,38 @@ var i = 0; // ^^^^^^^^^^^^ source.js.embedded.html - source source -// <- source.js.embedded.html - source source -// ^ source.js.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source -// ^ source.js.embedded.html - source source -// ^^^^^^^^^^^^^^ - source -// ^ - meta.tag - comment -// ^^^^^^^^^ meta.tag -// ^ - meta.tag -// ^^^ comment.block.html punctuation.definition.comment.end.html +// <- - comment - source +//^^ - comment - source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - comment - meta.tag - source +// ^^^^^^^^^ meta.tag - comment - source // ^^ punctuation.definition.tag.begin.html // ^^^^^^ entity.name.tag // ^ punctuation.definition.tag.end.html @@ -92,13 +92,12 @@ // ^^^^^^^^ meta.tag - meta.attribute-with-value - source // ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value - meta.attribute-with-value meta.attribute-with-value - source // ^ meta.tag - meta.attribute-with-value - source -// ^^^^^ - meta.tag - source +// ^^^^^^ - meta.tag - source // ^^^^^^ entity.name.tag // ^^^^ entity.other.attribute-name.html // ^ punctuation.separator.key-value.html // ^^^^^^^^^^^^^^^^^ string.quoted.double.html // ^^^^ comment.block.html punctuation.definition.comment.begin.html -// ^ source.js.embedded.html var foo = 100; // <- source.js.embedded.html - source source @@ -107,12 +106,11 @@ // ^^^ source.js.embedded.html keyword.operator - comment --> -// ^ source.js.embedded.html - source source -// ^^^^^^^^^^^^^^ - source -// ^ - meta.tag - comment -// ^^^^^^^^^ meta.tag -// ^ - meta.tag -// ^^^ comment.block.html punctuation.definition.comment.end.html +// <- - comment - source +//^^ - comment - source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - comment - meta.tag - source +// ^^^^^^^^^ meta.tag - comment - source // ^^ punctuation.definition.tag.begin.html // ^^^^^^ entity.name.tag // ^ punctuation.definition.tag.end.html @@ -128,10 +126,15 @@ // <- source.js.embedded.html - source source // ^^^^^^^^^^^^^^^^ source.js.embedded.html - source source -// <- source.js.embedded.html - source source -// ^ source.js.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source + + + // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag - meta.tag meta.tag - source // ^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.lang.html - meta.attribute-with-value meta.attribute-with-value @@ -148,109 +151,137 @@ // <- source.coffee.embedded.html - source source -// <- source.coffee.embedded.html - source source -//^^ source.coffee.embedded.html - source source +// <- - source // ^^^^^^^^^ meta.tag - source -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source + + + -// <- source.jsx.embedded.html - source source -//^^ source.jsx.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source + + + -// <- source.livescript.embedded.html - source source -//^^ source.livescript.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source + + -// <- source.ts.embedded.html - source source -//^^ source.ts.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source + + + -// <- source.tsx.embedded.html - source source -//^^ source.tsx.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^^ meta.tag - source diff --git a/tests/syntax_test_style.vue b/tests/syntax_test_style.vue index 54de7e8..2207931 100644 --- a/tests/syntax_test_style.vue +++ b/tests/syntax_test_style.vue @@ -37,48 +37,46 @@ // <- source.css.embedded.html -// <- source.css.embedded.html - source source -// ^ source.css.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source -// ^ source.css.embedded.html - source source -// ^^^^^^^^^^^^^ - source -// ^ - meta.tag - comment -// ^^^^^^^^ meta.tag -// ^ - meta.tag -// ^^^ comment.block.html punctuation.definition.comment.end.html +// <- - comment - source +//^^ - comment - source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - comment - meta.tag - source +// ^^^^^^^^ meta.tag - comment - source // ^^ punctuation.definition.tag.begin.html // ^^^^^ entity.name.tag // ^ punctuation.definition.tag.end.html @@ -88,24 +86,22 @@ // ^^^^^^^ meta.tag - meta.attribute-with-value - source // ^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value - meta.attribute-with-value meta.attribute-with-value - source // ^ meta.tag - meta.attribute-with-value - source -// ^^^^^ - meta.tag - source +// ^^^^^^ - meta.tag - source // ^^^^^ entity.name.tag // ^^^^ entity.other.attribute-name.html // ^ punctuation.separator.key-value.html // ^^^^^^^^^^ string.quoted.double.html // ^^^^ comment.block.html punctuation.definition.comment.begin.html -// ^ source.css.embedded.html h1 {} // <- source.css.embedded.html - source source --> -// ^ source.css.embedded.html - source source -// ^^^^^^^^^^^^^ - source -// ^ - meta.tag - comment -// ^^^^^^^^ meta.tag -// ^ - meta.tag -// ^^^ comment.block.html punctuation.definition.comment.end.html +// <- - comment - source +//^^ - comment - source +// ^^^ comment.block.html punctuation.definition.comment.end.html - source +// ^ - comment - meta.tag - source +// ^^^^^^^^ meta.tag - comment - source // ^^ punctuation.definition.tag.begin.html // ^^^^^ entity.name.tag // ^ punctuation.definition.tag.end.html @@ -122,11 +118,15 @@ // <- source.css.embedded.html - source source -// <- source.css.embedded.html - source source -// ^ source.css.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + + // ^^^^^^^^^^^^^^^^^^^ meta.tag - source // ^^^^^^^^^^^ meta.attribute-with-value.lang.html - meta.attribute-with-value meta.attribute-with-value @@ -138,112 +138,173 @@ // <- source.less.embedded.html - source source -// <- source.less.embedded.html - source source -//^^ source.less.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + // <- - source - comment - meta.tag //^^ - source - comment - meta.tag // ^^^^^^^^ meta.tag - source + + -// <- source.postcss.embedded.html -//^^ source.postcss.embedded.html +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + + -// <- source.sss.embedded.html - source source -//^^ source.sss.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + + -// <- source.sass.embedded.html - source source -//^^ source.sass.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + + -// <- source.scss.embedded.html - source source -//^^ source.scss.embedded.html - source source +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source + -// <- - source - comment - meta.tag -//^^ - source - comment - meta.tag +// <- - meta.tag - source +//^^ - meta.tag - source +// ^^^^^^^^ meta.tag - source + + + + + +// <- - meta.tag - source +//^^ - meta.tag - source +// ^^^^^^^^ meta.tag - source + + + +// <- - meta.tag - source +//^^ - meta.tag - source // ^^^^^^^^ meta.tag - source diff --git a/tests/syntax_test_template.vue b/tests/syntax_test_template.vue index c725b3a..5eabfa7 100644 --- a/tests/syntax_test_template.vue +++ b/tests/syntax_test_template.vue @@ -46,8 +46,8 @@ // <- text.jade.embedded.html -// <- text.jade.embedded.html -//^^ text.jade.embedded.html +// <- - text.jade +//^^ - text.jade // ^^^^^^^^^^^ meta.tag - meta.tag meta.tag - text.jade @@ -64,8 +64,8 @@ // <- text.jade.embedded.html -// <- text.jade.embedded.html -//^^ text.jade.embedded.html +// <- - text.jade +//^^ - text.jade // ^^^^^^^^^^^ meta.tag - meta.tag meta.tag - text.jade // ^^ punctuation.definition.tag.begin.html // ^^^^^^^^ entity.name.tag.template.html @@ -84,8 +84,8 @@ // <- text.pug.embedded.html -// <- text.pug.embedded.html -//^^ text.pug.embedded.html +// <- - text.pug +//^^ - text.pug // ^^^^^^^^^^^ meta.tag - meta.tag meta.tag - text.pug // ^^ punctuation.definition.tag.begin.html // ^^^^^^^^ entity.name.tag.template.html @@ -104,8 +104,8 @@ // <- text.slim.embedded.html -// <- text.slim.embedded.html -//^^ text.slim.embedded.html +// <- - text.slim +//^^ - text.slim // ^^^^^^^^^^^ meta.tag - meta.tag meta.tag - text.slm // ^^ punctuation.definition.tag.begin.html // ^^^^^^^^ entity.name.tag.template.html From ca855581529beaa03c35f28610ba2fef0cacaa22 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Tue, 19 Nov 2024 12:20:48 +0100 Subject: [PATCH 2/4] Backport HTML indentation rules In order to properly handle ` -// <- - text.jade -//^^ - text.jade // ^^^^^^^^^^^ meta.tag - meta.tag meta.tag - text.jade @@ -60,12 +50,9 @@ // ^^^^ entity.other.attribute-name.html // ^ punctuation.separator.key-value.html // ^ punctuation.definition.tag.end.html -// ^ - text.jade // <- text.jade.embedded.html -// <- - text.jade -//^^ - text.jade // ^^^^^^^^^^^ meta.tag - meta.tag meta.tag - text.jade // ^^ punctuation.definition.tag.begin.html // ^^^^^^^^ entity.name.tag.template.html @@ -80,12 +67,9 @@ // ^^^^ entity.other.attribute-name.html // ^ punctuation.separator.key-value.html // ^ punctuation.definition.tag.end.html -// ^ - text.pug // <- text.pug.embedded.html -// <- - text.pug -//^^ - text.pug // ^^^^^^^^^^^ meta.tag - meta.tag meta.tag - text.pug // ^^ punctuation.definition.tag.begin.html // ^^^^^^^^ entity.name.tag.template.html @@ -100,12 +84,9 @@ // ^^^^ entity.other.attribute-name.html // ^ punctuation.separator.key-value.html // ^ punctuation.definition.tag.end.html -// ^ - text.slim // <- text.slim.embedded.html -// <- - text.slim -//^^ - text.slim // ^^^^^^^^^^^ meta.tag - meta.tag meta.tag - text.slm // ^^ punctuation.definition.tag.begin.html // ^^^^^^^^ entity.name.tag.template.html From 6cd6aa9a466a7af75ce143da5a85b7b4abde4aa2 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 21 Nov 2024 10:49:39 +0100 Subject: [PATCH 4/4] Revert patterns as they will be dropped for ST4128+ --- Vue Component.sublime-syntax | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Vue Component.sublime-syntax b/Vue Component.sublime-syntax index 50a0166..41c14f4 100644 --- a/Vue Component.sublime-syntax +++ b/Vue Component.sublime-syntax @@ -23,14 +23,10 @@ variables: # see: # - https://github.com/sublimehq/Packages/issues/2322 # - https://github.com/sublimehq/sublime_text/issues/4701 - # - # Patterns backported from (required until ST4180): - # - https://github.com/sublimehq/Packages/pull/4020 script_content_begin: |- (?x: - # whitespace followed by opening html comment begin punctuation, - # optionally followed by whitespeace until end of line - \s*() \s* | ^ \s* )? (?= tag + (?: (\s*) (-->) \s* )? (?=) \s* $ + | ^ (\s*) (-->) \s* $ ) style_content_begin: '{{script_content_begin}}' style_content_end: |- (?x: - # optional html comment end punctuation or any whitespace at beginning of - # line followed by tag - (?: (?: ^ \s* | (\s*) ) (-->) \s* | ^ \s* )? (?= tag + (?: (\s*) (-->) \s* )? (?=) \s* $ + | ^ (\s*) (-->) \s* $ ) # Vue specific variables