Skip to content

Commit

Permalink
[Rails] Fix HAML line continuations (sublimehq#3975)
Browse files Browse the repository at this point in the history
Fixes sublimehq#3973
Fixes sublimehq#3974

This commit...

1. scopes `,` punctuation only within attributes and ruby code blocks.
2. ensures comment contexts pop off before `|` pipe continuation.
  • Loading branch information
deathaxe authored Apr 30, 2024
1 parent 8af9b40 commit 41b7232
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 18 deletions.
18 changes: 12 additions & 6 deletions Rails/Embeddings/Ruby (for HAML).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 17 additions & 11 deletions Rails/HAML.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contexts:
- include: escapes
- include: filters
- include: rubylines
- include: continuations
- include: pipe-continuations
- include: interpolations

###[ COMMENTS ]###############################################################
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
44 changes: 43 additions & 1 deletion Rails/tests/syntax_test_rails.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 41b7232

Please sign in to comment.