@@ -11,7 +11,7 @@ import * as pfs from 'vs/base/node/pfs';
1111import { EnvironmentService } from 'vs/platform/environment/node/environmentService' ;
1212import { parseArgs , OPTIONS } from 'vs/platform/environment/node/argv' ;
1313import { WorkspacesMainService , IStoredWorkspace } from 'vs/platform/workspaces/electron-main/workspacesMainService' ;
14- import { WORKSPACE_EXTENSION , IRawFileWorkspaceFolder , IWorkspaceFolderCreationData , IRawUriWorkspaceFolder , rewriteWorkspaceFileForNewLocation , IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces' ;
14+ import { WORKSPACE_EXTENSION , IRawFileWorkspaceFolder , IWorkspaceFolderCreationData , IRawUriWorkspaceFolder , rewriteWorkspaceFileForNewLocation , IWorkspaceIdentifier , IStoredWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces' ;
1515import { NullLogService } from 'vs/platform/log/common/log' ;
1616import { URI } from 'vs/base/common/uri' ;
1717import { getRandomTestPath } from 'vs/base/test/node/testUtils' ;
@@ -109,11 +109,27 @@ suite('WorkspacesMainService', () => {
109109 }
110110 }
111111
112- function createWorkspace ( folders : string [ ] , names ?: string [ ] ) {
112+ function createUntitledWorkspace ( folders : string [ ] , names ?: string [ ] ) {
113113 return service . createUntitledWorkspace ( folders . map ( ( folder , index ) => ( { uri : URI . file ( folder ) , name : names ? names [ index ] : undefined } as IWorkspaceFolderCreationData ) ) ) ;
114114 }
115115
116- function createWorkspaceSync ( folders : string [ ] , names ?: string [ ] ) {
116+ function createWorkspace ( workspaceConfigPath : string , folders : ( string | URI ) [ ] , names ?: string [ ] ) : void {
117+
118+ const ws : IStoredWorkspace = {
119+ folders : [ ]
120+ } ;
121+ for ( let i = 0 ; i < folders . length ; i ++ ) {
122+ const f = folders [ i ] ;
123+ const s : IStoredWorkspaceFolder = f instanceof URI ? { uri : f . toString ( ) } : { path : f } ;
124+ if ( names ) {
125+ s . name = names [ i ] ;
126+ }
127+ ws . folders . push ( s ) ;
128+ }
129+ fs . writeFileSync ( workspaceConfigPath , JSON . stringify ( ws ) ) ;
130+ }
131+
132+ function createUntitledWorkspaceSync ( folders : string [ ] , names ?: string [ ] ) {
117133 return service . createUntitledWorkspaceSync ( folders . map ( ( folder , index ) => ( { uri : URI . file ( folder ) , name : names ? names [ index ] : undefined } as IWorkspaceFolderCreationData ) ) ) ;
118134 }
119135
@@ -149,7 +165,7 @@ suite('WorkspacesMainService', () => {
149165 }
150166
151167 test ( 'createWorkspace (folders)' , async ( ) => {
152- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
168+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
153169 assert . ok ( workspace ) ;
154170 assert . ok ( fs . existsSync ( workspace . configPath . fsPath ) ) ;
155171 assert . ok ( service . isUntitledWorkspace ( workspace ) ) ;
@@ -163,7 +179,7 @@ suite('WorkspacesMainService', () => {
163179 } ) ;
164180
165181 test ( 'createWorkspace (folders with name)' , async ( ) => {
166- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] , [ 'currentworkingdirectory' , 'tempdir' ] ) ;
182+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] , [ 'currentworkingdirectory' , 'tempdir' ] ) ;
167183 assert . ok ( workspace ) ;
168184 assert . ok ( fs . existsSync ( workspace . configPath . fsPath ) ) ;
169185 assert . ok ( service . isUntitledWorkspace ( workspace ) ) ;
@@ -195,7 +211,7 @@ suite('WorkspacesMainService', () => {
195211 } ) ;
196212
197213 test ( 'createWorkspaceSync (folders)' , ( ) => {
198- const workspace = createWorkspaceSync ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
214+ const workspace = createUntitledWorkspaceSync ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
199215 assert . ok ( workspace ) ;
200216 assert . ok ( fs . existsSync ( workspace . configPath . fsPath ) ) ;
201217 assert . ok ( service . isUntitledWorkspace ( workspace ) ) ;
@@ -210,7 +226,7 @@ suite('WorkspacesMainService', () => {
210226 } ) ;
211227
212228 test ( 'createWorkspaceSync (folders with names)' , ( ) => {
213- const workspace = createWorkspaceSync ( [ process . cwd ( ) , os . tmpdir ( ) ] , [ 'currentworkingdirectory' , 'tempdir' ] ) ;
229+ const workspace = createUntitledWorkspaceSync ( [ process . cwd ( ) , os . tmpdir ( ) ] , [ 'currentworkingdirectory' , 'tempdir' ] ) ;
214230 assert . ok ( workspace ) ;
215231 assert . ok ( fs . existsSync ( workspace . configPath . fsPath ) ) ;
216232 assert . ok ( service . isUntitledWorkspace ( workspace ) ) ;
@@ -243,7 +259,7 @@ suite('WorkspacesMainService', () => {
243259 } ) ;
244260
245261 test ( 'resolveWorkspaceSync' , async ( ) => {
246- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
262+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
247263 assert . ok ( service . resolveLocalWorkspaceSync ( workspace . configPath ) ) ;
248264
249265 // make it a valid workspace path
@@ -262,31 +278,31 @@ suite('WorkspacesMainService', () => {
262278 } ) ;
263279
264280 test ( 'resolveWorkspaceSync (support relative paths)' , async ( ) => {
265- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
281+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
266282 fs . writeFileSync ( workspace . configPath . fsPath , JSON . stringify ( { folders : [ { path : './ticino-playground/lib' } ] } ) ) ;
267283
268284 const resolved = service . resolveLocalWorkspaceSync ( workspace . configPath ) ;
269285 assertEqualURI ( resolved ! . folders [ 0 ] . uri , URI . file ( path . join ( path . dirname ( workspace . configPath . fsPath ) , 'ticino-playground' , 'lib' ) ) ) ;
270286 } ) ;
271287
272288 test ( 'resolveWorkspaceSync (support relative paths #2)' , async ( ) => {
273- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
289+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
274290 fs . writeFileSync ( workspace . configPath . fsPath , JSON . stringify ( { folders : [ { path : './ticino-playground/lib/../other' } ] } ) ) ;
275291
276292 const resolved = service . resolveLocalWorkspaceSync ( workspace . configPath ) ;
277293 assertEqualURI ( resolved ! . folders [ 0 ] . uri , URI . file ( path . join ( path . dirname ( workspace . configPath . fsPath ) , 'ticino-playground' , 'other' ) ) ) ;
278294 } ) ;
279295
280296 test ( 'resolveWorkspaceSync (support relative paths #3)' , async ( ) => {
281- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
297+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
282298 fs . writeFileSync ( workspace . configPath . fsPath , JSON . stringify ( { folders : [ { path : 'ticino-playground/lib' } ] } ) ) ;
283299
284300 const resolved = service . resolveLocalWorkspaceSync ( workspace . configPath ) ;
285301 assertEqualURI ( resolved ! . folders [ 0 ] . uri , URI . file ( path . join ( path . dirname ( workspace . configPath . fsPath ) , 'ticino-playground' , 'lib' ) ) ) ;
286302 } ) ;
287303
288304 test ( 'resolveWorkspaceSync (support invalid JSON via fault tolerant parsing)' , async ( ) => {
289- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
305+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
290306 fs . writeFileSync ( workspace . configPath . fsPath , '{ "folders": [ { "path": "./ticino-playground/lib" } , ] }' ) ; // trailing comma
291307
292308 const resolved = service . resolveLocalWorkspaceSync ( workspace . configPath ) ;
@@ -296,14 +312,15 @@ suite('WorkspacesMainService', () => {
296312 test ( 'rewriteWorkspaceFileForNewLocation' , async ( ) => {
297313 const folder1 = process . cwd ( ) ; // absolute path because outside of tmpDir
298314 const tmpDir = os . tmpdir ( ) ;
299- const tmpInsideDir = path . join ( os . tmpdir ( ) , 'inside' ) ;
315+ const tmpInsideDir = path . join ( tmpDir , 'inside' ) ;
300316
301- const workspace = await createWorkspace ( [ folder1 , tmpInsideDir , path . join ( tmpInsideDir , 'somefolder' ) ] ) ;
302- const origContent = fs . readFileSync ( workspace . configPath . fsPath ) . toString ( ) ;
317+ const firstConfigPath = path . join ( tmpDir , 'myworkspace0.code-workspace' ) ;
318+ createWorkspace ( firstConfigPath , [ folder1 , 'inside' , path . join ( 'inside' , 'somefolder' ) ] ) ;
319+ const origContent = fs . readFileSync ( firstConfigPath ) . toString ( ) ;
303320
304- let origConfigPath = workspace . configPath ;
321+ let origConfigPath = URI . file ( firstConfigPath ) ;
305322 let workspaceConfigPath = URI . file ( path . join ( tmpDir , 'inside' , 'myworkspace1.code-workspace' ) ) ;
306- let newContent = rewriteWorkspaceFileForNewLocation ( origContent , origConfigPath , workspaceConfigPath ) ;
323+ let newContent = rewriteWorkspaceFileForNewLocation ( origContent , origConfigPath , false , workspaceConfigPath ) ;
307324 let ws = ( JSON . parse ( newContent ) as IStoredWorkspace ) ;
308325 assert . equal ( ws . folders . length , 3 ) ;
309326 assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 0 ] ) . path , folder1 ) ; // absolute path because outside of tmpdir
@@ -312,7 +329,7 @@ suite('WorkspacesMainService', () => {
312329
313330 origConfigPath = workspaceConfigPath ;
314331 workspaceConfigPath = URI . file ( path . join ( tmpDir , 'myworkspace2.code-workspace' ) ) ;
315- newContent = rewriteWorkspaceFileForNewLocation ( newContent , origConfigPath , workspaceConfigPath ) ;
332+ newContent = rewriteWorkspaceFileForNewLocation ( newContent , origConfigPath , false , workspaceConfigPath ) ;
316333 ws = ( JSON . parse ( newContent ) as IStoredWorkspace ) ;
317334 assert . equal ( ws . folders . length , 3 ) ;
318335 assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 0 ] ) . path , folder1 ) ;
@@ -321,45 +338,45 @@ suite('WorkspacesMainService', () => {
321338
322339 origConfigPath = workspaceConfigPath ;
323340 workspaceConfigPath = URI . file ( path . join ( tmpDir , 'other' , 'myworkspace2.code-workspace' ) ) ;
324- newContent = rewriteWorkspaceFileForNewLocation ( newContent , origConfigPath , workspaceConfigPath ) ;
341+ newContent = rewriteWorkspaceFileForNewLocation ( newContent , origConfigPath , false , workspaceConfigPath ) ;
325342 ws = ( JSON . parse ( newContent ) as IStoredWorkspace ) ;
326343 assert . equal ( ws . folders . length , 3 ) ;
327344 assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 0 ] ) . path , folder1 ) ;
328- assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 1 ] ) . path , tmpInsideDir ) ;
329- assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 2 ] ) . path , path . join ( tmpInsideDir , ' somefolder') ) ;
345+ assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 1 ] ) . path , isWindows ? '..\\inside' : '../inside' ) ;
346+ assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 2 ] ) . path , isWindows ? '..\\inside\\somefolder' : '../inside/ somefolder') ;
330347
331348 origConfigPath = workspaceConfigPath ;
332349 workspaceConfigPath = URI . parse ( 'foo://foo/bar/myworkspace2.code-workspace' ) ;
333- newContent = rewriteWorkspaceFileForNewLocation ( newContent , origConfigPath , workspaceConfigPath ) ;
350+ newContent = rewriteWorkspaceFileForNewLocation ( newContent , origConfigPath , false , workspaceConfigPath ) ;
334351 ws = ( JSON . parse ( newContent ) as IStoredWorkspace ) ;
335352 assert . equal ( ws . folders . length , 3 ) ;
336353 assert . equal ( ( < IRawUriWorkspaceFolder > ws . folders [ 0 ] ) . uri , URI . file ( folder1 ) . toString ( true ) ) ;
337354 assert . equal ( ( < IRawUriWorkspaceFolder > ws . folders [ 1 ] ) . uri , URI . file ( tmpInsideDir ) . toString ( true ) ) ;
338355 assert . equal ( ( < IRawUriWorkspaceFolder > ws . folders [ 2 ] ) . uri , URI . file ( path . join ( tmpInsideDir , 'somefolder' ) ) . toString ( true ) ) ;
339356
340- service . deleteUntitledWorkspaceSync ( workspace ) ;
357+ fs . unlinkSync ( firstConfigPath ) ;
341358 } ) ;
342359
343360 test ( 'rewriteWorkspaceFileForNewLocation (preserves comments)' , async ( ) => {
344- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) , path . join ( os . tmpdir ( ) , 'somefolder' ) ] ) ;
361+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) , path . join ( os . tmpdir ( ) , 'somefolder' ) ] ) ;
345362 const workspaceConfigPath = URI . file ( path . join ( os . tmpdir ( ) , `myworkspace.${ Date . now ( ) } .${ WORKSPACE_EXTENSION } ` ) ) ;
346363
347364 let origContent = fs . readFileSync ( workspace . configPath . fsPath ) . toString ( ) ;
348365 origContent = `// this is a comment\n${ origContent } ` ;
349366
350- let newContent = rewriteWorkspaceFileForNewLocation ( origContent , workspace . configPath , workspaceConfigPath ) ;
367+ let newContent = rewriteWorkspaceFileForNewLocation ( origContent , workspace . configPath , false , workspaceConfigPath ) ;
351368 assert . equal ( 0 , newContent . indexOf ( '// this is a comment' ) ) ;
352369 service . deleteUntitledWorkspaceSync ( workspace ) ;
353370 } ) ;
354371
355372 test ( 'rewriteWorkspaceFileForNewLocation (preserves forward slashes)' , async ( ) => {
356- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) , path . join ( os . tmpdir ( ) , 'somefolder' ) ] ) ;
373+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) , path . join ( os . tmpdir ( ) , 'somefolder' ) ] ) ;
357374 const workspaceConfigPath = URI . file ( path . join ( os . tmpdir ( ) , `myworkspace.${ Date . now ( ) } .${ WORKSPACE_EXTENSION } ` ) ) ;
358375
359376 let origContent = fs . readFileSync ( workspace . configPath . fsPath ) . toString ( ) ;
360377 origContent = origContent . replace ( / [ \\ ] / g, '/' ) ; // convert backslash to slash
361378
362- const newContent = rewriteWorkspaceFileForNewLocation ( origContent , workspace . configPath , workspaceConfigPath ) ;
379+ const newContent = rewriteWorkspaceFileForNewLocation ( origContent , workspace . configPath , false , workspaceConfigPath ) ;
363380 const ws = ( JSON . parse ( newContent ) as IStoredWorkspace ) ;
364381 assert . ok ( ws . folders . every ( f => ( < IRawFileWorkspaceFolder > f ) . path . indexOf ( '\\' ) < 0 ) ) ;
365382 service . deleteUntitledWorkspaceSync ( workspace ) ;
@@ -375,10 +392,10 @@ suite('WorkspacesMainService', () => {
375392 const folder2Location = '\\\\server\\share2\\some\\path' ;
376393 const folder3Location = path . join ( os . tmpdir ( ) , 'wsloc' , 'inner' , 'more' ) ;
377394
378- const workspace = await createWorkspace ( [ folder1Location , folder2Location , folder3Location ] ) ;
395+ const workspace = await createUntitledWorkspace ( [ folder1Location , folder2Location , folder3Location ] ) ;
379396 const workspaceConfigPath = URI . file ( path . join ( workspaceLocation , `myworkspace.${ Date . now ( ) } .${ WORKSPACE_EXTENSION } ` ) ) ;
380397 let origContent = fs . readFileSync ( workspace . configPath . fsPath ) . toString ( ) ;
381- const newContent = rewriteWorkspaceFileForNewLocation ( origContent , workspace . configPath , workspaceConfigPath ) ;
398+ const newContent = rewriteWorkspaceFileForNewLocation ( origContent , workspace . configPath , false , workspaceConfigPath ) ;
382399 const ws = ( JSON . parse ( newContent ) as IStoredWorkspace ) ;
383400 assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 0 ] ) . path , folder1Location ) ;
384401 assertPathEquals ( ( < IRawFileWorkspaceFolder > ws . folders [ 1 ] ) . path , folder2Location ) ;
@@ -388,14 +405,14 @@ suite('WorkspacesMainService', () => {
388405 } ) ;
389406
390407 test ( 'deleteUntitledWorkspaceSync (untitled)' , async ( ) => {
391- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
408+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
392409 assert . ok ( fs . existsSync ( workspace . configPath . fsPath ) ) ;
393410 service . deleteUntitledWorkspaceSync ( workspace ) ;
394411 assert . ok ( ! fs . existsSync ( workspace . configPath . fsPath ) ) ;
395412 } ) ;
396413
397414 test ( 'deleteUntitledWorkspaceSync (saved)' , async ( ) => {
398- const workspace = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
415+ const workspace = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
399416 service . deleteUntitledWorkspaceSync ( workspace ) ;
400417 } ) ;
401418
@@ -405,14 +422,14 @@ suite('WorkspacesMainService', () => {
405422 let untitled = service . getUntitledWorkspacesSync ( ) ;
406423 assert . equal ( untitled . length , 0 ) ;
407424
408- const untitledOne = await createWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
425+ const untitledOne = await createUntitledWorkspace ( [ process . cwd ( ) , os . tmpdir ( ) ] ) ;
409426 assert . ok ( fs . existsSync ( untitledOne . configPath . fsPath ) ) ;
410427
411428 untitled = service . getUntitledWorkspacesSync ( ) ;
412429 assert . equal ( 1 , untitled . length ) ;
413430 assert . equal ( untitledOne . id , untitled [ 0 ] . workspace . id ) ;
414431
415- const untitledTwo = await createWorkspace ( [ os . tmpdir ( ) , process . cwd ( ) ] ) ;
432+ const untitledTwo = await createUntitledWorkspace ( [ os . tmpdir ( ) , process . cwd ( ) ] ) ;
416433 assert . ok ( fs . existsSync ( untitledTwo . configPath . fsPath ) ) ;
417434 assert . ok ( fs . existsSync ( untitledOne . configPath . fsPath ) , `Unexpected workspaces count of 1 (expected 2): ${ untitledOne . configPath . fsPath } does not exist anymore?` ) ;
418435 const untitledHome = dirname ( dirname ( untitledTwo . configPath ) ) ;
0 commit comments