Skip to content

Commit 2c906ca

Browse files
Fix arguments in method defifinition with parentheses. Add support for multiline arguments in method definition without parentheses.
1 parent 02613b0 commit 2c906ca

File tree

2 files changed

+141
-111
lines changed

2 files changed

+141
-111
lines changed

Syntaxes/Ruby.plist

+87-111
Original file line numberDiff line numberDiff line change
@@ -522,100 +522,17 @@
522522
<key>match</key>
523523
<string>\G([&amp;*]?)(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
524524
</dict>
525-
<dict>
526-
<key>include</key>
527-
<string>#parens</string>
528-
</dict>
529-
<dict>
530-
<key>include</key>
531-
<string>#braces</string>
532-
</dict>
533-
<dict>
534-
<key>include</key>
535-
<string>$self</string>
536-
</dict>
537-
</array>
538-
</dict>
539-
</array>
540-
<key>repository</key>
541-
<dict>
542-
<key>braces</key>
543-
<dict>
544-
<key>begin</key>
545-
<string>\{</string>
546-
<key>beginCaptures</key>
547-
<dict>
548-
<key>0</key>
549-
<dict>
550-
<key>name</key>
551-
<string>punctuation.section.function.begin.ruby</string>
552-
</dict>
553-
</dict>
554-
<key>end</key>
555-
<string>\}</string>
556-
<key>endCaptures</key>
557-
<dict>
558-
<key>0</key>
559-
<dict>
560-
<key>name</key>
561-
<string>punctuation.section.function.end.ruby</string>
562-
</dict>
563-
</dict>
564-
<key>patterns</key>
565-
<array>
566-
<dict>
567-
<key>include</key>
568-
<string>#parens</string>
569-
</dict>
570-
<dict>
571-
<key>include</key>
572-
<string>#braces</string>
573-
</dict>
574525
<dict>
575526
<key>include</key>
576527
<string>$self</string>
577528
</dict>
578529
</array>
579530
</dict>
580-
<key>parens</key>
581531
<dict>
582-
<key>begin</key>
583-
<string>\(</string>
584-
<key>beginCaptures</key>
585-
<dict>
586-
<key>0</key>
587-
<dict>
588-
<key>name</key>
589-
<string>punctuation.section.function.begin.ruby</string>
590-
</dict>
591-
</dict>
592-
<key>end</key>
593-
<string>\)</string>
594-
<key>endCaptures</key>
595-
<dict>
596-
<key>0</key>
597-
<dict>
598-
<key>name</key>
599-
<string>punctuation.section.function.end.ruby</string>
600-
</dict>
601-
</dict>
602-
<key>patterns</key>
603-
<array>
604-
<dict>
605-
<key>include</key>
606-
<string>#parens</string>
607-
</dict>
608-
<dict>
609-
<key>include</key>
610-
<string>#braces</string>
611-
</dict>
612-
<dict>
613-
<key>include</key>
614-
<string>$self</string>
615-
</dict>
616-
</array>
532+
<key>include</key>
533+
<string>$self</string>
617534
</dict>
618-
</dict>
535+
</array>
619536
</dict>
620537
<dict>
621538
<key>begin</key>
@@ -644,16 +561,16 @@
644561
<key>comment</key>
645562
<string>same as the previous rule, but without parentheses around the arguments</string>
646563
<key>end</key>
647-
<string>$</string>
564+
<string>(?&lt;=[\w\])}`'";!?])\s*$</string>
648565
<key>name</key>
649566
<string>meta.function.method.with-arguments.ruby</string>
650567
<key>patterns</key>
651568
<array>
652569
<dict>
653570
<key>begin</key>
654-
<string>(?![\s,])</string>
571+
<string>(?=[&amp;*_a-zA-Z])</string>
655572
<key>end</key>
656-
<string>(?=,|$)</string>
573+
<string>(?=,|\s*$)</string>
657574
<key>patterns</key>
658575
<array>
659576
<dict>
@@ -682,15 +599,17 @@
682599
</dict>
683600
<key>match</key>
684601
<string>\G([&amp;*]?)(?:([_a-zA-Z]\w*(:))|([_a-zA-Z]\w*))</string>
685-
<key>name</key>
686-
<string>variable.parameter.function.ruby</string>
687602
</dict>
688603
<dict>
689604
<key>include</key>
690605
<string>$self</string>
691606
</dict>
692607
</array>
693608
</dict>
609+
<dict>
610+
<key>include</key>
611+
<string>$self</string>
612+
</dict>
694613
</array>
695614
</dict>
696615
<dict>
@@ -1956,34 +1875,91 @@
19561875
<string>punctuation.separator.other.ruby</string>
19571876
</dict>
19581877
<dict>
1959-
<key>match</key>
1878+
<key>begin</key>
19601879
<string>\{</string>
1961-
<key>name</key>
1962-
<string>punctuation.section.scope.begin.ruby</string>
1963-
</dict>
1964-
<dict>
1965-
<key>match</key>
1880+
<key>beginCaptures</key>
1881+
<dict>
1882+
<key>0</key>
1883+
<dict>
1884+
<key>name</key>
1885+
<string>punctuation.section.scope.begin.ruby</string>
1886+
</dict>
1887+
</dict>
1888+
<key>end</key>
19661889
<string>\}</string>
1967-
<key>name</key>
1968-
<string>punctuation.section.scope.end.ruby</string>
1890+
<key>endCaptures</key>
1891+
<dict>
1892+
<key>0</key>
1893+
<dict>
1894+
<key>name</key>
1895+
<string>punctuation.section.scope.end.ruby</string>
1896+
</dict>
1897+
</dict>
1898+
<key>patterns</key>
1899+
<array>
1900+
<dict>
1901+
<key>include</key>
1902+
<string>$self</string>
1903+
</dict>
1904+
</array>
19691905
</dict>
19701906
<dict>
1971-
<key>match</key>
1907+
<key>begin</key>
19721908
<string>\[</string>
1973-
<key>name</key>
1974-
<string>punctuation.section.array.begin.ruby</string>
1975-
</dict>
1976-
<dict>
1977-
<key>match</key>
1909+
<key>beginCaptures</key>
1910+
<dict>
1911+
<key>0</key>
1912+
<dict>
1913+
<key>name</key>
1914+
<string>punctuation.section.array.begin.ruby</string>
1915+
</dict>
1916+
</dict>
1917+
<key>end</key>
19781918
<string>\]</string>
1979-
<key>name</key>
1980-
<string>punctuation.section.array.end.ruby</string>
1919+
<key>endCaptures</key>
1920+
<dict>
1921+
<key>0</key>
1922+
<dict>
1923+
<key>name</key>
1924+
<string>punctuation.section.array.end.ruby</string>
1925+
</dict>
1926+
</dict>
1927+
<key>patterns</key>
1928+
<array>
1929+
<dict>
1930+
<key>include</key>
1931+
<string>$self</string>
1932+
</dict>
1933+
</array>
19811934
</dict>
19821935
<dict>
1983-
<key>match</key>
1984-
<string>\(|\)</string>
1985-
<key>name</key>
1986-
<string>punctuation.section.function.ruby</string>
1936+
<key>begin</key>
1937+
<string>\(</string>
1938+
<key>beginCaptures</key>
1939+
<dict>
1940+
<key>0</key>
1941+
<dict>
1942+
<key>name</key>
1943+
<string>punctuation.section.function.ruby</string>
1944+
</dict>
1945+
</dict>
1946+
<key>end</key>
1947+
<string>\)</string>
1948+
<key>endCaptures</key>
1949+
<dict>
1950+
<key>0</key>
1951+
<dict>
1952+
<key>name</key>
1953+
<string>punctuation.section.function.ruby</string>
1954+
</dict>
1955+
</dict>
1956+
<key>patterns</key>
1957+
<array>
1958+
<dict>
1959+
<key>include</key>
1960+
<string>$self</string>
1961+
</dict>
1962+
</array>
19871963
</dict>
19881964
</array>
19891965
<key>repository</key>

Tests/method_arguments.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
def method
2+
hello, world = [1,2]
3+
end
4+
5+
def method_with_parentheses(a, b, c = [foo,bar,baz])
6+
hello, world = [1,2]
7+
end
8+
9+
def method_without_parentheses a, b, c = [foo,bar,baz]
10+
hello, world = [1,2]
11+
end
12+
13+
14+
def method_with_parentheses(a, b = "hello", c = ["foo", "bar"], d = (2 + 2) * 2, e = {})
15+
hello, world = [1,2]
16+
do_something1
17+
do_something2
18+
end
19+
20+
def method_without_parentheses a, b = "hello", c = ["foo", "bar"], d = (2 + 2) * 2, e = ""
21+
hello, world = [1,2]
22+
do_something1
23+
do_something2
24+
end
25+
26+
def method_with_parentheses(a,
27+
b = hello, # test comment
28+
c = ["foo", bar, :baz],
29+
d = (2 + 2) * 2,
30+
e = {})
31+
hello, world = [1,2]
32+
do_something1
33+
do_something2
34+
end
35+
36+
def method_without_parentheses a,
37+
b = "hello" , # test comment
38+
c = ["foo", bar, :baz],
39+
d = (2 + 2) * 2,
40+
e = proc { |e| e + e }
41+
hello, world = [1,2]
42+
do_something1
43+
do_something2
44+
end
45+
46+
def method_without_parentheses a,
47+
b: hello , # test comment
48+
c: ["foo", bar, :baz],
49+
d: (2 + 2) * 2,
50+
e: proc { |e| e + e }
51+
hello, world = [1,2]
52+
do_something1
53+
do_something2
54+
end

0 commit comments

Comments
 (0)