ruff
5e943d35 - [ty] Ask the LSP client to watch all project search paths

Commit
26 days ago
[ty] Ask the LSP client to watch all project search paths This change rejiggers how we register globs for file watching with the LSP client. Previously, we registered a few globs like `**/*.py`, `**/pyproject.toml` and more. There were two problems with this approach. Firstly, it only watches files within the project root. Search paths may be outside the project root. Such as virtualenv directory. Secondly, there is variation on how tools interact with virtual environments. In the case of uv, depending on its link mode, we might not get any file change notifications after running `uv add foo` or `uv remove foo`. To remedy this, we instead just list for file change notifications on all files for all search paths. This simplifies the globs we use, but does potentially increase the number of notifications we'll get. However, given the somewhat simplistic interface supported by the LSP protocol, I think this is unavoidable (unless we used our own file watcher, which has its own considerably downsides). Moreover, this is seemingly consistent with how `ty check --watch` works. This also required moving file watcher registration to *after* workspaces are initialized, or else we don't know what the right search paths are. This change is in service of #19883, which in order for cache invalidation to work right, the LSP client needs to send notifications whenever a dependency is added or removed. This change should make that possible. I tried this patch with #19883 in addition to my work to activate Salsa caching, and everything seems to work as I'd expect. That is, completions no longer show stale results after a dependency is added or removed.
Author
Committer
Parents
Loading