on main help sign in
fix diagnostics for deleted files
2941137Kujtim Hoxha
internal/lsp/client.go+11−4
@@ -389,7 +389,7 @@ func (c *Client) openKeyConfigFiles(ctx context.Context) {
389 filepath.Join(workDir, "package.json"),
389 filepath.Join(workDir, "package.json"),
390 filepath.Join(workDir, "jsconfig.json"),
390 filepath.Join(workDir, "jsconfig.json"),
391 }
391 }
392−
392+
393 // Also find and open a few TypeScript files to help the server initialize
393 // Also find and open a few TypeScript files to help the server initialize
394 c.openTypeScriptFiles(ctx, workDir)
394 c.openTypeScriptFiles(ctx, workDir)
395 case ServerTypeGo:
395 case ServerTypeGo:
@@ -547,12 +547,12 @@ func (c *Client) openTypeScriptFiles(ctx context.Context, workDir string) {
547// shouldSkipDir returns true if the directory should be skipped during file search
547// shouldSkipDir returns true if the directory should be skipped during file search
548func shouldSkipDir(path string) bool {
548func shouldSkipDir(path string) bool {
549 dirName := filepath.Base(path)
549 dirName := filepath.Base(path)
550−
550+
551 // Skip hidden directories
551 // Skip hidden directories
552 if strings.HasPrefix(dirName, ".") {
552 if strings.HasPrefix(dirName, ".") {
553 return true
553 return true
554 }
554 }
555−
555+
556 // Skip common directories that won't contain relevant source files
556 // Skip common directories that won't contain relevant source files
557 skipDirs := map[string]bool{
557 skipDirs := map[string]bool{
558 "node_modules": true,
558 "node_modules": true,
@@ -562,7 +562,7 @@ func shouldSkipDir(path string) bool {
562 "vendor": true,
562 "vendor": true,
563 "target": true,
563 "target": true,
564 }
564 }
565−
565+
566 return skipDirs[dirName]
566 return skipDirs[dirName]
567}
567}
568
568
@@ -776,3 +776,10 @@ func (c *Client) GetDiagnosticsForFile(ctx context.Context, filepath string) ([]
776
776
777 return diagnostics, nil
777 return diagnostics, nil
778}
778}
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
643func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, changeType protocol.FileChangeType) {
643func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, changeType protocol.FileChangeType) {
644 // If the file is open and it's a change event, use didChange notification
644 // If the file is open and it's a change event, use didChange notification
645 filePath := uri[7:] // Remove "file://" prefix
645 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) {
647 err := w.client.NotifyChange(ctx, filePath)
649 err := w.client.NotifyChange(ctx, filePath)
648 if err != nil {
650 if err != nil {
649 logging.Error("Error notifying change", "error", err)
651 logging.Error("Error notifying change", "error", err)