-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(web,paths,server): WSL2-aware Open in IDE link #1504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
blankse
wants to merge
2
commits into
coleam00:dev
Choose a base branch
from
blankse:fix/1502-wsl-vscode-uri
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { describe, test, expect } from 'bun:test'; | ||
| import { ideUri } from './ide-uri'; | ||
|
|
||
| describe('ideUri', () => { | ||
| describe('default (non-WSL) form', () => { | ||
| test('emits vscode://file/<path> when env is undefined', () => { | ||
| expect(ideUri('/home/user/project')).toBe('vscode://file//home/user/project'); | ||
| }); | ||
|
|
||
| test('emits vscode://file/<path> when env.is_wsl is false', () => { | ||
| expect(ideUri('/home/user/project', { is_wsl: false })).toBe( | ||
| 'vscode://file//home/user/project' | ||
| ); | ||
| }); | ||
|
|
||
| test('falls back when is_wsl is true but wsl_distro is missing', () => { | ||
| // Without a distro name we can't construct the WSL form — better to emit | ||
| // the plain URI than to guess a distro that may not exist locally. | ||
| expect(ideUri('/home/user/project', { is_wsl: true })).toBe( | ||
| 'vscode://file//home/user/project' | ||
| ); | ||
| }); | ||
|
|
||
| test('normalises Windows-style backslashes', () => { | ||
| expect(ideUri('C:\\Users\\me\\project')).toBe('vscode://file/C:/Users/me/project'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('WSL2 form', () => { | ||
| test('emits vscode://vscode-remote/wsl+<distro>/<path>', () => { | ||
| expect(ideUri('/home/user/project', { is_wsl: true, wsl_distro: 'Ubuntu' })).toBe( | ||
| 'vscode://vscode-remote/wsl+Ubuntu/home/user/project' | ||
| ); | ||
| }); | ||
|
|
||
| test('preserves leading slash when path already absolute', () => { | ||
| const uri = ideUri('/home/user/project', { is_wsl: true, wsl_distro: 'Ubuntu' }); | ||
| expect(uri).toContain('/wsl+Ubuntu/home/user/project'); | ||
| expect(uri).not.toContain('/wsl+Ubuntu//home'); | ||
| }); | ||
|
|
||
| test('adds leading slash when path is relative-ish (defensive)', () => { | ||
| const uri = ideUri('home/user/project', { is_wsl: true, wsl_distro: 'Ubuntu' }); | ||
| expect(uri).toBe('vscode://vscode-remote/wsl+Ubuntu/home/user/project'); | ||
| }); | ||
|
|
||
| test('encodes distro names that contain non-URL-safe characters', () => { | ||
| // Hypothetical: WSL distro names with spaces / special chars | ||
| const uri = ideUri('/home/user/x', { is_wsl: true, wsl_distro: 'My Distro' }); | ||
| expect(uri).toBe('vscode://vscode-remote/wsl+My%20Distro/home/user/x'); | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * Build a `vscode://...` URI for opening a server-side absolute path in the | ||
| * user's locally-installed VS Code. | ||
| * | ||
| * Two flavours, picked based on where the Archon server is running: | ||
| * | ||
| * - **default**: `vscode://file/<path>` — works when the path is reachable | ||
| * from the same OS as the browser (typical local dev or remote SSH proxied | ||
| * to localhost). | ||
| * - **WSL2**: `vscode://vscode-remote/wsl+<distro>/<path>` — required when | ||
| * Archon runs inside a WSL2 distro and the browser is on the Windows host. | ||
| * Without this prefix Windows VS Code receives the Linux path verbatim and | ||
| * tries to resolve it on the Windows filesystem, which silently fails. | ||
| * | ||
| * @param path Absolute path on the server, as reported by the API. Backslashes | ||
| * are normalised to forward slashes. | ||
| * @param env Server-environment hints from `/api/health` — `is_wsl` plus | ||
| * `wsl_distro` when known. Omit (or pass `is_wsl: false`) for | ||
| * the plain `vscode://file/...` form. | ||
| */ | ||
| export function ideUri(path: string, env?: { is_wsl?: boolean; wsl_distro?: string }): string { | ||
| const normalised = path.replace(/\\/g, '/'); | ||
|
|
||
| if (env?.is_wsl && env.wsl_distro) { | ||
| // vscode-remote URIs need a leading slash before the absolute Linux path | ||
| const withLeadingSlash = normalised.startsWith('/') ? normalised : `/${normalised}`; | ||
| return `vscode://vscode-remote/wsl+${encodeURIComponent(env.wsl_distro)}${withLeadingSlash}`; | ||
| } | ||
|
|
||
| return `vscode://file/${normalised}`; | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.