36 Commits
Author SHA1 Message Date
Koichi Sasada 583587dfbf [ruby/error_highlight] use instance_method to get method object
instead of `method()`.

There is a bug around `define_method`, so this patch is workaround.

https://github.com/ruby/error_highlight/commit/4d04537f58
2024-10-31 00:30:10 +00:00
Nobuyoshi Nakada a9f509e6c5 [ruby/error_highlight] Redefine in the module context
https://github.com/ruby/error_highlight/commit/0048bd0285
2024-10-29 17:40:08 +00:00
Nobuyoshi Nakada e22d5c2584 Fix method definition owners 2024-10-30 02:02:20 +09:00
Nobuyoshi Nakada 21b3dfa03b [ruby/error_highlight] Suppress smaller max_snippet_width warning
https://github.com/ruby/error_highlight/commit/9cd14c5b9a
2024-10-29 07:56:32 +00:00
Guilherme Carreiro 0b3d518e81 [ruby/error_highlight] Rename the ErrorHighlight::DefaultFormatter setting to max_snippet_width for clarity
https://github.com/ruby/error_highlight/commit/e13cbd4335
2024-10-24 00:29:20 +00:00
Guilherme Carreiro e9ba6c2ea4 [ruby/error_highlight] Adjust truncation, add opt-out mechanism, rename methods, and prepare error highlighting to render on extremely small screens
https://github.com/ruby/error_highlight/commit/c565340958
2024-10-23 00:58:50 +00:00
Guilherme Carreiro e7c9dfb3e9 [ruby/error_highlight] Handle very long lines with errors in the middle of the line
https://github.com/ruby/error_highlight/commit/0657bc1afa
2024-10-23 00:58:50 +00:00
Guilherme Carreiro 5aa8b9e3b5 [ruby/error_highlight] Handle very long lines
https://github.com/ruby/error_highlight/commit/383490a4b4
2024-10-23 00:58:50 +00:00
tompng af1c356c7b Update default gem test for colon-style hash inspect 2024-10-03 18:47:09 +09:00
Luke Gruber 2a0ee408af [ruby/error_highlight] Fix error with prism when method given no arguments
such as:

  p = Proc.new

This now matches the RubyVM::AbstractSyntaxTree behavior, which is
not to highlight anything.

https://github.com/ruby/error_highlight/commit/d5c592a1ba
2024-09-24 13:28:01 +00:00
Yusuke Endoh bb1ef81732 [ruby/error_highlight] Make test_COLON2_5 conditional again
https://github.com/ruby/error_highlight/commit/da5e76bb06
2024-07-12 06:26:53 +00:00
Kevin Newton c1df15c3e6 [PRISM] Use node ids for error highlight 2024-07-11 14:25:54 -04:00
Kevin Newton 40ec860de7 [ruby/error_highlight] Support for the prism compiler
https://github.com/ruby/error_highlight/commit/69fbacfd49
2024-06-07 13:15:14 +00:00
Yusuke Endoh eb410c9fde [ruby/error_highlight] Load "did_you_mean" explicitly in test
I'm not sure how it works, but I seem to get an error
`undefined method 'formatter' for module DidYouMean` in parallel mode of
`make test-all`.

https://app.launchableinc.com/organizations/ruby/workspaces/ruby/data/test-paths/file%3Dtest%2Ferror_highlight%2Ftest_error_highlight.rb%23class%3DErrorHighlightTest%23testcase%3Dtest_explicit_raise_name_error?organizationId=ruby&workspaceId=ruby&testPathId=file%3Dtest%2Ferror_highlight%2Ftest_error_highlight.rb%23class%3DErrorHighlightTest%23testcase%3Dtest_explicit_raise_name_error&testSessionStatus=flake

https://github.com/ruby/error_highlight/commit/f931b42430
2024-05-20 03:47:22 +00:00
Yusuke Endoh 25d74b9527 Do not include a backtick in error messages and backtraces
[Feature #16495]
2024-02-15 18:42:31 +09:00
Yusuke Endoh 29f88b9fea [ruby/error_highlight] Support the new message format of NameError in Ruby 3.3
https://bugs.ruby-lang.org/issues/18285
https://github.com/ruby/ruby/pull/6950

https://github.com/ruby/error_highlight/commit/a7c2da052e
2023-02-19 10:29:56 +00:00
Yusuke Endoh 94d6d6d93f [ruby/error_highlight] Identify which node in Foo::Bar::Baz causes a NameError
In Ruby 3.2 or later, a nested constant access like `Foo::Bar::Baz` is
compiled to one instruction by the optimization https://github.com/ruby/ruby/pull/6187

We try to spot which sub-node caues a NameError in question based on the
constant name. We will give up if the same constant name is accessed in
a nested access (`Foo::Foo`).

Fixes https://github.com/ruby/error_highlight/pull/31

https://github.com/ruby/error_highlight/commit/0a4db7da0a
2023-01-13 08:25:09 +00:00
Yusuke Endoh 81c494d810 [ruby/error_highlight] Enable tests for TypeError and ArgumentError
These tests were unintentionally disabled by `if false`

https://github.com/ruby/error_highlight/commit/fa6d00d80d
2022-11-14 06:22:35 +00:00
eileencodesandAaron Patterson 350d0aa023 [ruby/error_highlight] Support nodes in spot
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/6593

https://github.com/ruby/error_highlight/commit/0b1b650a59

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2022-10-31 04:58:38 +00:00
Yusuke Endoh 3a58009066 [ruby/error_highlight] Make backtrace_location keyword work
We had to keep backtrace_location before opts is overwritten.

https://github.com/ruby/error_highlight/commit/2735e4681a
2022-08-10 21:19:10 +09:00
Yusuke Endoh 99e7fa5b37 [ruby/error_highlight] Make ErrorHighlight.spot accept Exception (https://github.com/ruby/error_highlight/pull/25)
... and move things from core_ext.rb to base.rb.
This will confine CRuby-dependent things to ErrorHighlight.spot.

https://github.com/ruby/error_highlight/commit/22d1dd7824
2022-08-10 18:37:13 +09:00
Yusuke Endoh f075be3dcb [ruby/error_highlight] Use Exception#detailed_message instead of overriding #message (https://github.com/ruby/error_highlight/pull/24)
See https://bugs.ruby-lang.org/issues/18564.
Ref: https://github.com/ruby/did_you_mean/pull/177

https://github.com/ruby/error_highlight/commit/671b7c61b2
2022-06-07 17:40:19 +09:00
Yusuke Endoh e9a4cc02b4 [ruby/error_highlight] Add a test to check if it is robust against a spoofed filename
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
2022-01-04 23:18:37 +09:00
Christian Boos 11b1ebe606 [ruby/error_highlight] Fix the spurious TypeError.
When we have no backtrace locations, we can't have the highlight,
so just return the message.

https://github.com/ruby/error_highlight/commit/9f5c639494
2022-01-04 23:09:01 +09:00
Christian Boos e22218b510 [ruby/error_highlight] Reproduce the error seen when calling .to_s in embedded Ruby
The test fails with the following error:

Error: test_simulate_funcallv_from_embedded_ruby(ErrorHighlightTest): TypeError: wrong argument type nil (expected method)

https://github.com/ruby/error_highlight/commit/52943c9cd2
2022-01-04 23:09:00 +09:00
Yusuke Endoh 4c32fcb84f [ruby/error_highlight] Make the formatter mechanism support Ractor
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
2021-10-27 11:29:20 +09:00
Yusuke Endoh 5e9598baea [ruby/error_highlight] Fixed the argument for DidYouMean.formatter=
Looks like this bug was hidden by did_you_mean's rescuing any
exceptions.

https://github.com/ruby/error_highlight/commit/7a8f0b4796
2021-08-20 16:27:07 +09:00
Masataka Pocke Kuwabara 242f024bcb [ruby/error_highlight] Keep it work if paren exists after receiver
https://github.com/ruby/error_highlight/commit/b79d679bbd
2021-07-31 22:15:16 +09:00
Hiroshi SHIBATA a4df7cb338 Partly picking https://github.com/ruby/error_highlight/commit/25ef7dbeda4f2cfcad1675f70319401ef4916f40#diff-1ce41a048bf2c08aa7bf25b741e9d3a4e08ea03f0d80bc6b8ee6d1c3c259704dR1022 2021-07-29 16:26:15 +09:00
Nobuyoshi Nakada 29ed9d1aaa [ruby/error_highlight] Fix leaked tempfiles
https://github.com/ruby/error_highlight/commit/8b353a10a7
2021-07-16 15:25:13 +09:00
Yusuke Endoh a5d6ea9266 [ruby/error_highlight] Set the binary mode for Tempfile creation in a test
https://github.com/ruby/error_highlight/commit/8273d3b6f2
2021-07-13 20:30:20 +09:00
Yusuke Endoh 5fd5d71a4b [ruby/error_highlight] Support a file that has no final newline
https://github.com/ruby/error_highlight/commit/9d671284cb
2021-07-13 16:54:17 +09:00
Yusuke Endoh 23c8bc367c [ruby/error_highlight] Support hard tabs
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 #7

https://github.com/ruby/error_highlight/commit/38f20fa542
2021-07-13 16:51:02 +09:00
Yusuke Endoh 84fea8ee39 [ruby/error_highlight] Update a test for multibyte characters
https://github.com/ruby/error_highlight/commit/2fc70d7f8e
2021-07-12 16:48:52 +09:00
Yusuke Endoh f428ced69c [ruby/error_highlight] Experimentally support a custom formatter
https://github.com/ruby/error_highlight/commit/f40a1de20e
2021-06-30 12:49:18 +09:00
Yusuke Endoh 9438c99590 Rename error_squiggle to error_highlight 2021-06-29 23:45:49 +09:00