From 892b889054043ec136c9ea845837b798c523d54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Luis=20Leal=20Cardoso=20Junior?= Date: Fri, 29 Mar 2024 10:55:45 -0300 Subject: [PATCH] Stop evaling command when it detects that the code will never be valid --- lib/pry/repl.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb index 3e5129be6..b54fc03a0 100644 --- a/lib/pry/repl.rb +++ b/lib/pry/repl.rb @@ -220,7 +220,7 @@ def input_reline(*args) Pry::InputLock.for(:all).interruptible_region do input.readmultiline(*args) do |multiline_input| Pry.commands.find_command(multiline_input) || - (Prism.parse_success?(multiline_input) && !Reline::IOGate.in_pasting?) + (complete_expression?(multiline_input) && !Reline::IOGate.in_pasting?) end end end @@ -264,6 +264,15 @@ def set_readline_output @readline_output = (Readline.output = Pry.config.output) if piping? end + def complete_expression?(multiline_input) + lex = Prism.lex(multiline_input) + + errors = lex.errors + return true if errors.empty? + + errors.any? { |error| error.type == :unexpected_token_ignore } + end + # Calculates correct overhang for current line. Supports vi Readline # mode and its indicators such as "(ins)" or "(cmd)". #