Detailed changes
@@ -435,7 +435,7 @@ func (c *coordinator) buildTools(ctx context.Context, agent config.Agent) ([]fan
tools.NewWriteTool(c.lspClients, c.permissions, c.history, c.filetracker, c.cfg.WorkingDir()),
)
- if len(c.cfg.LSP) > 0 {
+ if c.lspClients.Len() > 0 {
allTools = append(allTools, tools.NewDiagnosticsTool(c.lspClients), tools.NewReferencesTool(c.lspClients), tools.NewLSPRestartTool(c.lspClients))
}
@@ -135,6 +135,7 @@ func Close() error {
// Initialize initializes MCP clients based on the provided configuration.
func Initialize(ctx context.Context, permissions permission.Service, cfg *config.Config) {
+ slog.Info("Initializing MCP clients")
var wg sync.WaitGroup
// Initialize states for all configured MCPs
for name, m := range cfg.MCP {
@@ -109,10 +109,7 @@ func New(ctx context.Context, conn *sql.DB, cfg *config.Config) (*App, error) {
// Check for updates in the background.
go app.checkForUpdates(ctx)
- go func() {
- slog.Info("Initializing MCP clients")
- mcp.Initialize(ctx, app.Permissions, cfg)
- }()
+ go mcp.Initialize(ctx, app.Permissions, cfg)
// cleanup database upon app shutdown
app.cleanupFuncs = append(app.cleanupFuncs, conn.Close, mcp.Close)
@@ -5,6 +5,7 @@ import (
"log/slog"
"os/exec"
"slices"
+ "sync"
"time"
"github.com/charmbracelet/crush/internal/config"
@@ -58,16 +59,25 @@ func (app *App) initLSPClients(ctx context.Context) {
updateLSPState(name, lsp.StateDisabled, nil, nil, 0)
}
}
+
+ var wg sync.WaitGroup
for name, server := range filtered {
if app.config.Options.AutoLSP != nil && !*app.config.Options.AutoLSP && !slices.Contains(userConfiguredLSPs, name) {
slog.Debug("Ignoring non user-define LSP client due to AutoLSP being disabled", "name", name)
continue
}
- go app.createAndStartLSPClient(
- ctx, name,
- toOurConfig(server),
- slices.Contains(userConfiguredLSPs, name),
- )
+ wg.Go(func() {
+ app.createAndStartLSPClient(
+ ctx, name,
+ toOurConfig(server),
+ slices.Contains(userConfiguredLSPs, name),
+ )
+ })
+ }
+ wg.Wait()
+
+ if err := app.AgentCoordinator.UpdateModels(ctx); err != nil {
+ slog.Error("Failed to refresh tools after LSP startup", "error", err)
}
}