-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Problem
In long-running sessions (e.g., when using lean-lsp-mcp with Claude Code), the diagnostics returned by the LSP can become stale. Specifically, diagnostics may differ from what a fresh lake build <file> produces on the same file.
This issue is hard to reproduce reliably, but seems to occur when:
- Files are edited externally (e.g., by an AI coding assistant)
- leanclient syncs the new content via
textDocument/didChange - Diagnostics are retrieved, but they don't reflect the true compilation state
Running lake build externally and then querying diagnostics can produce different (often more accurate) results.
Where does the problem originate?
This may be a layered issue:
Lean LSP server (incremental elaboration)
↑
leanclient (Python LSP client)
↑
lean-lsp-mcp (MCP wrapper)
↑
Claude Code (edits files)
Lean LSP server: Uses incremental elaboration for performance. When textDocument/didChange is received, it re-elaborates the file but may use cached/stale internal state for imports and dependencies. This is likely the root cause.
leanclient: Correctly syncs file content to the LSP server. However, there may be limited options for forcing a full re-elaboration vs. incremental.
lean-lsp-mcp: Could detect staleness and trigger rebuilds, but this is a workaround rather than a fix.
Questions
-
Is there an LSP protocol mechanism to force the Lean LSP server to fully re-elaborate a file (not incrementally)?
-
Does closing and reopening a file (
force_reopen=True) help clear the LSP server's internal state? -
Should this be raised as an issue with the Lean project if the root cause is in the LSP server's incremental elaboration?
Potential mitigations
In leanclient
- Track file modification times to detect when external edits occurred
- Expose staleness detection so consumers can decide how to respond
- Test whether
force_reopen=Truehelps vs. justdidChange
In lean-lsp-mcp
- Detect staleness before returning diagnostics
- Auto-trigger
lean_buildwhen stale state is detected (slow but reliable)
Notes
- The issue primarily manifests in long-running agentic sessions with many edits
- Current workaround is periodic
lean_buildcalls, but this is slow - Understanding whether this is fixable at the client level or requires Lean changes would help prioritize the right solution