feat: add virtual workspace support via registerUriTranslator API#1008
Open
jianyexi wants to merge 1 commit into
Open
feat: add virtual workspace support via registerUriTranslator API#1008jianyexi wants to merge 1 commit into
jianyexi wants to merge 1 commit into
Conversation
Add support for virtual workspaces by exporting a registerUriTranslator() API that VFS providers (e.g., vscode-trident) can use to register a URI translator. This follows the same pattern as Pylance's registerUriTranslator. The VFS provider owns the disk cache and implements three methods: - initialize(workspaceFolders): async setup — sync files to cache, populate translation maps. Called once before the server starts. - translateToDisk(uri): synchronous — returns cached file:// URI for a virtual URI - translateToVirtual(uri): synchronous — returns virtual URI for a file:// URI On registration, the Ruff language server restarts with: - uriConverters that translate all URIs via the translator - Server cwd set to the translated workspace root - All initializationOptions settings translated to local paths - Middleware for config file change notifications (didChangeWatchedFiles) - Commands (autofix, format, organize imports) use code2ProtocolConverter Key design decisions: - translateToDisk/translateToVirtual are synchronous (all async work in initialize) - Server defers startup in virtual workspaces until translator registers - Uses toString(true) for file URIs to avoid percent-encoding drive letters Changed files: - New: src/common/uriTranslator.ts — interface + API + registration logic - src/extension.ts — activate() returns API, deferred VFS startup - src/common/server.ts — translator integration, cwd/settings translation - src/common/commands.ts — use code2ProtocolConverter for command URIs - src/common/settings.ts — scheme-aware variable resolution - src/common/utilities.ts — virtual workspace getProjectRoot() fix - package.json — virtualWorkspaces.supported: true Ref: astral-sh#1007 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1756e38 to
c77b9dc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add virtual workspace support via a
registerUriTranslatorAPI, following the same pattern Pylance uses.VFS providers (e.g., Microsoft Fabric Data Engineering VS Code extension) implement a
RuffUriTranslatorand register it with Ruff. The translator handles bidirectional URI translation between virtual workspace URIs and local disk cache URIs, enabling Ruff's linting, formatting, and auto-fix to work on virtual files.Closes #1007
Design
The VFS provider owns the disk cache. Ruff exports the API.
RuffUriTranslator interface
initialize(workspaceFolders)— async, called once before server start. VFS provider syncs config files, creates directory structures, pre-populates translation caches.translateToDisk(uri)— synchronous, returnsfile://URI for a virtual URI.translateToVirtual(uri)— synchronous, returns virtual URI for afile://URI.How it works
runServer()is calledtranslator.initialize()prepares the local cacheuriConverterson the LanguageClient translate all URIs via the translatorcwd,workspace) are translated before sending to the serverworkspace/configurationmiddleware translates dynamically requested settingsworkspace/didChangeWatchedFilesnotificationsChanges
src/common/uriTranslator.tssrc/common/vfsSupport.tssrc/common/server.tssrc/extension.tssrc/common/commands.tscode2ProtocolConverterfor command URIssrc/common/settings.tssrc/common/utilities.tsgetProjectRoot()fixpackage.jsonvirtualWorkspaces.supported: "limited".vscode-test.jssrc/test/testVfsExtension/src/test/vfs.e2e.test.tsTest Plan
5 E2E tests run in a pure virtual workspace (
testvfs:/project):Existing tests (Unit, E2E) are unaffected — no existing test files were modified.
Context
I work on the Microsoft Fabric Data Engineering VS Code extension which uses a custom VFS. We already register a URI translator with Pylance for Python IntelliSense. This PR adds the same integration pattern for Ruff.