on main help sign in
fix diagnostics for deleted files
commit294113741641cb7f6fe5c9aa114328b5bf8814ec authorKujtim Hoxha <kujtimii.h@gmail.com> dateMon 28 Apr 2025, 19:37 (2 years ago) parentb3c0285
2 files changed+14−5
internal/lsp/client.go+11−4 internal/lsp/watcher/watcher.go+3−1
internal/lsp/client.go+11−4
@@ -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
548548func 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+3−1
@@ -643,7 +643,9 @@ func (w *WorkspaceWatcher) debounceHandleFileEvent(ctx context.Context, uri stri
643643func (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)