fix diagnostics for deleted files

This commit is contained in:
Kujtim Hoxha
2025-04-28 19:37:42 +02:00
parent b3c0285db3
commit 2941137416
2 changed files with 14 additions and 5 deletions

View File

@@ -776,3 +776,10 @@ func (c *Client) GetDiagnosticsForFile(ctx context.Context, filepath string) ([]
return diagnostics, nil return diagnostics, nil
} }
// ClearDiagnosticsForURI removes diagnostics for a specific URI from the cache
func (c *Client) ClearDiagnosticsForURI(uri protocol.DocumentUri) {
c.diagnosticsMu.Lock()
defer c.diagnosticsMu.Unlock()
delete(c.diagnostics, uri)
}

View File

@@ -643,7 +643,9 @@ func (w *WorkspaceWatcher) debounceHandleFileEvent(ctx context.Context, uri stri
func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, changeType protocol.FileChangeType) { func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, changeType protocol.FileChangeType) {
// If the file is open and it's a change event, use didChange notification // If the file is open and it's a change event, use didChange notification
filePath := uri[7:] // Remove "file://" prefix filePath := uri[7:] // Remove "file://" prefix
if changeType == protocol.FileChangeType(protocol.Changed) && w.client.IsFileOpen(filePath) { if changeType == protocol.FileChangeType(protocol.Deleted) {
w.client.ClearDiagnosticsForURI(protocol.DocumentUri(uri))
} else if changeType == protocol.FileChangeType(protocol.Changed) && w.client.IsFileOpen(filePath) {
err := w.client.NotifyChange(ctx, filePath) err := w.client.NotifyChange(ctx, filePath)
if err != nil { if err != nil {
logging.Error("Error notifying change", "error", err) logging.Error("Error notifying change", "error", err)