Skip to content

Support multi-root Pydance workspaces#38

Open
ankitchouhan1020 wants to merge 5 commits into
ram-nadella:mainfrom
ankitchouhan1020:pydance-multi-root-workspace-indexing
Open

Support multi-root Pydance workspaces#38
ankitchouhan1020 wants to merge 5 commits into
ram-nadella:mainfrom
ankitchouhan1020:pydance-multi-root-workspace-indexing

Conversation

@ankitchouhan1020

@ankitchouhan1020 ankitchouhan1020 commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Pydance is a VS Code extension backed by the pylight LSP server. Its main feature is workspace-wide Python symbol search: VS Code sends workspace/symbol requests, and pylight answers from an in-memory index built at server startup and kept fresh by file watchers.

Before this change, Pydance only indexed the single legacy rootUri from LSP initialization. In a VS Code multi-root workspace like:

my-workspace.code-workspace
├── repo-a/
│   └── a.py
└── repo-b/
    └── b.py

only the top/root repo was indexed. Symbols from the other workspace folders were missing from Go to Symbol in Workspace / workspace/symbol results.

After this change, pylight reads InitializeParams.workspaceFolders and indexes every folder VS Code sends. It still falls back to rootUri for normal single-folder workspaces, so existing single-repo behavior stays unchanged.

Behavior changes

  • Multi-root VS Code workspaces now index all workspace folders, not just the first/root folder.
  • The file watcher subscribes to every workspace folder so edits in any repo update the index.
  • Ignore rules remain per repo: each workspace folder gets its own IgnoreFilter, so each repo's .gitignore and default Python ignores apply relative to that repo.
  • Bulk reindex rebuilds one shared symbol index from all workspace folders.
  • Added Pydance: Restart Server so local testing can force a fresh LSP process and reindex without reloading the whole VS Code window.
  • Bumped Pydance/Pylight to 0.3.1 for the local extension update.

Example

Given a workspace with two folders:

{
  "workspaceFolders": [
    { "uri": "file:///path/repo-a", "name": "repo-a" },
    { "uri": "file:///path/repo-b", "name": "repo-b" }
  ]
}

Pydance now:

  1. indexes /path/repo-a
  2. indexes /path/repo-b
  3. watches both folders recursively
  4. returns symbols from both repos for workspace/symbol

If VS Code only sends the legacy single-root shape:

{ "rootUri": "file:///path/repo-a" }

Pydance keeps the old behavior and indexes only /path/repo-a.

Extension test coverage

A new VS Code integration runner opens a real multi-root .code-workspace fixture while the existing single-root integration runner remains unchanged:

src/testWorkspaces/multi-root.code-workspace
├── ../testFixture/test.py
└── ../testFixtureSecond/second.py

That exercises the full headless VS Code path in CI:

  • VS Code launches with a multi-root workspace file.
  • The Pydance extension activates normally.
  • The real pylight server indexes both workspace folders.
  • vscode.executeWorkspaceSymbolProvider finds symbols from the second workspace folder.
  • Pydance: Restart Server is executed and verified to reindex symbols after restart.

The test runner also uses a short /tmp user-data-dir to avoid macOS IPC socket path-length failures when the repo path is long.

Implementation notes

  • LspServer now stores workspace_roots: Vec<PathBuf> instead of a single optional root.
  • workspace_roots_from_initialize_params prefers workspaceFolders and falls back to rootUri.
  • IndexUpdater::new_multi carries multiple roots and matching ignore filters.
  • FileWatcher no longer owns a single-root ignore filter; it delegates watch decisions to the event handler, which has the multi-root context.
  • Pydance: Restart Server stops the current LanguageClient, recreates it with the existing server/client options, reapplies trace config, and starts it again.

Test plan

  • cd pylight && cargo test --quiet
  • cd pydance && npm run compile
  • cd pydance && npm run compile:tests
  • cd pydance && npm run test:integration
  • cd pydance && npm run test:integration:multi-root
  • Installed locally into VS Code as toughtype.pydance-0.3.1
  • Verified multi-root workspace indexing works locally
  • Verified Pydance: Restart Server is available and restarts/reindexes locally

Not included

Dynamic workspace-folder add/remove handling after the LSP server has started is not included. Restarting the server covers that case for now; we can add workspace/didChangeWorkspaceFolders support if that becomes important.

Comment thread pydance/src/test/suite/extension.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant