File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ import { errorHandler } from "./routes/errors"
88import { canConnect } from "./util"
99
1010export interface EditorSessionEntry {
11- workspace : {
11+ // Not set for a window that has no folder open.
12+ workspace ?: {
1213 id : string
1314 folders : {
1415 uri : {
@@ -98,7 +99,7 @@ export class EditorSessionManager {
9899 if ( matchCheckResults . has ( entry . socketPath ) ) {
99100 return matchCheckResults . get ( entry . socketPath ) !
100101 }
101- const result = entry . workspace . folders . some ( ( folder ) => filePath . startsWith ( folder . uri . path + path . sep ) )
102+ const result = entry . workspace ? .folders . some ( ( folder ) => filePath . startsWith ( folder . uri . path + path . sep ) ) ?? false
102103 matchCheckResults . set ( entry . socketPath , result )
103104 return result
104105 }
Original file line number Diff line number Diff line change @@ -779,6 +779,42 @@ describe("cli", () => {
779779 vscodeSockets . close ( )
780780 } )
781781
782+ it ( "should use existing if a window with no folder is also open" , async ( ) => {
783+ const sessionSocket = path . join ( tmpDirPath , "session-socket" )
784+ const server = await makeEditorSessionManagerServer ( sessionSocket , new EditorSessionManager ( ) )
785+
786+ const client = new EditorSessionManagerClient ( sessionSocket )
787+ const socketPath = path . join ( tmpDirPath , "socket" )
788+ await client . addSession ( {
789+ entry : {
790+ workspace : {
791+ id : "aaa" ,
792+ folders : [
793+ {
794+ uri : {
795+ path : "/aaa" ,
796+ } ,
797+ } ,
798+ ] ,
799+ } ,
800+ socketPath,
801+ } ,
802+ } )
803+ // Code sends no workspace for a window with no folder open.
804+ await client . addSession ( {
805+ entry : {
806+ socketPath : path . join ( tmpDirPath , "socket-no-folder" ) ,
807+ } ,
808+ } )
809+ const vscodeSockets = listenOn ( socketPath )
810+
811+ const args : UserProvidedArgs = { "reuse-window" : true , _ : [ "/aaa/file" ] }
812+ await expect ( shouldOpenInExistingInstance ( args , sessionSocket ) ) . resolves . toStrictEqual ( socketPath )
813+
814+ server . close ( )
815+ vscodeSockets . close ( )
816+ } )
817+
782818 it ( "should prefer matching sessions for only the first path" , async ( ) => {
783819 const sessionSocket = path . join ( tmpDirPath , "session-socket" )
784820 const server = await makeEditorSessionManagerServer ( sessionSocket , new EditorSessionManager ( ) )
Original file line number Diff line number Diff line change @@ -169,6 +169,31 @@ describe("EditorSessionManager", () => {
169169 `${ tmpDirPath } /vscode-ipc-aaa.sock` ,
170170 ] )
171171 } )
172+ it ( "should not fail on a window with no folder open" , async ( ) => {
173+ const manager = new EditorSessionManager ( )
174+ manager . addSession ( {
175+ workspace : {
176+ id : "aaa" ,
177+ folders : [
178+ {
179+ uri : {
180+ path : "/aaa" ,
181+ } ,
182+ } ,
183+ ] ,
184+ } ,
185+ socketPath : `${ tmpDirPath } /vscode-ipc-aaa.sock` ,
186+ } )
187+ // Code sends no workspace for a window with no folder open.
188+ manager . addSession ( {
189+ socketPath : `${ tmpDirPath } /vscode-ipc-empty.sock` ,
190+ } )
191+ const entries = manager . getCandidatesForFile ( "/bbb/some-file:1:1" )
192+ expect ( entries . map ( ( x ) => x . socketPath ) ) . toEqual ( [
193+ `${ tmpDirPath } /vscode-ipc-empty.sock` ,
194+ `${ tmpDirPath } /vscode-ipc-aaa.sock` ,
195+ ] )
196+ } )
172197 } )
173198
174199 describe ( "getConnectedSocketPath" , ( ) => {
You can’t perform that action at this time.
0 commit comments