fix(linter): fix LSP panic from stale directive spans#18082
fix(linter): fix LSP panic from stale directive spans#18082graphite-app[bot] merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an LSP panic caused by stale disable directive spans when re-linting files. The panic occurs when cached directives contain spans from old source text but are applied to new source text after the file changes.
Changes:
- Added a
removemethod toDirectivesStoreto clear directives for a specific file path - Clear cached directives before re-linting in
IsolatedLintHandler::lint_path()to prevent stale span usage
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_linter/src/lint_runner.rs | Adds remove method to clear directives for a specific path |
| apps/oxlint/src/lsp/isolated_lint_handler.rs | Clears stale directives before re-linting to prevent panics |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
Sysix
left a comment
There was a problem hiding this comment.
One little comment which should be non-blocking
Merge activity
|
## Summary - Clear cached disable directives before re-linting a file to prevent using outdated spans - Add `remove` method to `DirectivesStore` for per-path directive removal ## Root Cause The `DirectivesStore` caches disable directives per file path. When a file is edited and re-linted: 1. If linting succeeds and produces directives → they are updated in the store 2. If linting fails or doesn't produce directives (e.g., parse errors, partial loader files) → **old directives remain in the store** When the file content changes between linting runs and the new linting fails to update directives, the stored directives contain spans calculated from the OLD source text. Using these stale spans with the NEW source text/rope causes the "byte index out of bounds" panic. ## Fix 1. Added `remove` method to `DirectivesStore` for clearing directives for a specific file 2. Call `remove` before linting in `IsolatedLintHandler::lint_path()` to ensure stale directives are cleared This ensures that when a file is re-linted, any stale directives from previous runs are cleared first. If the new linting run produces fresh directives, they'll be stored; if not, no stale directives will be used. ## Test plan - Existing LSP tests pass (73 tests) - Unused directives tests pass Closes #15415 🤖 Generated with [Claude Code](https://claude.ai/code)
41743cf to
6956543
Compare
Summary
removemethod toDirectivesStorefor per-path directive removalRoot Cause
The
DirectivesStorecaches disable directives per file path. When a file is edited and re-linted:When the file content changes between linting runs and the new linting fails to update directives, the stored directives contain spans calculated from the OLD source text. Using these stale spans with the NEW source text/rope causes the "byte index out of bounds" panic.
Fix
removemethod toDirectivesStorefor clearing directives for a specific fileremovebefore linting inIsolatedLintHandler::lint_path()to ensure stale directives are clearedThis ensures that when a file is re-linted, any stale directives from previous runs are cleared first. If the new linting run produces fresh directives, they'll be stored; if not, no stale directives will be used.
Test plan
Closes #15415
🤖 Generated with Claude Code