Cache invalidation bug in the LSP with following unexpected token

Open
#16,344 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active

Research direction

Start with the minimal reproduction linked in the issue and inspect Lean's language server cache invalidation path for edits that remove a newline after an unexpected token. Trace how the diagnostic is refreshed when the following token changes. Done means the error updates to report def after the described deletion while still updating correctly when the comment alone is removed.

Written by the indexing model from the issue text.

Description

bug
Prerequisites
  • Check that your issue is not already filed:
    https://github.com/leanprover/lean4/issues
  • Reduce the issue to a minimal, self-contained, reproducible test case.
    Avoid dependencies to Mathlib or Batteries.
  • Test your test case against the latest nightly release, for example on
    https://live.lean-lang.org/#project=lean-nightly
    (You can also use the settings there to switch to “Lean nightly”)
  • When reporting a perceived soundness bug: Does it affect lake check --paranoid?
    If in doubt, please reach out on [email protected] for responsible disclosure.
Description

When reporting "unexpected token", the error message is not updated if only the following token is updated.

Steps to Reproduce
  1. Go to https://live.lean-lang.org/#project=lean-nightly&codez=CYUwZgBARgTg9gaxAOwgLggOQIYBd0C8EAFAIwQDUEATAAwBQA9ALTMQDGcAtlyvs43qhIYOABsxcAO4BLZAHNCEAMxA
  2. See error unexpected token '/--'; expected ')', ',' or ':'
  3. Select from the start of line 2 to the start of line 3
  4. Press [Delete]. It's expected that the entirety of line 2 /-- comment -/ plus the following newline is removed with only this one keystroke.
  5. Observe that the error message remains the same, even though /-- does not appear in the source code at all

Note that if only /-- comment -/ (without the following newline) is removed, the error message would be correctly updated.

Expected behavior: The error message should be updated to unexpected token 'def'; expected ')', ',' or ':'

Versions

Lean 4.37.0-nightly-2026-11-07
Target: x86_64-unknown-linux-gnu Linux

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Dominant language
Lean
Stars
10.3k
Forks
1.1k
Avg merge
19h 8m
Merged PRs (30d)
421

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from leanprover/lean4

All issues in leanprover/lean4

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.