Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 2941137

Browse files
committed
fix diagnostics for deleted files
1 parent b3c0285 commit 2941137

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

internal/lsp/client.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func (c *Client) openKeyConfigFiles(ctx context.Context) {
389389
filepath.Join(workDir, "package.json"),
390390
filepath.Join(workDir, "jsconfig.json"),
391391
}
392-
392+
393393
// Also find and open a few TypeScript files to help the server initialize
394394
c.openTypeScriptFiles(ctx, workDir)
395395
case ServerTypeGo:
@@ -547,12 +547,12 @@ func (c *Client) openTypeScriptFiles(ctx context.Context, workDir string) {
547547
// shouldSkipDir returns true if the directory should be skipped during file search
548548
func shouldSkipDir(path string) bool {
549549
dirName := filepath.Base(path)
550-
550+
551551
// Skip hidden directories
552552
if strings.HasPrefix(dirName, ".") {
553553
return true
554554
}
555-
555+
556556
// Skip common directories that won't contain relevant source files
557557
skipDirs := map[string]bool{
558558
"node_modules": true,
@@ -562,7 +562,7 @@ func shouldSkipDir(path string) bool {
562562
"vendor": true,
563563
"target": true,
564564
}
565-
565+
566566
return skipDirs[dirName]
567567
}
568568

@@ -776,3 +776,10 @@ func (c *Client) GetDiagnosticsForFile(ctx context.Context, filepath string) ([]
776776

777777
return diagnostics, nil
778778
}
779+
780+
// ClearDiagnosticsForURI removes diagnostics for a specific URI from the cache
781+
func (c *Client) ClearDiagnosticsForURI(uri protocol.DocumentUri) {
782+
c.diagnosticsMu.Lock()
783+
defer c.diagnosticsMu.Unlock()
784+
delete(c.diagnostics, uri)
785+
}

internal/lsp/watcher/watcher.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,9 @@ func (w *WorkspaceWatcher) debounceHandleFileEvent(ctx context.Context, uri stri
643643
func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, changeType protocol.FileChangeType) {
644644
// If the file is open and it's a change event, use didChange notification
645645
filePath := uri[7:] // Remove "file://" prefix
646-
if changeType == protocol.FileChangeType(protocol.Changed) && w.client.IsFileOpen(filePath) {
646+
if changeType == protocol.FileChangeType(protocol.Deleted) {
647+
w.client.ClearDiagnosticsForURI(protocol.DocumentUri(uri))
648+
} else if changeType == protocol.FileChangeType(protocol.Changed) && w.client.IsFileOpen(filePath) {
647649
err := w.client.NotifyChange(ctx, filePath)
648650
if err != nil {
649651
logging.Error("Error notifying change", "error", err)

0 commit comments

Comments
 (0)