From 94d27c433ed61cb9734699b1fed15a0dcee66a4e Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Tue, 20 Jan 2026 13:38:50 +0100 Subject: [PATCH] Handle `on_sp` when using prism 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: * https://github.com/ruby/ruby/pull/15914 * https://github.com/ruby/prism/pull/3859 --- CHANGELOG.md | 2 ++ lib/syntax_suggest/code_line.rb | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee4c4da..60f0cbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## HEAD (unreleased) +- Fix: Correctly identify trailing slashes when using Prism > 1.8.0. (https://github.com/ruby/syntax_suggest/pull/241) + ## 2.0.2 - Fix: Separate multiple parser errors by newline. (https://github.com/ruby/syntax_suggest/pull/232) diff --git a/lib/syntax_suggest/code_line.rb b/lib/syntax_suggest/code_line.rb index 58197e9..892c273 100644 --- a/lib/syntax_suggest/code_line.rb +++ b/lib/syntax_suggest/code_line.rb @@ -180,10 +180,13 @@ def ignore_newline_not_beg? # EOM # expect(lines.first.trailing_slash?).to eq(true) # - if SyntaxSuggest.use_prism_parser? + if SyntaxSuggest.use_prism_parser? && Prism::VERSION <= "1.8.0" + # Older versions of prism didn't correctly emit on_sp def trailing_slash? last = @lex.last - last&.type == :on_tstring_end + return false unless last + + last.type == :on_tstring_end || (last.type == :on_sp && last.token == TRAILING_SLASH) end else def trailing_slash?