Skip to content

[3.3] Backport syntax_suggest 2.0.3#15924

Merged
hsbt merged 12 commits intoruby:ruby_3_3from
Earlopain:backport-syntax-suggest-3.3
Mar 23, 2026
Merged

[3.3] Backport syntax_suggest 2.0.3#15924
hsbt merged 12 commits intoruby:ruby_3_3from
Earlopain:backport-syntax-suggest-3.3

Conversation

@Earlopain
Copy link
Copy Markdown
Contributor

schneems and others added 11 commits January 21, 2026 18:12
In ruby#225 it was reported that the output looks incorrect:

```
$ cat /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
def x.y.z
end
$ ruby /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
/tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb: --> /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
expected a delimiter to close the parametersunexpected '.', ignoring it
> 1  def x.y.z
> 2  end
```

Specifically:

```
expected a delimiter to close the parametersunexpected '.', ignoring it
```

However this does not show up when executing the debug executable:

```
$ bin/bundle exec exe/syntax_suggest /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
--> /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb

expected a delimiter to close the parameters
unexpected '.', ignoring it

> 1  def x.y.z
> 2  end
```

This is because `exe/syntax_suggest` uses STDOUT.puts while calling `ruby` with the filename uses a fake IO object represented by MiniStringIO. This class was incorrectly not adding a newline to the end of the print.

The fix was to move the class to it's own file where it can be tested and then fix the behavior.

close ruby/syntax_suggest#225

ruby/syntax_suggest@d2ecd94a3b

Co-authored-by: Andy Yong <andyywz@gmail.com>
It used to not emit this token type, but now it does.
So when a newer version of prism is present, we can fall back
to the same code that ripper uses.

Ref:
* ruby#15914
* ruby/prism#3859

ruby/syntax_suggest@42a3b8f6cb
The reason this logic for different methods branches in the class instead of internally was to be eagerly aggressive about runtime performance. This code is currently only used once for the document where it's invoked ~N times (where N is number of lines):

```ruby
module SyntaxSuggest
  class CleanDocument
    # ...
    def join_trailing_slash!
      trailing_groups = @document.select(&:trailing_slash?).map do |code_line|
        take_while_including(code_line.index..) { |x| x.trailing_slash? }
      end
      join_groups(trailing_groups)
      self
    end
```

Since this is not currently a hot-spot I think merging the branches and using a case statement is a reasonable tradeoff and avoids the need to do specific version testing.

An alternative idea was presented in ruby#241 of behavior-based testing for branch logic (which I would prefer), however, calling the code triggered requiring a `DelegateClass` when the `syntax_suggest/api` is being required.

ruby/syntax_suggest@ab122c455f
This commit didn't apply for some reason
@Earlopain Earlopain force-pushed the backport-syntax-suggest-3.3 branch from ddaeb39 to a8d98fd Compare January 21, 2026 17:41
@hsbt hsbt self-assigned this Feb 10, 2026
@hsbt hsbt merged commit 2772163 into ruby:ruby_3_3 Mar 23, 2026
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants