diff --git a/internal/lsp/client.go b/internal/lsp/client.go index c4d80d8af918a202b97d71d5d939338aa3cf1c77..7ba6cc23c6b12f3b54e285a998c67a669b4ff6b5 100644 --- a/internal/lsp/client.go +++ b/internal/lsp/client.go @@ -329,26 +329,7 @@ func (c *Client) HandlesFile(path string) bool { slog.Debug("File outside workspace", "name", c.name, "file", path, "workDir", c.workDir) return false } - - // If no file types are specified, handle all files (backward compatibility). - if len(c.fileTypes) == 0 { - return true - } - - kind := powernap.DetectLanguage(path) - name := strings.ToLower(filepath.Base(path)) - for _, filetype := range c.fileTypes { - suffix := strings.ToLower(filetype) - if !strings.HasPrefix(suffix, ".") { - suffix = "." + suffix - } - if strings.HasSuffix(name, suffix) || filetype == string(kind) { - slog.Debug("Handles file", "name", c.name, "file", name, "filetype", filetype, "kind", kind) - return true - } - } - slog.Debug("Doesn't handle file", "name", c.name, "file", name) - return false + return handlesFiletype(c.name, c.fileTypes, path) } // OpenFile opens a file in the LSP server. diff --git a/internal/lsp/manager.go b/internal/lsp/manager.go index b59819e0d64a592d2c5fd7d9e8c6c9ec8d2fed38..4b70205fc033b52db56a660e9b8f0166cd54bdc5 100644 --- a/internal/lsp/manager.go +++ b/internal/lsp/manager.go @@ -17,8 +17,7 @@ import ( "github.com/charmbracelet/crush/internal/csync" "github.com/charmbracelet/crush/internal/fsext" powernapconfig "github.com/charmbracelet/x/powernap/pkg/config" - "github.com/charmbracelet/x/powernap/pkg/lsp" - "github.com/charmbracelet/x/powernap/pkg/lsp/protocol" + powernap "github.com/charmbracelet/x/powernap/pkg/lsp" "github.com/sourcegraph/jsonrpc2" ) @@ -215,14 +214,25 @@ func resolveServerName(manager *powernapconfig.Manager, name string) string { return name } -func handlesFiletype(server *powernapconfig.ServerConfig, ext string, language protocol.LanguageKind) bool { - for _, ft := range server.FileTypes { - if protocol.LanguageKind(ft) == language || - ft == strings.TrimPrefix(ext, ".") || - "."+ft == ext { +func handlesFiletype(sname string, fileTypes []string, filePath string) bool { + if len(fileTypes) == 0 { + return true + } + + kind := powernap.DetectLanguage(filePath) + name := strings.ToLower(filepath.Base(filePath)) + for _, filetype := range fileTypes { + suffix := strings.ToLower(filetype) + if !strings.HasPrefix(suffix, ".") { + suffix = "." + suffix + } + if strings.HasSuffix(name, suffix) || filetype == string(kind) { + slog.Debug("Handles file", "name", sname, "file", name, "filetype", filetype, "kind", kind) return true } } + + slog.Debug("Doesn't handle file", "name", sname, "file", name) return false } @@ -241,9 +251,7 @@ func hasRootMarkers(dir string, markers []string) bool { } func handles(server *powernapconfig.ServerConfig, filePath, workDir string) bool { - language := lsp.DetectLanguage(filePath) - ext := filepath.Ext(filePath) - return handlesFiletype(server, ext, language) && + return handlesFiletype(server.Command, server.FileTypes, filePath) && hasRootMarkers(workDir, server.RootMarkers) }