instance method
ErrorHighlight::Spotter#prism_spot_call_for_name
prism_spot_call_for_name
lib/error_highlight/base.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/error_highlight/base.rb, line 743
def prism_spot_call_for_name
# Explicitly turn off foo.() syntax because error_highlight expects this
# to not work.
return nil if @node.name == :call && @node.message_loc.nil?
location = @node.message_loc || @node.call_operator_loc || @node.location
location = @node.call_operator_loc.join(location) if @node.call_operator_loc&.start_line == location.start_line
# If the method name ends with "=" but the message does not, then this is
# a method call using the "attribute assignment" syntax
# (e.g., foo.bar = 1). In this case we need to go retrieve the = sign and
# add it to the location.
if (name = @node.name).end_with?("=") && !@node.message.end_with?("=")
location = location.adjoin("=")
end
prism_location(location)
if !name.end_with?("=") && !name.match?(/[[:alpha:]_\[]/)
# If the method name is an operator, then error_highlight only
# highlights the first line.
fetch_line(location.start_line)
end
end
Example:
x.foo ^^^^ x.foo(42) ^^^^ x&.foo ^^^^^ x[42] ^^^^ x.foo = 1 ^^^^^^ x[42] = 1 ^^^^^^ x + 1 ^ +x ^ foo(42) ^^^ foo 42 ^^^ foo ^^^