Skip to content

[4.0] Backport syntax_suggest 2.0.3#15922

Merged
k0kubun merged 3 commits intoruby:ruby_4_0from
Earlopain:backport-syntax-suggest
Jan 21, 2026
Merged

[4.0] Backport syntax_suggest 2.0.3#15922
k0kubun merged 3 commits intoruby:ruby_4_0from
Earlopain:backport-syntax-suggest

Conversation

@Earlopain
Copy link
Copy Markdown
Contributor

Earlopain and others added 2 commits January 21, 2026 17:49
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
@Earlopain Earlopain requested a review from k0kubun as a code owner January 21, 2026 17:25
Copy link
Copy Markdown
Member

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I just realized they released Ruby 4.0.0 with syntax_suggest v2.0.2 + ruby/syntax_suggest@54bb8ab. So this diff seems like a correct sync.

@k0kubun
Copy link
Copy Markdown
Member

k0kubun commented Jan 21, 2026

Can you add [Backport #21847] or [Bug #21847] in one of these commits? Otherwise I'll need to squash-merge these commits to edit the commit message.

That works for me too, but given that you formatted commits to preserve history, I thought you would prefer keeping that.

@Earlopain
Copy link
Copy Markdown
Contributor Author

Earlopain commented Jan 21, 2026

Ah, I didn't notice. Right, it should in theory look the same as for 3.4.

BTW, how is one supposed to do this? I used ./tool/sync_default_gems -a syntax_suggest but I think I should instead use ./tool/sync_default_gems syntax_suggest. That just seems to delete all related gem files and then crashses after it can't find the just deleted gemspec anymore. I was struggling with this when backporting prism too.

And [Bug #21847] is for automatic release notes probably? I'll do that, yeah. Although, I think I have individual commits because the other variant just doesn't work for me.

@Earlopain Earlopain force-pushed the backport-syntax-suggest branch from da6b74f to edad27b Compare January 21, 2026 17:40
@k0kubun
Copy link
Copy Markdown
Member

k0kubun commented Jan 21, 2026

I think I should instead use ./tool/sync_default_gems syntax_suggest

That is right.

That just seems to delete all related gem files and then crashses after it can't find the just deleted gemspec anymore. I was struggling with this when backporting prism too.

I'm not sure why it doesn't work for you, but tool/sync_default_gems prism normally works fine for me. #15856 was in fact made by that command. Feel free to open PRs to fix the behavior of that file if something breaks it in your environment.

And [Bug #21847] is for automatic release notes probably?

No, these tags are for Redmine. They help me when I use tool/redmine-backporter.rb to close tickets, transitioning the Backport field. Automatic release notes on GitHub releases pick up GitHub PRs without these tags just fine.

@k0kubun k0kubun enabled auto-merge (rebase) January 21, 2026 17:45
@k0kubun k0kubun merged commit e4dd078 into ruby:ruby_4_0 Jan 21, 2026
89 checks passed
@Earlopain
Copy link
Copy Markdown
Contributor Author

Perhaps I have something weird in my git config or something. I'll try to check it out some time. Nice to know it's supposed to work at least.

Should I do something with the ticket? It's closed now because this was merged with the reference (I also added the reference to the other two backport PRs)

@k0kubun
Copy link
Copy Markdown
Member

k0kubun commented Jan 21, 2026

No, I'll work on the status of tickets right before I release the next version. So don't worry about it.

@Earlopain
Copy link
Copy Markdown
Contributor Author

Ah, I understand. As the creator of the ticket, I wouldn't consider it closed until all the backport PRs are merged. But it's no different from all the other tickets that are closed after the issue is fixed on main. So the status doesn't really matter. Thanks for explaining 👍

@Earlopain
Copy link
Copy Markdown
Contributor Author

Earlopain commented Jan 22, 2026

re sync_default_gems. It seems to go wrong fairly early. If I run it on the 3.4 branch it prints this:

Expected '../syntax_suggest' (/home/user/code/ruby/syntax_suggest) to be a directory, but it wasn't.

I guess it lost some error reporting along the way (I'll add that back) . How am I supposed to get this repo there, just clone it myself? Or do I need to run some command first.

On main, it seems to expect it in /home/user/ruby/syntax_suggest. If I do that, then it seems to work (copies over the changes and leaves them for me to commit).

@k0kubun
Copy link
Copy Markdown
Member

k0kubun commented Jan 22, 2026

just clone it myself?

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants