on main help sign in
refactor(lsp): use same handle file in client and manager (#2168)

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

commit074917b7418c3541458963b3c720fa1546745690 authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateMon 9 Feb 2026, 09:35 (8 months ago) parent04d05e1
2 files changed+19−30
internal/lsp/client.go+1−20 internal/lsp/manager.go+18−10
internal/lsp/client.go+1−20
@@ -329,26 +329,7 @@ func (c *Client) HandlesFile(path string) bool {
329329 slog.Debug("File outside workspace", "name", c.name, "file", path, "workDir", c.workDir)
330330 return false
331331 }
332−
333− // If no file types are specified, handle all files (backward compatibility).
334− if len(c.fileTypes) == 0 {
335− return true
336− }
337−
338− kind := powernap.DetectLanguage(path)
339− name := strings.ToLower(filepath.Base(path))
340− for _, filetype := range c.fileTypes {
341− suffix := strings.ToLower(filetype)
342− if !strings.HasPrefix(suffix, ".") {
343− suffix = "." + suffix
344− }
345− if strings.HasSuffix(name, suffix) || filetype == string(kind) {
346− slog.Debug("Handles file", "name", c.name, "file", name, "filetype", filetype, "kind", kind)
347− return true
348− }
349− }
350− slog.Debug("Doesn't handle file", "name", c.name, "file", name)
351− return false
332+ return handlesFiletype(c.name, c.fileTypes, path)
352333}
353334
354335// OpenFile opens a file in the LSP server.
internal/lsp/manager.go+18−10
@@ -17,8 +17,7 @@ import (
1717 "github.com/charmbracelet/crush/internal/csync"
1818 "github.com/charmbracelet/crush/internal/fsext"
1919 powernapconfig "github.com/charmbracelet/x/powernap/pkg/config"
20− "github.com/charmbracelet/x/powernap/pkg/lsp"
21− "github.com/charmbracelet/x/powernap/pkg/lsp/protocol"
20+ powernap "github.com/charmbracelet/x/powernap/pkg/lsp"
2221 "github.com/sourcegraph/jsonrpc2"
2322)
2423
@@ -215,14 +214,25 @@ func resolveServerName(manager *powernapconfig.Manager, name string) string {
215214 return name
216215}
217216
218−func handlesFiletype(server *powernapconfig.ServerConfig, ext string, language protocol.LanguageKind) bool {
219− for _, ft := range server.FileTypes {
220− if protocol.LanguageKind(ft) == language ||
221− ft == strings.TrimPrefix(ext, ".") ||
222− "."+ft == ext {
217+func handlesFiletype(sname string, fileTypes []string, filePath string) bool {
218+ if len(fileTypes) == 0 {
219+ return true
220+ }
221+
222+ kind := powernap.DetectLanguage(filePath)
223+ name := strings.ToLower(filepath.Base(filePath))
224+ for _, filetype := range fileTypes {
225+ suffix := strings.ToLower(filetype)
226+ if !strings.HasPrefix(suffix, ".") {
227+ suffix = "." + suffix
228+ }
229+ if strings.HasSuffix(name, suffix) || filetype == string(kind) {
230+ slog.Debug("Handles file", "name", sname, "file", name, "filetype", filetype, "kind", kind)
223231 return true
224232 }
225233 }
234+
235+ slog.Debug("Doesn't handle file", "name", sname, "file", name)
226236 return false
227237}
228238
@@ -241,9 +251,7 @@ func hasRootMarkers(dir string, markers []string) bool {
241251}
242252
243253func handles(server *powernapconfig.ServerConfig, filePath, workDir string) bool {
244− language := lsp.DetectLanguage(filePath)
245− ext := filepath.Ext(filePath)
246− return handlesFiletype(server, ext, language) &&
254+ return handlesFiletype(server.Command, server.FileTypes, filePath) &&
247255 hasRootMarkers(workDir, server.RootMarkers)
248256}
249257