Skip to content

Report evaluate compile errors in the response instead of stderr - #1292

Open
daviwil wants to merge 1 commit into
elixir-lsp:masterfrom
daviwil:fix/evaluate-diagnostics
Open

daviwil wants to merge 1 commit into
elixir-lsp:masterfrom
daviwil:fix/evaluate-diagnostics

Conversation

@daviwil

@daviwil daviwil commented Nov 5, 2026

Copy link
Copy Markdown

Fixes #1291

Since Elixir 1.15, Code.eval_string/3 prints compiler diagnostics to stderr before raising CompileError, and the exception only says cannot compile file (errors have been logged). So a failed evaluate (hovering over defmodule while paused, for example) sent the diagnostic to the client as a stderr output event, once per hover, and the evaluateError it returned did not contain the actual message.

evaluate_code_expression/3 now runs inside Code.with_diagnostics/1:

  • On CompileError, the error diagnostics replace the exception's description, so the response starts with ** (CompileError) lib/foo.ex: undefined variable "defmodule" and the error is not printed.
  • Other diagnostics, such as warnings, are still printed with Code.print_diagnostic/1, on success and on failure. They now come out after the evaluation returns rather than before it runs.
  • The Code.with_diagnostics/2 frame is dropped from the reported stacktrace.

This covers every evaluate context (hover, watch, repl, clipboard). Conditional breakpoints, hit conditions and log points use the separate BreakpointCondition path and still print diagnostics; there the printed diagnostic is the only place the error message appears, so I left it alone. Happy to fold it into their console message in a follow-up if you want.

New tests in debugger_test.exs cover a compile error (message in the response, nothing on stderr), a compile error with a warning (only the warning printed) and a warning on a successful evaluate.

Since Elixir 1.15, Code.eval_string/3 prints compiler diagnostics to
stderr before raising CompileError, and the CompileError itself only
says "cannot compile file (errors have been logged)". A failed
evaluate, such as hovering over `defmodule` while paused, therefore
sent the diagnostic to the client as a stderr output event and
returned an evaluateError without the actual message. Each hover added
another block to the debug console.

Run the evaluation inside Code.with_diagnostics/1. When it raises
CompileError, use the error diagnostics as the description, so the
evaluateError carries the message instead of stderr. Other diagnostics,
such as warnings, are still printed, now after the evaluation returns.

Fixes elixir-lsp#1291

This branch has not been deployed

No deployments
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.

Debug adapter: a failed evaluate prints compiler diagnostics to the Debug Console

1 participant