summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYusuke Endoh <[email protected]>2025-01-29 17:33:30 +0900
committergit <[email protected]>2025-01-29 08:51:42 +0000
commite01b4ca1c8eb24528b950bf77c9d0415bf1a1719 (patch)
treebd6e820cec0aa5cbb469c12c7a20ab4a4896fada /lib
parentbe44d5677d67b7f365eedfd81fda495a75e60f16 (diff)
[ruby/error_highlight] Ensure first_line and last_line are set
Fixes https://github.com/ruby/error_highlight/pull/58 https://github.com/ruby/error_highlight/commit/9ddc1f31a9
Diffstat (limited to 'lib')
-rw-r--r--lib/error_highlight/base.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/error_highlight/base.rb b/lib/error_highlight/base.rb
index e2077fa5a6..14e0ce5785 100644
--- a/lib/error_highlight/base.rb
+++ b/lib/error_highlight/base.rb
@@ -344,6 +344,7 @@ module ErrorHighlight
end
elsif mid.to_s =~ /\A\W+\z/ && lines.match(/\G\s*(#{ Regexp.quote(mid) })=.*\n/, nd_recv.last_column)
@snippet = $` + $&
+ @beg_lineno = @end_lineno = lineno
@beg_column = $~.begin(1)
@end_column = $~.end(1)
end
@@ -582,8 +583,9 @@ module ErrorHighlight
@beg_column = nd_parent.last_column
@end_column = @node.last_column
else
- @snippet = @fetch[@node.last_lineno]
+ fetch_line(@node.last_lineno)
if @snippet[[email protected]_column].match(/#{ Regexp.quote(const) }\z/)
+ @beg_lineno = @end_lineno = @node.last_lineno
@beg_column = $~.begin(0)
@end_column = $~.end(0)
end
@@ -597,7 +599,7 @@ module ErrorHighlight
nd_lhs, op, _nd_rhs = @node.children
*nd_parent_lhs, _const = nd_lhs.children
if @name == op
- @snippet = @fetch[nd_lhs.last_lineno]
+ fetch_line(nd_lhs.last_lineno)
if @snippet.match(/\G\s*(#{ Regexp.quote(op) })=/, nd_lhs.last_column)
@beg_column = $~.begin(1)
@end_column = $~.end(1)
@@ -607,12 +609,12 @@ module ErrorHighlight
@end_column = nd_lhs.last_column
if nd_parent_lhs.empty? # example: ::C += 1
if nd_lhs.first_lineno == nd_lhs.last_lineno
- @snippet = @fetch[nd_lhs.last_lineno]
+ fetch_line(nd_lhs.last_lineno)
@beg_column = nd_lhs.first_column
end
else # example: Foo::Bar::C += 1
if nd_parent_lhs.last.last_lineno == nd_lhs.last_lineno
- @snippet = @fetch[nd_lhs.last_lineno]
+ fetch_line(nd_lhs.last_lineno)
@beg_column = nd_parent_lhs.last.last_column
end
end