11import {
2+ buildRemoteOpenUrl ,
23 EDITORS ,
34 type ContextMenuItem ,
45 type EditorId ,
@@ -12,6 +13,7 @@ import {
1213} from "~/components/preview/fileExplorerLabel" ;
1314import { usePreferredEditor } from "./editorPreferences" ;
1415import { readLocalApi } from "./localApi" ;
16+ import { openRemoteEditorUrl , useRemoteCapableEditors , useRemoteOpenState } from "./remoteOpen" ;
1517import { serverEnvironment } from "./state/server" ;
1618import { shellEnvironment } from "./state/shell" ;
1719import { useAtomCommand } from "./state/use-atom-command" ;
@@ -33,6 +35,7 @@ export interface FileContextMenuTarget {
3335 readonly filePath : string ;
3436 readonly workspaceRoot : string | undefined ;
3537 readonly repositoryRoot ?: string | undefined ;
38+ readonly isDirectory ?: boolean ;
3639}
3740
3841export function resolveFileContextMenuAbsolutePath ( target : FileContextMenuTarget ) : string | null {
@@ -109,20 +112,30 @@ export function useFileContextMenu(environmentId: EnvironmentId | null) {
109112 const openInEditor = useAtomCommand ( shellEnvironment . openInEditor , { reportFailure : false } ) ;
110113 const serverConfig = useAtomValue ( serverEnvironment . configValueAtom ( environmentId ) ) ;
111114
112- const availableEditors = serverConfig ?. availableEditors ?? [ ] ;
115+ const remote = useRemoteOpenState ( environmentId ) ;
116+ const remoteCapableEditors = useRemoteCapableEditors ( ) ;
117+ const isLocal = remote . mode === "local-exec" ;
118+ // Away from the server's machine, editors open over SSH on this machine, which
119+ // only works for editors with a remote URL scheme and can't reveal files.
120+ const availableEditors = isLocal
121+ ? ( serverConfig ?. availableEditors ?? [ ] )
122+ : remote . mode === "remote-links"
123+ ? remoteCapableEditors
124+ : [ ] ;
113125 const [ preferredEditor ] = usePreferredEditor ( availableEditors ) ;
114126 const capabilities : FileContextMenuCapabilities = {
115127 // The reveal wording comes from the server because on WSL the reveal can
116128 // run through Windows File Explorer even though the host reports Linux.
117129 revealLabel :
130+ isLocal &&
118131 environmentId !== null &&
119132 serverConfig ?. shellRevealInFileManager === true &&
120133 serverConfig . availableEditors . includes ( "file-manager" )
121134 ? serverConfig . shellRevealInFileManagerKind === undefined
122135 ? revealInFileExplorerLabelForOs ( serverConfig . environment . platform . os )
123136 : revealInFileExplorerLabelForKind ( serverConfig . shellRevealInFileManagerKind )
124137 : undefined ,
125- canOpenDefault : availableEditors . includes ( "file-manager" ) ,
138+ canOpenDefault : isLocal && availableEditors . includes ( "file-manager" ) ,
126139 editorIds : availableEditors ,
127140 } ;
128141
@@ -140,6 +153,22 @@ export function useFileContextMenu(environmentId: EnvironmentId | null) {
140153 : ( action . slice ( "editor:" . length ) as EditorId ) ;
141154 if ( action !== "open" && ! reveal && ! capabilities . editorIds . includes ( editor ) ) return ;
142155
156+ if ( remote . mode === "remote-links" ) {
157+ const url = buildRemoteOpenUrl ( {
158+ editor,
159+ ...remote . host ,
160+ absolutePath,
161+ isFile : target . isDirectory !== true ,
162+ } ) ;
163+ if ( url !== undefined && ( await openRemoteEditorUrl ( url ) ) ) return ;
164+ toastManager . add ( {
165+ type : "error" ,
166+ title : `Could not open in ${ EDITOR_LABEL_BY_ID . get ( editor ) ?? editor } ` ,
167+ description : absolutePath ,
168+ } ) ;
169+ return ;
170+ }
171+
143172 const result = await openInEditor ( {
144173 environmentId,
145174 input : { cwd : absolutePath , editor, ...( reveal ? { reveal : true } : { } ) } ,
0 commit comments