WebStorm plugin: DiagnosticTools crashes on Cmd+` (NextWindow) due to invalid PSI elements
Summary
The Claude Code WebStorm plugin's DiagnosticTools listener causes SEVERE crashes and contributes to EDT starvation when switching between project windows with Cmd+` (NextWindow action).
Environment
- IDE: WebStorm 2025.3.2 / 2025.3.3 / 2025.3.4
- Plugin version: Claude Code plugin 0.1.14-beta
- OS: macOS (Darwin)
- JDK: 21.0.9 / 21.0.10 (JetBrains)
- Setup: Multiple projects open simultaneously
Steps to Reproduce
- Open multiple projects in separate WebStorm windows
- Have files open with active code analysis (TypeScript, Markdown, etc.)
- Press Cmd+` to switch between windows
Expected Behavior
Window switching should complete without errors.
Actual Behavior
The NextWindow action triggers SEVERE errors from the plugin's DiagnosticTools listener:
PsiInvalidElementAccessException in DiagnosticTools
The plugin's DiagnosticTools listener (DiagnosticTools.kt:106) subscribes to DaemonCodeAnalyzer.DaemonListener.daemonFinished events. When the window switch causes the daemon to stop/restart, the listener calls isErrorAnalyzingFinished() which tries to access PSI file elements that have already been invalidated during the focus change.
SEVERE - #c.i.u.m.i.MessageBusImpl - Last Action: NextWindow
com.intellij.diagnostic.PluginException: Invalid PSI Element: class com.intellij.lang.javascript.psi.impl.JSFileImpl #TypeScript
at com.intellij.psi.util.PsiUtilCore.ensureValid(PsiUtilCore.java:509)
at com.intellij.psi.impl.source.PsiFileImpl.getTextLength(PsiFileImpl.java:349)
at com.intellij.psi.impl.source.PsiFileImpl.getTextRange(PsiFileImpl.java:355)
at com.intellij.codeInsight.daemon.impl.FileStatusMap.getFileDirtyScope(FileStatusMap.java:224)
at com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl.isErrorAnalyzingFinished(DaemonCodeAnalyzerImpl.java:931)
at com.anthropic.code.plugin.mcp.tools.DiagnosticTools$addTools$1$1$1.daemonFinished(DiagnosticTools.kt:106)
This error fires repeatedly for multiple file types (TypeScript, Markdown, TextMate), producing suppressed exception counts up to 50+. It is not file-type-specific — it's a general race condition in the listener.
EDT Starvation
These repeated exceptions contribute to EDT starvation, where toolbar action updates block for 1000–13000ms:
WARN - #c.i.o.a.i.ActionUpdater - 13370 ms total to grab EDT 13 times to expand DefaultActionGroup#expandGroup@DiffToolbar
Reproducibility
Observed 6 times across different sessions and WebStorm versions (2025.3.2 through 2025.3.4).
Suggested Fix
The daemonFinished listener in DiagnosticTools.kt:106 should guard against invalidated PSI elements before calling isErrorAnalyzingFinished():
if (psiFile.isValid) {
daemonCodeAnalyzer.isErrorAnalyzingFinished(psiFile)
}
Or wrap the call in a try-catch for PsiInvalidElementAccessException.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗