Skip to content

Commit d4bfb27

Browse files
committed
fix(ruby): narrow context window for ruby
Attempt at fix #361
1 parent 64dd4cf commit d4bfb27

2 files changed

Lines changed: 115 additions & 41 deletions

File tree

queries/ruby/context.scm

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
(class
2-
(body_statement) @context.end) @context
2+
name: (constant)
3+
(_) @context.end) @context
34

45
(singleton_class
5-
(body_statement) @context.end) @context
6+
value: (self) @context.end) @context
67

78
(module
8-
(body_statement) @context.end) @context
9+
name: (constant) @context.end) @context
10+
11+
(method
12+
name: (identifier)
13+
parameters: (method_parameters) @context.end) @context
914

1015
(method
11-
(body_statement) @context.end) @context
16+
name: (identifier) @context.end) @context
17+
18+
(singleton_method
19+
object: (self)
20+
name: (identifier)
21+
parameters: (method_parameters) @context.end) @context
1222

1323
(singleton_method
14-
(body_statement) @context.end) @context
24+
object: (self)
25+
name: (identifier) @context.end) @context
1526

1627
(if
1728
(then) @context.end) @context
1829

1930
(if
20-
(else
21-
(_) @context.end)) @context
31+
condition: (_) @context.end) @context
32+
33+
(else
34+
(_) @context.end) @context
2235

2336
(unless
2437
(then) @context.end) @context
2538

2639
(unless
27-
(else
28-
(_) @context.end)) @context
40+
condition: (_) @context.end) @context
2941

30-
(_
31-
(do_block
32-
(body_statement) @context.end)) @context
42+
(do_block
43+
parameters: (block_parameters) @context.end) @context
3344

3445
(call
3546
method: (identifier) @_identifier

test/lang/test.rb

Lines changed: 92 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,108 @@
1+
# {{TEST}}
12
# frozen_string_literal: true
23

3-
module Bar # BUG: The contexts here include too many newlines
4-
class Foo
5-
class << self
6-
def run
4+
# BUG: The contexts need newlines or they don't appear
75

6+
# Comment before module starts
7+
module Bar # {{CONTEXT}}
8+
# Comment after module starts
89

910

11+
# {{CURSOR}}
12+
# Comment before class starts
13+
class Foo # {{CONTEXT}}
14+
# Comment after class starts
1015

11-
if false
12-
(20..30).each do |element|
13-
block.call(element)
14-
end
15-
else
16-
1 + 1
17-
end
18-
end
19-
end
2016

21-
def self.other_method
22-
unless false
23-
(10..20).each do |element|
24-
block.call(element)
25-
end
26-
else
27-
1 + 1
28-
end
29-
end
17+
# {{CURSOR}}
18+
# Comment before singleton class starts
19+
class << self # {{CONTEXT}}
20+
# Comment after singleton class starts
3021

31-
def run(&block)
32-
unless false
33-
(1..10).each do |element|
34-
block.call(element)
35-
end
36-
else
37-
1 + 1
22+
23+
# {{CURSOR}}
24+
# Comment before method starts
25+
def run # {{CONTEXT}}
26+
# Comment after method starts
27+
28+
29+
# {{CURSOR}}
30+
if false # {{CONTEXT}}
31+
# Comment after if starts
32+
33+
34+
# {{CURSOR}}
35+
(20..30).each do |element| # {{CONTEXT}}
36+
# Comment after block starts
37+
38+
39+
block.call(element) # {{CURSOR}}
40+
end # {{POPCONTEXT}}
41+
else # {{CONTEXT}}
42+
# Comment after else starts
43+
44+
45+
1 + 1 #{{CURSOR}}
46+
end # {{POPCONTEXT}}
47+
end # {{POPCONTEXT}}
48+
end # {{POPCONTEXT}}
49+
# {{POPCONTEXT}} # XXX: Extra pop to pop the else context
50+
51+
# Comment before singleton method
52+
def self.other_method # {{CONTEXT}}
53+
# Comment after singleton method starts
54+
55+
56+
# {{CURSOR}}
57+
unless false # {{CONTEXT}}
58+
# Comment after unless starts
59+
60+
61+
# {{CURSOR}}
62+
(10..20).each do |element| # {{CONTEXT}}
63+
# Comment after block starts
64+
65+
66+
block.call(element) # {{CURSOR}}
67+
end # {{POPCONTEXT}}
68+
else # {{CONTEXT}}
69+
# Comment after else starts
70+
71+
72+
1 + 1 # {{CURSOR}}
73+
end # {{POPCONTEXT}}
74+
end # {{POPCONTEXT}}
75+
# {{POPCONTEXT}} # XXX: Extra pop to pop the else context
76+
77+
# Comment before method starts
78+
def run(&block) # {{CONTEXT}}
79+
# Comment after method starts
80+
81+
82+
# {{CURSOR}}
83+
unless false # {{CONTEXT}}
84+
# Comment after unless starts
85+
86+
87+
# {{CURSOR}}
88+
(1..10).each do |element| # {{CONTEXT}}
89+
# Comment after block starts
90+
91+
92+
block.call(element) # {{CURSOR}}
93+
end # {{POPCONTEXT}}
94+
else # {{CONTEXT}}
95+
# Comment after else starts
96+
97+
98+
1 + 1 # {{CURSOR}}
3899
end
39100
end
40101
end
41102
end
42103

104+
# {{TEST}}
105+
43106
RSpec.describe 'foo' do # {{CONTEXT}}
44107
context 'bar' do # {{CONTEXT}}
45108
shared_context 'shared context' do # {{CONTEXT}}

0 commit comments

Comments
 (0)