@@ -34,6 +34,9 @@ type Client struct {
34 client *powernap.Client
34 client *powernap.Client
35 name string
35 name string
37+ // Working directory this LSP is scoped to.
37 // File types this LSP server handles (e.g., .go, .rs, .py)
40 // File types this LSP server handles (e.g., .go, .rs, .py)
38 fileTypes []string
41 fileTypes []string
@@ -133,6 +136,7 @@ func (c *Client) createPowernapClient() error {
135 rootURI := string(protocol.URIFromPath(workDir))
138 rootURI := string(protocol.URIFromPath(workDir))
137 command, err := c.resolver.ResolveValue(c.config.Command)
141 command, err := c.resolver.ResolveValue(c.config.Command)
138 if err != nil {
142 if err != nil {
@@ -305,9 +309,22 @@ type OpenFileInfo struct {
305 URI protocol.DocumentURI
309 URI protocol.DocumentURI
308−// HandlesFile checks if this LSP client handles the given file based on its extension.
312+// HandlesFile checks if this LSP client handles the given file based on its
313+// extension and whether it's within the working directory.
309func (c *Client) HandlesFile(path string) bool {
314func (c *Client) HandlesFile(path string) bool {
315+ // Check if file is within working directory.
316+ absPath, err := filepath.Abs(path)
318+ slog.Debug("cannot resolve path", "name", c.name, "file", path, "error", err)
321+ relPath, err := filepath.Rel(c.workDir, absPath)
322+ if err != nil || strings.HasPrefix(relPath, "..") {
323+ slog.Debug("file outside workspace", "name", c.name, "file", path, "workDir", c.workDir)
310− // If no file types are specified, handle all files (backward compatibility)
327+ // If no file types are specified, handle all files (backward compatibility).
311 if len(c.fileTypes) == 0 {
328 if len(c.fileTypes) == 0 {
312 return true
329 return true