Skip to content

Commit 98cf5b0

Browse files
committed
enhance file event handling to skip delete events and ensure file validity
1 parent fc59303 commit 98cf5b0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/main/java/com/tang/intellij/lua/editor/LuaGutterCacheListener.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.intellij.openapi.startup.ProjectActivity
1919
import com.intellij.openapi.vfs.VirtualFile
2020
import com.intellij.openapi.vfs.VirtualFileManager
2121
import com.intellij.openapi.vfs.newvfs.BulkFileListener
22+
import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent
2223
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
2324
import com.intellij.psi.PsiManager
2425
import com.tang.intellij.lua.lang.LuaFileType
@@ -169,15 +170,23 @@ class LuaGutterCacheStartupActivity : ProjectActivity {
169170
override fun after(events: List<VFileEvent>) {
170171
for (event in events) {
171172
val file = event.file
172-
if (file != null && file.fileType === LuaFileType.INSTANCE) {
173+
if (file != null && file.isValid && file.fileType === LuaFileType.INSTANCE) {
173174
// Clear cache when file changes externally
174175
LuaGutterCacheManager.clearCache(file.url)
175176

177+
// Skip delete events - no need to restart analysis on deleted files
178+
if (event is VFileDeleteEvent) {
179+
continue
180+
}
181+
176182
// Trigger update
177183
ApplicationManager.getApplication().invokeLater {
178-
val psiFile = PsiManager.getInstance(project).findFile(file)
179-
if (psiFile is LuaPsiFile && psiFile.isValid) {
180-
DaemonCodeAnalyzer.getInstance(project).restart(psiFile)
184+
// Double-check file is still valid when callback executes
185+
if (file.isValid) {
186+
val psiFile = PsiManager.getInstance(project).findFile(file)
187+
if (psiFile is LuaPsiFile && psiFile.isValid) {
188+
DaemonCodeAnalyzer.getInstance(project).restart(psiFile)
189+
}
181190
}
182191
}
183192
}

0 commit comments

Comments
 (0)