mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 18:54:21 +01:00
fix diagnostics for deleted files
This commit is contained in:
@@ -389,7 +389,7 @@ func (c *Client) openKeyConfigFiles(ctx context.Context) {
|
|||||||
filepath.Join(workDir, "package.json"),
|
filepath.Join(workDir, "package.json"),
|
||||||
filepath.Join(workDir, "jsconfig.json"),
|
filepath.Join(workDir, "jsconfig.json"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also find and open a few TypeScript files to help the server initialize
|
// Also find and open a few TypeScript files to help the server initialize
|
||||||
c.openTypeScriptFiles(ctx, workDir)
|
c.openTypeScriptFiles(ctx, workDir)
|
||||||
case ServerTypeGo:
|
case ServerTypeGo:
|
||||||
@@ -547,12 +547,12 @@ func (c *Client) openTypeScriptFiles(ctx context.Context, workDir string) {
|
|||||||
// shouldSkipDir returns true if the directory should be skipped during file search
|
// shouldSkipDir returns true if the directory should be skipped during file search
|
||||||
func shouldSkipDir(path string) bool {
|
func shouldSkipDir(path string) bool {
|
||||||
dirName := filepath.Base(path)
|
dirName := filepath.Base(path)
|
||||||
|
|
||||||
// Skip hidden directories
|
// Skip hidden directories
|
||||||
if strings.HasPrefix(dirName, ".") {
|
if strings.HasPrefix(dirName, ".") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip common directories that won't contain relevant source files
|
// Skip common directories that won't contain relevant source files
|
||||||
skipDirs := map[string]bool{
|
skipDirs := map[string]bool{
|
||||||
"node_modules": true,
|
"node_modules": true,
|
||||||
@@ -562,7 +562,7 @@ func shouldSkipDir(path string) bool {
|
|||||||
"vendor": true,
|
"vendor": true,
|
||||||
"target": true,
|
"target": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
return skipDirs[dirName]
|
return skipDirs[dirName]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user