From 41b7232d08850f9387c86b622dcdc949c188498d Mon Sep 17 00:00:00 2001 From: deathaxe Date: Tue, 30 Apr 2024 19:06:50 +0200 Subject: [PATCH] [Rails] Fix HAML line continuations (#3975) Fixes #3973 Fixes #3974 This commit... 1. scopes `,` punctuation only within attributes and ruby code blocks. 2. ensures comment contexts pop off before `|` pipe continuation. --- .../Embeddings/Ruby (for HAML).sublime-syntax | 18 +++++--- Rails/HAML.sublime-syntax | 28 +++++++----- Rails/tests/syntax_test_rails.haml | 44 ++++++++++++++++++- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/Rails/Embeddings/Ruby (for HAML).sublime-syntax b/Rails/Embeddings/Ruby (for HAML).sublime-syntax index 914b17d09d..dddd847663 100644 --- a/Rails/Embeddings/Ruby (for HAML).sublime-syntax +++ b/Rails/Embeddings/Ruby (for HAML).sublime-syntax @@ -9,14 +9,20 @@ contexts: prototype: - meta_prepend: true - - include: HAML.sublime-syntax#continuations + - include: HAML.sublime-syntax#pipe-continuations comments: - meta_prepend: true - match: \#+ scope: punctuation.definition.comment.ruby - push: - - meta_scope: comment.line.number-sign.ruby - # support continuations, but escape afterwards - - match: ^ - pop: true + push: comment-body + + comment-body: + - meta_include_prototype: false + - meta_scope: comment.line.number-sign.ruby + # support continuations, but escape afterwards + - match: ^ + pop: 1 + # pipe continuation no longer belongs to comment + - match: (?=\|\s*$) + pop: 1 diff --git a/Rails/HAML.sublime-syntax b/Rails/HAML.sublime-syntax index c7cbd982cd..03b482099d 100644 --- a/Rails/HAML.sublime-syntax +++ b/Rails/HAML.sublime-syntax @@ -21,7 +21,7 @@ contexts: - include: escapes - include: filters - include: rubylines - - include: continuations + - include: pipe-continuations - include: interpolations ###[ COMMENTS ]############################################################### @@ -54,34 +54,39 @@ contexts: 4: punctuation.section.brackets.end.haml comment-body: + - meta_include_prototype: false - meta_scope: comment.block.haml - match: ^(?!\1 ) pop: 1 + - match: (?=\|\s*$) + pop: 1 - include: main ###[ CONTINUATIONS ]########################################################## - continuations: + comma-continuations: # Attribute sections and embedded ruby code may continue on next line # if the current line is terminated with comma. # https://haml.info/docs/yardoc/file.REFERENCE.html#attributes # https://haml.info/docs/yardoc/file.REFERENCE.html#running-ruby-- - - match: (,)\n + - match: (,)\s*$ captures: 1: punctuation.separator.sequence.haml - push: comma-continuations-body - # https://haml.info/docs/yardoc/file.REFERENCE.html#multiline - - match: (\|)\s*\n - captures: - 1: punctuation.separator.continuation.haml - push: pipe-continuations-body + push: comma-continuation-body - comma-continuations-body: + comma-continuation-body: # Skip "line ends with pipe" check if previous line was continued by comma. - match: (?=\S) pop: 1 - pipe-continuations-body: + pipe-continuations: + # https://haml.info/docs/yardoc/file.REFERENCE.html#multiline + - match: (\|)\s*$ + captures: + 1: punctuation.separator.continuation.haml + push: pipe-continuation-body + + pipe-continuation-body: - match: ^ pop: 1 @@ -287,6 +292,7 @@ contexts: # A line after a pipe-continuation must be terminated by pipe, too. - match: ^(?!.*(\|\s*$)) pop: 1 + - include: comma-continuations - include: scope:source.ruby.rails.embedded.haml apply_prototype: true diff --git a/Rails/tests/syntax_test_rails.haml b/Rails/tests/syntax_test_rails.haml index 0049a4b286..6934bbba44 100644 --- a/Rails/tests/syntax_test_rails.haml +++ b/Rails/tests/syntax_test_rails.haml @@ -102,6 +102,32 @@ This is my form +%ol + %li +/ ^^^ meta.tag.haml + lorem, +/ ^^^^^^^^ - punctuation + + %li + lorem, + %li +/ ^^^ meta.tag.haml + ipsum. +/ ^^^^^^^^ - punctuation + + %li + ipsum. + %li +/ ^^^ meta.tag.haml + lorm| +/ ^^^^^ - punctuation +/ ^ punctuation.separator.continuation.haml + + %li + lorm| + %li +/ ^^^ meta.tag.haml + = render 'form' # comment / <- meta.embedded.haml /^^^^^^^^^^^^^^^^^^^^^^^^ meta.line.ruby.haml meta.embedded.haml source.ruby.rails.embedded.haml @@ -110,6 +136,21 @@ / ^^^^^^^^^ comment.line.number-sign.ruby / ^ punctuation.definition.comment.ruby +.row + = f.text_field :hello, + { value: myobj.mymethod, +/ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.line.ruby.haml meta.embedded.haml source.ruby.rails.embedded.haml +/ ^ punctuation.separator.sequence.haml + +.row + = f.text_field :hello, + { value: myobj.mymethod, + class: 'clazz', +/ ^^^^^^^^^^^^^^^^^^^^^ meta.line.ruby.haml meta.embedded.haml source.ruby.rails.embedded.haml +/ ^^^^^^ constant.other.symbol.ruby +/ ^^^^^^^ meta.string.ruby string.quoted.single.ruby +/ ^ punctuation.separator.sequence.haml + %title = @title / ^ meta.line.ruby.haml meta.embedded.haml punctuation.section.embedded.haml @@ -194,7 +235,8 @@ %p{:class => "myclass", | # :id => "myid"} My paragraph | -/ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.attributes.haml meta.braces.haml comment.line.number-sign.ruby +/ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.attributes.haml meta.braces.haml comment.line.number-sign.ruby +/ ^^ meta.tag.attributes.haml meta.braces.haml - comment / ^ - punctuation / ^ punctuation.separator.continuation.haml