Skip to content

Commit

Permalink
Stop evaling command when it detects that the code will never be valid
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Mar 29, 2024
1 parent 08753a9 commit 892b889
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/pry/repl.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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)".
#
Expand Down

0 comments on commit 892b889

Please sign in to comment.