Bläddra i källkod

fix: diagnostics tool init

adamdottv 9 månader sedan
förälder
incheckning
406ccf9b87
2 ändrade filer med 7 tillägg och 4 borttagningar
  1. 5 3
      internal/llm/agent/tools.go
  2. 2 1
      internal/llm/tools/diagnostics.go

+ 5 - 3
internal/llm/agent/tools.go

@@ -20,9 +20,11 @@ func CoderAgentTools(
 ) []tools.BaseTool {
 	ctx := context.Background()
 	otherTools := GetMcpTools(ctx, permissions)
-	if len(lspClients) > 0 {
-		otherTools = append(otherTools, tools.NewDiagnosticsTool(lspClients))
-	}
+
+	// Always add the Diagnostics tool even if lspClients is empty
+	// The tool will handle the case when no clients are available
+	otherTools = append(otherTools, tools.NewDiagnosticsTool(lspClients))
+
 	return append(
 		[]tools.BaseTool{
 			tools.NewBashTool(permissions),

+ 2 - 1
internal/llm/tools/diagnostics.go

@@ -74,7 +74,8 @@ func (b *diagnosticsTool) Run(ctx context.Context, call ToolCall) (ToolResponse,
 	lsps := b.lspClients
 
 	if len(lsps) == 0 {
-		return NewTextErrorResponse("no LSP clients available"), nil
+		// Return a more helpful message when LSP clients aren't ready yet
+		return NewTextResponse("\n<diagnostic_summary>\nLSP clients are still initializing. Diagnostics will be available once they're ready.\n</diagnostic_summary>\n"), nil
 	}
 
 	if params.FilePath != "" {