File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -223,13 +223,16 @@ export const OpenInPicker = memo(function OpenInPicker({
223223 environmentId,
224224 keybindings,
225225 openInCwd,
226+ openInLine,
226227 presentation = "toolbar" ,
227228 compact = false ,
228229 enableShortcut = true ,
229230} : {
230231 environmentId : EnvironmentId ;
231232 keybindings : ResolvedKeybindingsConfig ;
232233 openInCwd : string | null ;
234+ /** Set when `openInCwd` is a file, so remote editor links open the file instead of a folder. */
235+ openInLine ?: number ;
233236 presentation ?: "toolbar" | "menu" ;
234237 compact ?: boolean ;
235238 enableShortcut ?: boolean ;
@@ -278,6 +281,7 @@ export const OpenInPicker = memo(function OpenInPicker({
278281 host : remote . host . host ,
279282 absolutePath : openInCwd ,
280283 authority : remote . host . kind === "wsl" ? "wsl" : "ssh-remote" ,
284+ ...( openInLine === undefined ? { } : { line : openInLine } ) ,
281285 } ) ;
282286 if ( url === undefined ) return ;
283287 // Only record hint-seen/preferred when the shell actually accepted
@@ -304,6 +308,7 @@ export const OpenInPicker = memo(function OpenInPicker({
304308 markRemoteHintSeen ,
305309 openInCwd ,
306310 openInEditorMutation ,
311+ openInLine ,
307312 preferredEditor ,
308313 remote ,
309314 setPreferredEditor ,
Original file line number Diff line number Diff line change @@ -1117,6 +1117,7 @@ export default function FilePreviewPanel({
11171117 environmentId = { environmentId }
11181118 keybindings = { keybindings }
11191119 openInCwd = { absolutePath }
1120+ openInLine = { revealLine ?? 1 }
11201121 compact
11211122 enableShortcut = { false }
11221123 />
Original file line number Diff line number Diff line change @@ -129,6 +129,18 @@ describe("buildRemoteOpenUrl", () => {
129129 ) . toBe ( "vscode://vscode-remote/ssh-remote+sol.tail1234.ts.net/home/theo/code/my%20repo" ) ;
130130 } ) ;
131131
132+ it ( "ends file links with the line so VS Code opens a file, not a folder" , ( ) => {
133+ expect (
134+ buildRemoteOpenUrl ( {
135+ editor : "vscode" ,
136+ host : "Debian" ,
137+ absolutePath : "/home/luca/code/t3code/apps/desktop/src/main.ts" ,
138+ authority : "wsl" ,
139+ line : 12 ,
140+ } ) ,
141+ ) . toBe ( "vscode://vscode-remote/wsl+Debian/home/luca/code/t3code/apps/desktop/src/main.ts:12" ) ;
142+ } ) ;
143+
132144 it ( "uses the fork's scheme" , ( ) => {
133145 expect ( buildRemoteOpenUrl ( { editor : "cursor" , host : "sol" , absolutePath : "/tmp/x" } ) ) . toBe (
134146 "cursor://vscode-remote/ssh-remote+sol/tmp/x" ,
Original file line number Diff line number Diff line change @@ -119,12 +119,16 @@ export const supportsRemoteOpenAuthority = (
119119 * the editor's Remote WSL integration. Zed takes `zed://ssh/<host><path>`
120120 * and has no WSL form. Returns undefined for editors without deep-link support
121121 * for the authority.
122+ *
123+ * VS Code opens a `vscode-remote` path as a folder unless it ends in
124+ * `:<line>`, so pass `line` when `absolutePath` is a file.
122125 */
123126export const buildRemoteOpenUrl = ( input : {
124127 readonly editor : EditorId ;
125128 readonly host : string ;
126129 readonly absolutePath : string ;
127130 readonly authority ?: RemoteOpenAuthority ;
131+ readonly line ?: number ;
128132} ) : string | undefined => {
129133 const authority = input . authority ?? "ssh-remote" ;
130134 const scheme = remoteSchemeForEditor ( input . editor ) ;
@@ -145,7 +149,8 @@ export const buildRemoteOpenUrl = (input: {
145149 return `${ scheme } ://ssh/${ encodedHost } ${ encodedZedPath } ` ;
146150 }
147151 const encodedPath = rootedPath . split ( "/" ) . map ( encodeURIComponent ) . join ( "/" ) ;
148- return `${ scheme } ://vscode-remote/${ authority } +${ encodedHost } ${ encodedPath } ` ;
152+ const lineSuffix = input . line === undefined ? "" : `:${ input . line } ` ;
153+ return `${ scheme } ://vscode-remote/${ authority } +${ encodedHost } ${ encodedPath } ${ lineSuffix } ` ;
149154} ;
150155
151156/**
You can’t perform that action at this time.
0 commit comments