@@ -53,6 +53,7 @@ func (b *diagnosticsTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
54 if params.FilePath != "" {
54 if params.FilePath != "" {
55 notifyLspOpenFile(ctx, params.FilePath, lsps)
55 notifyLspOpenFile(ctx, params.FilePath, lsps)
56+ waitForLspDiagnostics(ctx, params.FilePath, lsps)
58 output := appendDiagnostics(params.FilePath, lsps)
59 output := appendDiagnostics(params.FilePath, lsps)
@@ -61,6 +62,22 @@ func (b *diagnosticsTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
63func notifyLspOpenFile(ctx context.Context, filePath string, lsps map[string]*lsp.Client) {
64func notifyLspOpenFile(ctx context.Context, filePath string, lsps map[string]*lsp.Client) {
65+ for _, client := range lsps {
67+ err := client.OpenFile(ctx, filePath)
69+ // If there's an error opening the file, continue to the next client
75+// waitForLspDiagnostics opens a file in LSP clients and waits for diagnostics to be published
76+func waitForLspDiagnostics(ctx context.Context, filePath string, lsps map[string]*lsp.Client) {
64 // Create a channel to receive diagnostic notifications
81 // Create a channel to receive diagnostic notifications
65 diagChan := make(chan struct{}, 1)
82 diagChan := make(chan struct{}, 1)
@@ -92,11 +109,18 @@ func notifyLspOpenFile(ctx context.Context, filePath string, lsps map[string]*ls
92 // Register our temporary handler
109 // Register our temporary handler
93 client.RegisterNotificationHandler("textDocument/publishDiagnostics", handler)
110 client.RegisterNotificationHandler("textDocument/publishDiagnostics", handler)
112+ // Notify change if the file is already open
113+ if client.IsFileOpen(filePath) {
114+ err := client.NotifyChange(ctx, filePath)
95− // Open the file
119+ // Open the file if it's not already open
96− err := client.OpenFile(ctx, filePath)
120+ err := client.OpenFile(ctx, filePath)
97− if err != nil {
121+ if err != nil {
98− // If there's an error opening the file, continue to the next client
99− continue
122+ continue
@@ -104,7 +128,7 @@ func notifyLspOpenFile(ctx context.Context, filePath string, lsps map[string]*ls
105 case <-diagChan:
129 case <-diagChan:
106 // Diagnostics received
130 // Diagnostics received
107− case <-time.After(10 * time.Second):
131+ case <-time.After(5 * time.Second):
108 // Timeout after 5 seconds - this is a fallback in case no diagnostics are published
132 // Timeout after 5 seconds - this is a fallback in case no diagnostics are published
109 case <-ctx.Done():
133 case <-ctx.Done():
110 // Context cancelled
134 // Context cancelled