@@ -922,6 +922,159 @@ it.effect("discovers editors through the service API", () =>
922922 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
923923) ;
924924
925+ for ( const { platform, installPath, editor, args } of [
926+ {
927+ platform : "darwin" ,
928+ installPath : "Applications/Cursor.app/Contents/Resources/app/bin/code" ,
929+ editor : "cursor" ,
930+ args : [ "--classic" , "--goto" , "/workspace with spaces/file.ts:12:4" ] ,
931+ } ,
932+ {
933+ platform : "darwin" ,
934+ installPath : "Applications/Kiro.app/Contents/Resources/app/bin/code" ,
935+ editor : "kiro" ,
936+ args : [ "--goto" , "/workspace with spaces/file.ts:12:4" ] ,
937+ } ,
938+ {
939+ platform : "darwin" ,
940+ installPath : "Applications/WebStorm.app/Contents/MacOS/webstorm" ,
941+ editor : "webstorm" ,
942+ args : [ "--line" , "12" , "--column" , "4" , "/workspace with spaces/file.ts" ] ,
943+ } ,
944+ {
945+ platform : "darwin" ,
946+ installPath : "Applications/Zed.app/Contents/MacOS/cli" ,
947+ editor : "zed" ,
948+ args : [ "/workspace with spaces/file.ts:12:4" ] ,
949+ } ,
950+ {
951+ platform : "win32" ,
952+ installPath : "Programs/Cursor/resources/app/bin/cursor.cmd" ,
953+ editor : "cursor" ,
954+ args : [ '^"--classic^"' , '^"--goto^"' , '^"/workspace^ with^ spaces/file.ts:12:4^"' ] ,
955+ } ,
956+ {
957+ platform : "win32" ,
958+ installPath : "Programs/Microsoft VS Code/bin/code.cmd" ,
959+ editor : "vscode" ,
960+ args : [ '^"--goto^"' , '^"/workspace^ with^ spaces/file.ts:12:4^"' ] ,
961+ } ,
962+ {
963+ platform : "win32" ,
964+ installPath : "Programs/JetBrains/WebStorm 2026.2/bin/webstorm64.exe" ,
965+ editor : "webstorm" ,
966+ args : [ "--line" , "12" , "--column" , "4" , "/workspace with spaces/file.ts" ] ,
967+ } ,
968+ {
969+ platform : "win32" ,
970+ installPath : "Programs/WebStorm/bin/webstorm64.exe" ,
971+ editor : "webstorm" ,
972+ args : [ "--line" , "12" , "--column" , "4" , "/workspace with spaces/file.ts" ] ,
973+ } ,
974+ {
975+ platform : "win32" ,
976+ installPath : "Programs/Zed/bin/zed.exe" ,
977+ editor : "zed" ,
978+ args : [ "/workspace with spaces/file.ts:12:4" ] ,
979+ } ,
980+ {
981+ platform : "linux" ,
982+ installPath : ".local/share/JetBrains/Toolbox/scripts/idea" ,
983+ editor : "idea" ,
984+ args : [ "--line" , "12" , "--column" , "4" , "/workspace with spaces/file.ts" ] ,
985+ } ,
986+ {
987+ platform : "linux" ,
988+ installPath : ".local/bin/zed" ,
989+ editor : "zed" ,
990+ args : [ "/workspace with spaces/file.ts:12:4" ] ,
991+ } ,
992+ ] as const ) {
993+ it . effect . skipIf ( windowsHost && platform !== "win32" ) (
994+ `discovers and launches ${ editor } outside PATH on ${ platform } ` ,
995+ ( ) =>
996+ Effect . gen ( function * ( ) {
997+ const fs = yield * FileSystem . FileSystem ;
998+ const path = yield * Path . Path ;
999+ const home = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-editor installs-" } ) ;
1000+ const executable = path . join ( home , installPath ) ;
1001+ yield * fs . makeDirectory ( path . dirname ( executable ) , { recursive : true } ) ;
1002+ yield * fs . writeFileString ( executable , "#!/bin/sh\n" ) ;
1003+ yield * fs . chmod ( executable , 0o755 ) ;
1004+ let spawned : ChildProcess . StandardCommand | undefined ;
1005+ yield * Effect . gen ( function * ( ) {
1006+ const launcher = yield * ExternalLauncher . ExternalLauncher ;
1007+ assert . include ( yield * launcher . resolveAvailableEditors ( ) , editor ) ;
1008+ yield * launcher . launchEditor ( { editor, cwd : "/workspace with spaces/file.ts:12:4" } ) ;
1009+ } ) . pipe (
1010+ Effect . provide (
1011+ testLayer ( {
1012+ platform,
1013+ env : { HOME : home , LOCALAPPDATA : home , PATH : path . join ( home , "empty" ) } ,
1014+ onSpawn : ( command ) => {
1015+ spawned = command ;
1016+ } ,
1017+ } ) ,
1018+ ) ,
1019+ ) ;
1020+ assert . ok ( spawned ) ;
1021+ assert . equal (
1022+ spawned . command ,
1023+ executable . endsWith ( ".cmd" ) ? `^"${ executable . replaceAll ( " " , "^ " ) } ^"` : executable ,
1024+ ) ;
1025+ assert . deepEqual ( spawned . args , args ) ;
1026+ assert . equal ( spawned . options . shell , executable . endsWith ( ".cmd" ) ) ;
1027+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
1028+ ) ;
1029+ }
1030+
1031+ it . effect . skipIf ( windowsHost ) ( "ignores unusable app bundles and keeps PATH launchers first" , ( ) =>
1032+ Effect . gen ( function * ( ) {
1033+ const fs = yield * FileSystem . FileSystem ;
1034+ const path = yield * Path . Path ;
1035+ const home = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-editor-priority-" } ) ;
1036+ const executable = path . join ( home , "Applications/Cursor.app/Contents/Resources/app/bin/code" ) ;
1037+ const env = { HOME : home , PATH : path . join ( home , "bin" ) } ;
1038+ const discover = Effect . gen ( function * ( ) {
1039+ const launcher = yield * ExternalLauncher . ExternalLauncher ;
1040+ return yield * launcher . resolveAvailableEditors ( ) ;
1041+ } ) ;
1042+ const before = yield * discover . pipe ( Effect . provide ( testLayer ( { platform : "darwin" , env } ) ) ) ;
1043+ yield * fs . makeDirectory ( executable , { recursive : true } ) ;
1044+ assert . deepEqual (
1045+ yield * discover . pipe ( Effect . provide ( testLayer ( { platform : "darwin" , env } ) ) ) ,
1046+ before ,
1047+ ) ;
1048+ yield * fs . remove ( executable , { recursive : true } ) ;
1049+ yield * fs . writeFileString ( executable , "#!/bin/sh\n" ) ;
1050+ yield * fs . chmod ( executable , 0o644 ) ;
1051+ assert . deepEqual (
1052+ yield * discover . pipe ( Effect . provide ( testLayer ( { platform : "darwin" , env } ) ) ) ,
1053+ before ,
1054+ ) ;
1055+ yield * fs . chmod ( executable , 0o755 ) ;
1056+ yield * fs . makeDirectory ( env . PATH ) ;
1057+ yield * fs . writeFileString ( path . join ( env . PATH , "cursor" ) , "#!/bin/sh\n" ) ;
1058+ yield * fs . chmod ( path . join ( env . PATH , "cursor" ) , 0o755 ) ;
1059+ let spawned : ChildProcess . StandardCommand | undefined ;
1060+ yield * Effect . gen ( function * ( ) {
1061+ const launcher = yield * ExternalLauncher . ExternalLauncher ;
1062+ yield * launcher . launchEditor ( { editor : "cursor" , cwd : "/workspace" } ) ;
1063+ } ) . pipe (
1064+ Effect . provide (
1065+ testLayer ( {
1066+ platform : "darwin" ,
1067+ env : { ...env , PATH : `${ env . PATH } :/usr/bin` } ,
1068+ onSpawn : ( command ) => {
1069+ spawned = command ;
1070+ } ,
1071+ } ) ,
1072+ ) ,
1073+ ) ;
1074+ assert . equal ( spawned ?. command , "cursor" ) ;
1075+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
1076+ ) ;
1077+
9251078it . effect ( "memoizes editor discovery and refreshes after the cache window" , ( ) => {
9261079 let statCalls = 0 ;
9271080 const fileInfo = { type : "File" } as FileSystem . File . Info ;
0 commit comments