Skip to content

Commit 9d2d9d6

Browse files
committed
Revert "Let Location support sub buffers"
This reverts commit 83a683d.
1 parent 36cc0b4 commit 9d2d9d6

4 files changed

Lines changed: 11 additions & 132 deletions

File tree

ext/rbs_extension/location.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ void rbs__init_location(void) {
314314
rb_define_private_method(RBS_Location, "initialize", location_initialize, 3);
315315
rb_define_private_method(RBS_Location, "initialize_copy", location_initialize_copy, 1);
316316
rb_define_method(RBS_Location, "buffer", location_buffer, 0);
317-
rb_define_method(RBS_Location, "_start_pos", location_start_pos, 0);
318-
rb_define_method(RBS_Location, "_end_pos", location_end_pos, 0);
317+
rb_define_method(RBS_Location, "start_pos", location_start_pos, 0);
318+
rb_define_method(RBS_Location, "end_pos", location_end_pos, 0);
319319
rb_define_method(RBS_Location, "_add_required_child", location_add_required_child, 3);
320320
rb_define_method(RBS_Location, "_add_optional_child", location_add_optional_child, 3);
321321
rb_define_method(RBS_Location, "_add_optional_no_child", location_add_optional_no_child, 1);

lib/rbs/location_aux.rb

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ def self.new(buffer_ = nil, start_pos_ = nil, end_pos_ = nil, buffer: nil, start
2828

2929
WithChildren = self
3030

31-
def start_pos
32-
buffer.absolute_position(_start_pos) || raise
33-
end
34-
35-
def end_pos
36-
buffer.absolute_position(_end_pos) || raise
37-
end
38-
3931
def name
4032
buffer.name
4133
end
@@ -57,19 +49,19 @@ def end_column
5749
end
5850

5951
def start_loc
60-
@start_loc ||= buffer.top_buffer.pos_to_loc(start_pos)
52+
@start_loc ||= buffer.pos_to_loc(start_pos)
6153
end
6254

6355
def end_loc
64-
@end_loc ||= buffer.top_buffer.pos_to_loc(end_pos)
56+
@end_loc ||= buffer.pos_to_loc(end_pos)
6557
end
6658

6759
def range
6860
@range ||= start_pos...end_pos
6961
end
7062

7163
def source
72-
@source ||= (buffer.top_buffer.content[range] || raise)
64+
@source ||= (buffer.content[range] || raise)
7365
end
7466

7567
def to_s
@@ -142,25 +134,5 @@ def optional_key?(name)
142134
def required_key?(name)
143135
_required_keys.include?(name)
144136
end
145-
146-
def local_location
147-
loc = Location.new(buffer.detach, _start_pos, _end_pos)
148-
149-
each_optional_key do |key|
150-
value = self[key]
151-
if value
152-
loc.add_optional_child(key, value._start_pos...value._end_pos)
153-
else
154-
loc.add_optional_child(key, nil)
155-
end
156-
end
157-
158-
each_required_key do |key|
159-
value = self[key] or raise
160-
loc.add_required_child(key, value._start_pos...value._end_pos)
161-
end
162-
163-
loc #: self
164-
end
165137
end
166138
end

sig/location.rbs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@ module RBS
88
# The buffer this location points on.
99
attr_reader buffer (): Buffer
1010

11-
# The absolute start index of character the range starts from
12-
#
13-
# It returns the index in the `buffer.top_buffer`.
14-
#
11+
# The index of character the range starts from.
1512
attr_reader start_pos (): Integer
1613

17-
# The absolute end index of character the range ends at
18-
#
19-
# It returns the index in the `buffer.top_buffer`.
20-
#
14+
# The index of character the range ends at.
2115
attr_reader end_pos (): Integer
2216

2317
def initialize: (Buffer, Integer start_pos, Integer end_pos) -> void
@@ -30,37 +24,26 @@ module RBS
3024
# Returns the name of the buffer.
3125
def name: () -> untyped
3226

33-
# The *raw* index of character the range starts from.
34-
attr_reader _start_pos (): Integer
35-
36-
# The *raw* index of character the range ends at.
37-
attr_reader _end_pos (): Integer
38-
39-
# Line of the `start_pos` (1 origin, absolute)
27+
# Line of the `start_pos` (1 origin)
4028
attr_reader start_line (): Integer
4129

42-
# Column of the `start_pos` (0 origin, absolute)
30+
# Column of the `start_pos` (0 origin)
4331
attr_reader start_column (): Integer
4432

45-
# Line of the `end_pos` (1 origin, absolute)
33+
# Line of the `end_pos` (1 origin)
4634
attr_reader end_line (): Integer
4735

48-
# Column of the `end_pos` (0 origin, absolute)
36+
# Column of the `end_pos` (0 origin)
4937
attr_reader end_column (): Integer
5038

51-
# The absolute line-column pair of the start position
52-
#
5339
attr_reader start_loc (): Buffer::loc
5440

5541
@start_loc: Buffer::loc?
5642

57-
# The absolute line-column pair of the end position
58-
#
5943
attr_reader end_loc (): Buffer::loc
6044

6145
@end_loc: Buffer::loc?
6246

63-
# The absolute range of the start and end position
6447
attr_reader range (): Range[Integer]
6548

6649
@range: Range[Integer]?
@@ -114,10 +97,6 @@ module RBS
11497

11598
def key?: (Symbol) -> bool
11699

117-
# Returns the location of the buffer, but the buffer is detached from the parent buffer
118-
#
119-
def local_location: () -> self
120-
121100
private
122101

123102
def _add_required_child: (RequiredChildKeys name, Integer start_pos, Integer end_pos) -> void

test/rbs/location_test.rb

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -89,78 +89,6 @@ def test_location_inspect
8989
assert_include loc.inspect, "source=\"class Foo\""
9090
end
9191

92-
def test_sub_buffer_location
93-
buffer = buffer()
94-
# 01
95-
# bc
96-
buffer = buffer.sub_buffer(lines: [0...2, 5...7])
97-
98-
loc = Location.new(buffer, 0, 5)
99-
100-
# Raw positions
101-
assert_equal 0, loc._start_pos
102-
assert_equal 5, loc._end_pos
103-
104-
# Absolute positions
105-
assert_equal 0, loc.start_pos
106-
assert_equal 7, loc.end_pos
107-
assert_equal [1, 0], loc.start_loc
108-
assert_equal [2, 3], loc.end_loc
109-
110-
assert_equal "123\nabc", loc.source
111-
112-
loc.add_optional_child(:opt, 0...2)
113-
loc[:opt].tap do |loc|
114-
assert_equal 0, loc.start_pos
115-
assert_equal 2, loc.end_pos
116-
assert_equal "12", loc.source
117-
end
118-
119-
loc.add_required_child(:req, 1...4)
120-
loc[:req].tap do |loc|
121-
assert_equal 1, loc.start_pos
122-
assert_equal 6, loc.end_pos
123-
assert_equal "23\nab", loc.source
124-
end
125-
end
126-
127-
def test_sub_buffer_local_location
128-
buffer = buffer()
129-
# 01
130-
# bc
131-
buffer = buffer.sub_buffer(lines: [0...2, 5...7])
132-
133-
loc = Location.new(buffer, 0, 5)
134-
loc.add_optional_child(:opt, 0...2)
135-
loc.add_required_child(:req, 1...4)
136-
137-
loc = loc.local_location
138-
139-
# Raw positions
140-
assert_equal 0, loc._start_pos
141-
assert_equal 5, loc._end_pos
142-
143-
# Absolute positions in sub buffer
144-
assert_equal 0, loc.start_pos
145-
assert_equal 5, loc.end_pos
146-
assert_equal [1, 0], loc.start_loc
147-
assert_equal [2, 2], loc.end_loc
148-
149-
assert_equal "12\nbc", loc.source
150-
151-
loc[:opt].tap do |loc|
152-
assert_equal 0, loc.start_pos
153-
assert_equal 2, loc.end_pos
154-
assert_equal "12", loc.source
155-
end
156-
157-
loc[:req].tap do |loc|
158-
assert_equal 1, loc.start_pos
159-
assert_equal 4, loc.end_pos
160-
assert_equal "2\nb", loc.source
161-
end
162-
end
163-
16492
private
16593

16694
def buffer(content: nil)

0 commit comments

Comments
 (0)