Skip to content

[3.4] Backport syntax_suggest 2.0.3#15923

Open
Earlopain wants to merge 6 commits intoruby:ruby_3_4from
Earlopain:backport-syntax-suggest-3.4
Open

[3.4] Backport syntax_suggest 2.0.3#15923
Earlopain wants to merge 6 commits intoruby:ruby_3_4from
Earlopain:backport-syntax-suggest-3.4

Conversation

@Earlopain
Copy link
Copy Markdown
Contributor

hsbt and others added 5 commits January 21, 2026 18:07
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 force-pushed the backport-syntax-suggest-3.4 branch from b341175 to 741711a Compare January 21, 2026 17:40
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