Skip to content

Commit ee99a4c

Browse files
committed
Prevent endless defs from starting a method region
This assumes endless defs are one-liners. Fixes #439
1 parent a2b8e91 commit ee99a4c

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

spec/syntax/methods_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,15 @@ def foo bar=:baz
3333
def foo bar:; end
3434
EOF
3535
end
36+
37+
specify "endless def does not start a method region" do
38+
assert_correct_highlighting <<~'EOF', 'end', ''
39+
def foo = bar
40+
end
41+
EOF
42+
assert_correct_highlighting <<~'EOF', 'end', ''
43+
def foo (a, b) = bar
44+
end
45+
EOF
46+
end
3647
end

syntax/ruby.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
363363
SynFold 'class' syn region rubyClassBlock start="\<class\>" matchgroup=rubyClass skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop
364364
SynFold 'module' syn region rubyModuleBlock start="\<module\>" matchgroup=rubyModule skip="\<end:" end="\<end\>" contains=ALLBUT,@rubyNotTop
365365

366+
" endless def
367+
syn match rubyDefine "\<def\s\+\ze[^[:space:];#(]\+\%(\s\+\|\s*(.*)\s*\)=" nextgroup=rubyMethodDeclaration skipwhite
368+
366369
" modifiers
367370
syn match rubyLineContinuation "\\$" nextgroup=@rubyModifier skipwhite skipnl
368371
syn match rubyConditionalModifier "\<\%(if\|unless\)\>"

0 commit comments

Comments
 (0)