Skip to content

[LSP] Working directory should not affect functionality #26182

Description

@rchl

Summary

A user of LSP-ruff (Sublime Text package integrating ruff) reported an issue about ruff/ty behaving differently depending on which working directory is being set when starting the server.

In the LSP world the working directory should in theory not matter or affect functionality since this is not really relevant there and the LSP spec doesn't specify anything related to that. The closest relevant thing is probably WorkspaceFolders sent during initialization but in this particular case (when opening individual files), those are not set.

The user's report says:

If open file (eg. double click in file explorer or Open file from ST menu) - servers starts in installation dir of ST:
LSP: starting ['C:\Users\...\LSP-ty\v0.0.50\ty.exe', 'server'] in C:\Program Files\Sublime Text
The server is expected to run in the directory of the file being edited for full functionality.
If the server is started in the wrong directory, not all functions will work (eg. rename or completeFunctionParentheses).

I'm thinking that, in LSP mode, it's the server's responsibility to figure out the best "working directory" for a given file. If no workspace folders are provided then maybe it should infer it from the open file. But note that the user might open another file from a completely different location next...

If that is not feasible, maybe server could introduce some custom logic for handling files outside workspace folder. I think rust-analyzer does something similar where it passes opened files through a dedicated initialization option. Not a big fan of that solution but if there is no other option...

Version

ruff 0.15.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    serverRelated to the LSP server

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions