Fixes a bug where `spot` was using the wrong local variable.
We want to use error highlight with code that has been eval'd,
specifically ERB templates. We can recover the compiled source code of
the ERB template but we need an API to pass the node into error
highlight's `spot`.
Required Ruby PR: https://github.com/ruby/ruby/pull/6593https://github.com/ruby/error_highlight/commit/0b1b650a59
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Previously, RubyVM::AST.of opened a wrong file if the iseq's file path is spoofed.
```
module Dummy
binding.irb
end
```
```
$ ruby test.rb
From: test.rb @ line 2 :
1: module Dummy
=> 2: binding.irb
3: end
irb(Dummy):001:0> foo
/home/mame/work/ruby/local/lib/ruby/3.1.0/error_highlight/base.rb:412:in `spot_colon2': undefined method `last_lineno' for nil:NilClass (NoMethodError)
if nd_parent.last_lineno == @node.last_lineno
^^^^^^^^^^^^
```
Found by @kateinoigakukun
This issue is already fixed in the interpreter side.
This change just adds a test for the case.
https://github.com/ruby/error_highlight/commit/f3626b9032
Now the formatter configuration is per Ractor. DefaultFormatter is used
if not set.
DefaultFormatter#message_for is now a class method to allow sub-Ractors
to call the method.
https://github.com/ruby/error_highlight/commit/9fbaa8ab7c
Now, the highlight line is created by replacing non-tab characters with
spaces, and keeping all hard tabs as-is. This means the highlight line
has the completely same indentation as the code snippet line.
Fixes#7https://github.com/ruby/error_highlight/commit/38f20fa542