Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
1967cd3d
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1967cd3d
编写于
9月 18, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve format of workspace paths when writing
- fixes #33270 - fixes #33328
上级
e58b8568
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
200 addition
and
116 deletion
+200
-116
src/vs/editor/standalone/browser/simpleServices.ts
src/vs/editor/standalone/browser/simpleServices.ts
+1
-1
src/vs/platform/workspace/common/workspace.ts
src/vs/platform/workspace/common/workspace.ts
+4
-4
src/vs/platform/workspace/test/common/workspace.test.ts
src/vs/platform/workspace/test/common/workspace.test.ts
+23
-21
src/vs/platform/workspaces/electron-main/workspacesMainService.ts
...latform/workspaces/electron-main/workspacesMainService.ts
+5
-36
src/vs/platform/workspaces/node/workspaces.ts
src/vs/platform/workspaces/node/workspaces.ts
+66
-0
src/vs/platform/workspaces/test/electron-main/workspacesMainService.test.ts
...rkspaces/test/electron-main/workspacesMainService.test.ts
+26
-0
src/vs/workbench/services/configuration/test/node/configuration.test.ts
...ch/services/configuration/test/node/configuration.test.ts
+1
-1
src/vs/workbench/services/files/test/node/fileService.test.ts
...vs/workbench/services/files/test/node/fileService.test.ts
+4
-4
src/vs/workbench/services/keybinding/test/node/keybindingEditing.test.ts
...h/services/keybinding/test/node/keybindingEditing.test.ts
+1
-1
src/vs/workbench/services/workspace/node/workspaceEditingService.ts
...kbench/services/workspace/node/workspaceEditingService.ts
+61
-43
src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts
...ch/test/electron-browser/api/extHostConfiguration.test.ts
+5
-4
src/vs/workbench/test/electron-browser/api/extHostWorkspace.test.ts
...kbench/test/electron-browser/api/extHostWorkspace.test.ts
+3
-1
未找到文件。
src/vs/editor/standalone/browser/simpleServices.ts
浏览文件 @
1967cd3d
...
...
@@ -535,7 +535,7 @@ export class SimpleWorkspaceContextService implements IWorkspaceContextService {
constructor
()
{
const
resource
=
URI
.
from
({
scheme
:
SimpleWorkspaceContextService
.
SCHEME
,
authority
:
'
model
'
,
path
:
'
/
'
});
this
.
workspace
=
{
id
:
'
4064f6ec-cb38-4ad0-af64-ee6467e63c82
'
,
folders
:
[{
uri
:
resource
,
raw
:
resource
.
toString
()
,
name
:
''
,
index
:
0
,
}],
name
:
resource
.
fsPath
};
this
.
workspace
=
{
id
:
'
4064f6ec-cb38-4ad0-af64-ee6467e63c82
'
,
folders
:
[{
uri
:
resource
,
raw
:
{
path
:
resource
.
toString
()
}
,
name
:
''
,
index
:
0
,
}],
name
:
resource
.
fsPath
};
}
public
getWorkspace
():
IWorkspace
{
...
...
src/vs/platform/workspace/common/workspace.ts
浏览文件 @
1967cd3d
...
...
@@ -120,7 +120,7 @@ export interface WorkspaceFolder {
/**
* The raw path of this workspace folder
*/
readonly
raw
:
string
;
readonly
raw
:
IStoredWorkspaceFolder
;
}
export
class
Workspace
implements
IWorkspace
{
...
...
@@ -190,12 +190,12 @@ export function toWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[],
}
function
parseWorkspaceFolders
(
configuredFolders
:
IStoredWorkspaceFolder
[],
relativeTo
:
URI
):
WorkspaceFolder
[]
{
return
configuredFolders
.
map
((
{
path
,
name
}
,
index
)
=>
{
const
uri
=
toUri
(
path
,
relativeTo
);
return
configuredFolders
.
map
((
configuredFolder
,
index
)
=>
{
const
uri
=
toUri
(
configuredFolder
.
path
,
relativeTo
);
if
(
!
uri
)
{
return
void
0
;
}
return
{
uri
,
raw
:
path
,
index
,
name
};
return
{
uri
,
raw
:
configuredFolder
,
index
,
name
:
configuredFolder
.
name
};
});
}
...
...
src/vs/platform/workspace/test/common/workspace.test.ts
浏览文件 @
1967cd3d
...
...
@@ -51,7 +51,7 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
1
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
/src/test
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
/src/test
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
test
'
);
});
...
...
@@ -61,7 +61,7 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
1
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
./test
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
./test
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
test
'
);
});
...
...
@@ -71,7 +71,7 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
1
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
/src/test
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
/src/test
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
hello
'
);
});
...
...
@@ -81,17 +81,17 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
3
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
test2
'
);
assert
.
equal
(
actual
[
1
].
uri
.
fsPath
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
.
path
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
index
,
1
);
assert
.
equal
(
actual
[
1
].
name
,
'
test3
'
);
assert
.
equal
(
actual
[
2
].
uri
.
fsPath
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
.
path
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
2
].
index
,
2
);
assert
.
equal
(
actual
[
2
].
name
,
'
test1
'
);
});
...
...
@@ -101,17 +101,17 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
3
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
test2
'
);
assert
.
equal
(
actual
[
1
].
uri
.
fsPath
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
.
path
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
index
,
1
);
assert
.
equal
(
actual
[
1
].
name
,
'
noName
'
);
assert
.
equal
(
actual
[
2
].
uri
.
fsPath
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
.
path
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
2
].
index
,
2
);
assert
.
equal
(
actual
[
2
].
name
,
'
test1
'
);
});
...
...
@@ -121,17 +121,17 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
3
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
test2
'
);
assert
.
equal
(
actual
[
1
].
uri
.
fsPath
,
'
/abc/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
,
'
/abc/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
.
path
,
'
/abc/test3
'
);
assert
.
equal
(
actual
[
1
].
index
,
1
);
assert
.
equal
(
actual
[
1
].
name
,
'
noName
'
);
assert
.
equal
(
actual
[
2
].
uri
.
fsPath
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
,
'
./test1
'
);
assert
.
equal
(
actual
[
2
].
raw
.
path
,
'
./test1
'
);
assert
.
equal
(
actual
[
2
].
index
,
2
);
assert
.
equal
(
actual
[
2
].
name
,
'
test1
'
);
});
...
...
@@ -141,12 +141,12 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
2
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
test2
'
);
assert
.
equal
(
actual
[
1
].
uri
.
fsPath
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
1
].
raw
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
1
].
raw
.
path
,
'
/src/test1
'
);
assert
.
equal
(
actual
[
1
].
index
,
1
);
assert
.
equal
(
actual
[
1
].
name
,
'
test1
'
);
});
...
...
@@ -156,17 +156,17 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
3
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
test2
'
);
assert
.
equal
(
actual
[
1
].
uri
.
fsPath
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
.
path
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
index
,
1
);
assert
.
equal
(
actual
[
1
].
name
,
'
noName
'
);
assert
.
equal
(
actual
[
2
].
uri
.
fsPath
,
'
/abc/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
,
'
/abc/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
.
path
,
'
/abc/test1
'
);
assert
.
equal
(
actual
[
2
].
index
,
2
);
assert
.
equal
(
actual
[
2
].
name
,
'
test1
'
);
});
...
...
@@ -176,23 +176,25 @@ suite('Workspace', () => {
assert
.
equal
(
actual
.
length
,
3
);
assert
.
equal
(
actual
[
0
].
uri
.
fsPath
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
raw
.
path
,
'
/src/test2
'
);
assert
.
equal
(
actual
[
0
].
index
,
0
);
assert
.
equal
(
actual
[
0
].
name
,
'
test2
'
);
assert
.
equal
(
actual
[
1
].
uri
.
fsPath
,
'
/src/test3
'
);
assert
.
equal
(
actual
[
1
].
raw
,
'
./test3
'
);
assert
.
equal
(
actual
[
1
].
raw
.
path
,
'
./test3
'
);
assert
.
equal
(
actual
[
1
].
index
,
1
);
assert
.
equal
(
actual
[
1
].
name
,
'
test3
'
);
assert
.
equal
(
actual
[
2
].
uri
.
fsPath
,
'
/abc/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
,
'
/abc/test1
'
);
assert
.
equal
(
actual
[
2
].
raw
.
path
,
'
/abc/test1
'
);
assert
.
equal
(
actual
[
2
].
index
,
2
);
assert
.
equal
(
actual
[
2
].
name
,
'
test1
'
);
});
function
aWorkspaceFolder
(
uri
:
URI
,
index
:
number
=
0
):
WorkspaceFolder
{
return
{
uri
,
raw
:
uri
.
fsPath
,
index
,
name
:
''
};
return
{
uri
,
raw
:
{
path
:
uri
.
fsPath
},
index
,
name
:
''
};
}
});
\ No newline at end of file
src/vs/platform/workspaces/electron-main/workspacesMainService.ts
浏览文件 @
1967cd3d
...
...
@@ -9,22 +9,20 @@ import { IWorkspacesMainService, IWorkspaceIdentifier, IStoredWorkspace, WORKSPA
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
isParent
}
from
'
vs/platform/files/common/files
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
extname
,
join
,
dirname
,
isAbsolute
,
resolve
,
relative
}
from
'
path
'
;
import
{
extname
,
join
,
dirname
,
isAbsolute
,
resolve
}
from
'
path
'
;
import
{
mkdirp
,
writeFile
,
readFile
}
from
'
vs/base/node/pfs
'
;
import
{
readFileSync
,
writeFileSync
,
existsSync
,
mkdirSync
}
from
'
fs
'
;
import
{
isLinux
,
isMacintosh
,
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
isLinux
,
isMacintosh
}
from
'
vs/base/common/platform
'
;
import
{
delSync
,
readdirSync
}
from
'
vs/base/node/extfs
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
isEqual
,
isEqualOrParent
,
normalize
}
from
'
vs/base/common/paths
'
;
import
{
isEqual
}
from
'
vs/base/common/paths
'
;
import
{
coalesce
}
from
'
vs/base/common/arrays
'
;
import
{
createHash
}
from
'
crypto
'
;
import
*
as
json
from
'
vs/base/common/json
'
;
import
*
as
jsonEdit
from
'
vs/base/common/jsonEdit
'
;
import
{
applyEdit
}
from
'
vs/base/common/jsonFormatter
'
;
import
{
normalizeDriveLetter
}
from
'
vs/base/common/labels
'
;
const
SLASH
=
'
/
'
;
import
{
massageFolderPathForWorkspace
}
from
'
vs/platform/workspaces/node/workspaces
'
;
export
class
WorkspacesMainService
implements
IWorkspacesMainService
{
...
...
@@ -198,18 +196,6 @@ export class WorkspacesMainService implements IWorkspacesMainService {
const
sourceConfigFolder
=
dirname
(
workspace
.
configPath
);
const
targetConfigFolder
=
dirname
(
targetConfigPath
);
// Determine which path separator to use:
// - macOS/Linux: slash
// - Windows: use slash if already used in that file
let
useSlashesForPath
=
!
isWindows
;
if
(
isWindows
)
{
storedWorkspace
.
folders
.
forEach
(
folder
=>
{
if
(
folder
.
path
.
indexOf
(
SLASH
)
>=
0
)
{
useSlashesForPath
=
true
;
}
});
}
// Rewrite absolute paths to relative paths if the target workspace folder
// is a parent of the location of the workspace file itself. Otherwise keep
// using absolute paths.
...
...
@@ -218,24 +204,7 @@ export class WorkspacesMainService implements IWorkspacesMainService {
folder
.
path
=
resolve
(
sourceConfigFolder
,
folder
.
path
);
// relative paths get resolved against the workspace location
}
if
(
isEqualOrParent
(
folder
.
path
,
targetConfigFolder
,
!
isLinux
))
{
folder
.
path
=
relative
(
targetConfigFolder
,
folder
.
path
)
||
'
.
'
;
// absolute paths get converted to relative ones to workspace location if possible
}
// Windows gets special treatment:
// - normalize all paths to get nice casing of drive letters
// - convert to slashes if we want to use slashes for paths
if
(
isWindows
)
{
if
(
isAbsolute
(
folder
.
path
))
{
if
(
useSlashesForPath
)
{
folder
.
path
=
normalize
(
folder
.
path
,
false
/* do not use OS path separator */
);
}
folder
.
path
=
normalizeDriveLetter
(
folder
.
path
);
}
else
if
(
useSlashesForPath
)
{
folder
.
path
=
folder
.
path
.
replace
(
/
[\\]
/g
,
SLASH
);
}
}
folder
.
path
=
massageFolderPathForWorkspace
(
folder
.
path
,
targetConfigFolder
,
storedWorkspace
.
folders
);
});
// Preserve as much of the existing workspace as possible by using jsonEdit
...
...
src/vs/platform/workspaces/node/workspaces.ts
0 → 100644
浏览文件 @
1967cd3d
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
IStoredWorkspaceFolder
}
from
'
vs/platform/workspaces/common/workspaces
'
;
import
{
isWindows
,
isLinux
}
from
'
vs/base/common/platform
'
;
import
{
isAbsolute
,
relative
}
from
'
path
'
;
import
{
isEqualOrParent
,
normalize
}
from
'
vs/base/common/paths
'
;
import
{
normalizeDriveLetter
}
from
'
vs/base/common/labels
'
;
const
SLASH
=
'
/
'
;
/**
* Given the absolute path to a folder, massage it in a way that it fits
* into an existing set of workspace folders of a workspace.
*
* @param absoluteFolderPath the absolute path of a workspace folder
* @param targetConfigFolder the folder where the workspace is living in
* @param existingFolders a set of existing folders of the workspace
*/
export
function
massageFolderPathForWorkspace
(
absoluteFolderPath
:
string
,
targetConfigFolder
:
string
,
existingFolders
:
IStoredWorkspaceFolder
[]):
string
{
const
useSlashesForPath
=
shouldUseSlashForPath
(
existingFolders
);
// Convert path to relative path if the target config folder
// is a parent of the path.
if
(
isEqualOrParent
(
absoluteFolderPath
,
targetConfigFolder
,
!
isLinux
))
{
absoluteFolderPath
=
relative
(
targetConfigFolder
,
absoluteFolderPath
)
||
'
.
'
;
}
// Windows gets special treatment:
// - normalize all paths to get nice casing of drive letters
// - convert to slashes if we want to use slashes for paths
if
(
isWindows
)
{
if
(
isAbsolute
(
absoluteFolderPath
))
{
if
(
useSlashesForPath
)
{
absoluteFolderPath
=
normalize
(
absoluteFolderPath
,
false
/* do not use OS path separator */
);
}
absoluteFolderPath
=
normalizeDriveLetter
(
absoluteFolderPath
);
}
else
if
(
useSlashesForPath
)
{
absoluteFolderPath
=
absoluteFolderPath
.
replace
(
/
[\\]
/g
,
SLASH
);
}
}
return
absoluteFolderPath
;
}
function
shouldUseSlashForPath
(
storedFolders
:
IStoredWorkspaceFolder
[]):
boolean
{
// Determine which path separator to use:
// - macOS/Linux: slash
// - Windows: use slash if already used in that file
let
useSlashesForPath
=
!
isWindows
;
if
(
isWindows
)
{
storedFolders
.
forEach
(
folder
=>
{
if
(
!
useSlashesForPath
&&
folder
.
path
.
indexOf
(
SLASH
)
>=
0
)
{
useSlashesForPath
=
true
;
}
});
}
return
useSlashesForPath
;
}
\ No newline at end of file
src/vs/platform/workspaces/test/electron-main/workspacesMainService.test.ts
浏览文件 @
1967cd3d
...
...
@@ -271,6 +271,32 @@ suite('WorkspacesMainService', () => {
});
});
test
(
'
saveWorkspace (saved workspace, preserves forward slashes)
'
,
done
=>
{
return
service
.
createWorkspace
([
process
.
cwd
(),
os
.
tmpdir
(),
path
.
join
(
os
.
tmpdir
(),
'
somefolder
'
)]).
then
(
workspace
=>
{
const
workspaceConfigPath
=
path
.
join
(
os
.
tmpdir
(),
`myworkspace.
${
Date
.
now
()}
.
${
WORKSPACE_EXTENSION
}
`
);
const
newWorkspaceConfigPath
=
path
.
join
(
os
.
tmpdir
(),
`mySavedWorkspace.
${
Date
.
now
()}
.
${
WORKSPACE_EXTENSION
}
`
);
return
service
.
saveWorkspace
(
workspace
,
workspaceConfigPath
).
then
(
savedWorkspace
=>
{
const
contents
=
fs
.
readFileSync
(
savedWorkspace
.
configPath
).
toString
();
fs
.
writeFileSync
(
savedWorkspace
.
configPath
,
contents
.
replace
(
/
[\\]
/g
,
'
/
'
));
// convert backslash to slash
return
service
.
saveWorkspace
(
savedWorkspace
,
newWorkspaceConfigPath
).
then
(
newSavedWorkspace
=>
{
assert
.
ok
(
newSavedWorkspace
.
id
);
assert
.
notEqual
(
newSavedWorkspace
.
id
,
workspace
.
id
);
assert
.
equal
(
newSavedWorkspace
.
configPath
,
newWorkspaceConfigPath
);
const
ws
=
JSON
.
parse
(
fs
.
readFileSync
(
newSavedWorkspace
.
configPath
).
toString
())
as
IStoredWorkspace
;
assert
.
ok
(
ws
.
folders
.
every
(
f
=>
f
.
path
.
indexOf
(
'
\\
'
)
<
0
));
extfs
.
delSync
(
workspaceConfigPath
);
extfs
.
delSync
(
newWorkspaceConfigPath
);
done
();
});
});
});
});
test
(
'
deleteUntitledWorkspaceSync (untitled)
'
,
done
=>
{
return
service
.
createWorkspace
([
process
.
cwd
(),
os
.
tmpdir
()]).
then
(
workspace
=>
{
assert
.
ok
(
fs
.
existsSync
(
workspace
.
configPath
));
...
...
src/vs/workbench/services/configuration/test/node/configuration.test.ts
浏览文件 @
1967cd3d
...
...
@@ -100,7 +100,7 @@ suite('WorkspaceContextService - Folder', () => {
assert
.
equal
(
actual
.
folders
[
0
].
uri
.
fsPath
,
workspaceResource
);
assert
.
equal
(
actual
.
folders
[
0
].
name
,
workspaceName
);
assert
.
equal
(
actual
.
folders
[
0
].
index
,
0
);
assert
.
equal
(
actual
.
folders
[
0
].
raw
,
workspaceResource
);
assert
.
equal
(
actual
.
folders
[
0
].
raw
.
path
,
workspaceResource
);
assert
.
ok
(
!
actual
.
configuration
);
});
...
...
src/vs/workbench/services/files/test/node/fileService.test.ts
浏览文件 @
1967cd3d
...
...
@@ -38,7 +38,7 @@ suite('FileService', () => {
return
onError
(
error
,
done
);
}
service
=
new
FileService
(
new
TestContextService
(
new
Workspace
(
testDir
,
testDir
,
[{
uri
:
uri
.
file
(
testDir
),
raw
:
testDir
,
index
:
0
,
name
:
''
}])),
new
TestTextResourceConfigurationService
(),
new
TestConfigurationService
(),
{
disableWatcher
:
true
});
service
=
new
FileService
(
new
TestContextService
(
new
Workspace
(
testDir
,
testDir
,
[{
uri
:
uri
.
file
(
testDir
),
raw
:
{
path
:
testDir
}
,
index
:
0
,
name
:
''
}])),
new
TestTextResourceConfigurationService
(),
new
TestConfigurationService
(),
{
disableWatcher
:
true
});
done
();
});
});
...
...
@@ -853,11 +853,11 @@ suite('FileService', () => {
});
});
function
aWorkspaceFolder
(
raw
:
string
,
index
:
number
,
name
:
string
=
''
):
WorkspaceFolder
{
function
aWorkspaceFolder
(
path
:
string
,
index
:
number
,
name
:
string
=
''
):
WorkspaceFolder
{
return
{
uri
:
uri
.
file
(
raw
),
uri
:
uri
.
file
(
path
),
index
,
raw
,
raw
:
{
path
:
path
}
,
name
};
}
...
...
src/vs/workbench/services/keybinding/test/node/keybindingEditing.test.ts
浏览文件 @
1967cd3d
...
...
@@ -74,7 +74,7 @@ suite('Keybindings Editing', () => {
instantiationService
.
stub
(
ITelemetryService
,
NullTelemetryService
);
instantiationService
.
stub
(
IModeService
,
ModeServiceImpl
);
instantiationService
.
stub
(
IModelService
,
instantiationService
.
createInstance
(
ModelServiceImpl
));
instantiationService
.
stub
(
IFileService
,
new
FileService
(
new
TestContextService
(
new
Workspace
(
testDir
,
testDir
,
[{
uri
:
uri
.
file
(
testDir
),
raw
:
testDir
,
index
:
0
,
name
:
''
}])),
new
TestTextResourceConfigurationService
(),
new
TestConfigurationService
(),
{
disableWatcher
:
true
}));
instantiationService
.
stub
(
IFileService
,
new
FileService
(
new
TestContextService
(
new
Workspace
(
testDir
,
testDir
,
[{
uri
:
uri
.
file
(
testDir
),
raw
:
{
path
:
testDir
}
,
index
:
0
,
name
:
''
}])),
new
TestTextResourceConfigurationService
(),
new
TestConfigurationService
(),
{
disableWatcher
:
true
}));
instantiationService
.
stub
(
IUntitledEditorService
,
instantiationService
.
createInstance
(
UntitledEditorService
));
instantiationService
.
stub
(
ITextFileService
,
instantiationService
.
createInstance
(
TestTextFileService
));
instantiationService
.
stub
(
ITextModelService
,
<
ITextModelService
>
instantiationService
.
createInstance
(
TextModelResolverService
));
...
...
src/vs/workbench/services/workspace/node/workspaceEditingService.ts
浏览文件 @
1967cd3d
...
...
@@ -7,16 +7,16 @@
import
{
IWorkspaceEditingService
}
from
'
vs/workbench/services/workspace/common/workspaceEditing
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
equals
,
distinct
}
from
'
vs/base/common/arrays
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IWorkspaceContextService
,
WorkbenchState
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IWindowsService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IJSONEditingService
}
from
'
vs/workbench/services/configuration/common/jsonEditing
'
;
import
{
IWorkspacesService
,
IStoredWorkspaceFolder
}
from
'
vs/platform/workspaces/common/workspaces
'
;
import
{
dirname
}
from
'
path
'
;
import
{
IWorkspaceConfigurationService
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
import
{
massageFolderPathForWorkspace
}
from
'
vs/platform/workspaces/node/workspaces
'
;
import
{
isLinux
}
from
'
vs/base/common/platform
'
;
import
{
dirname
,
relative
}
from
'
path
'
;
import
{
isEqualOrParent
}
from
'
vs/base/common/paths
'
;
export
class
WorkspaceEditingService
implements
IWorkspaceEditingService
{
...
...
@@ -27,7 +27,8 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
@
IWorkspaceContextService
private
contextService
:
IWorkspaceContextService
,
@
IEnvironmentService
private
environmentService
:
IEnvironmentService
,
@
IWindowsService
private
windowsService
:
IWindowsService
,
@
IWorkspacesService
private
workspacesService
:
IWorkspacesService
@
IWorkspacesService
private
workspacesService
:
IWorkspacesService
,
@
IWorkspaceConfigurationService
private
workspaceConfigurationService
:
IWorkspaceConfigurationService
)
{
}
...
...
@@ -36,9 +37,29 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
return
TPromise
.
as
(
void
0
);
// we need a workspace to begin with
}
const
folders
=
this
.
contextService
.
getWorkspace
().
folders
.
map
(
folder
=>
folder
.
uri
);
const
currentWorkspaceFolders
=
this
.
contextService
.
getWorkspace
().
folders
;
const
currentWorkspaceFolderUris
=
currentWorkspaceFolders
.
map
(
folder
=>
folder
.
uri
);
const
currentStoredFolders
=
currentWorkspaceFolders
.
map
(
folder
=>
folder
.
raw
);
return
this
.
doSetFolders
([...
folders
,
...
foldersToAdd
]);
const
storedFoldersToAdd
:
IStoredWorkspaceFolder
[]
=
[];
const
workspaceConfigFolder
=
dirname
(
this
.
contextService
.
getWorkspace
().
configuration
.
fsPath
);
foldersToAdd
.
forEach
(
foldersToAdd
=>
{
if
(
this
.
contains
(
currentWorkspaceFolderUris
,
foldersToAdd
))
{
return
;
// already existing
}
storedFoldersToAdd
.
push
({
path
:
massageFolderPathForWorkspace
(
foldersToAdd
.
fsPath
,
workspaceConfigFolder
,
currentStoredFolders
)
});
});
if
(
storedFoldersToAdd
.
length
>
0
)
{
return
this
.
doSetFolders
([...
currentStoredFolders
,
...
storedFoldersToAdd
]);
}
return
TPromise
.
as
(
void
0
);
}
public
removeFolders
(
foldersToRemove
:
URI
[]):
TPromise
<
void
>
{
...
...
@@ -46,54 +67,51 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
return
TPromise
.
as
(
void
0
);
// we need a workspace to begin with
}
const
f
olders
=
this
.
contextService
.
getWorkspace
().
folders
;
const
foldersToRemoveRaw
=
foldersToRemove
.
map
(
folder
=>
folder
.
toString
()
);
const
currentWorkspaceF
olders
=
this
.
contextService
.
getWorkspace
().
folders
;
const
currentStoredFolders
=
currentWorkspaceFolders
.
map
(
folder
=>
folder
.
raw
);
return
this
.
doSetFolders
(
folders
.
filter
(
folder
=>
foldersToRemoveRaw
.
indexOf
(
folder
.
uri
.
toString
())
===
-
1
).
map
(
folder
=>
folder
.
uri
));
}
const
newStoredFolders
:
IStoredWorkspaceFolder
[]
=
currentStoredFolders
.
filter
((
folder
,
index
)
=>
{
if
(
!
folder
.
path
)
{
return
true
;
// keep entries which are unrelated
}
private
isSupported
():
boolean
{
return
(
this
.
environmentService
.
appQuality
!==
'
stable
'
// not yet enabled in stable
&&
!!
this
.
contextService
.
getWorkspace
().
configuration
// we need a workspace configuration file to begin with
);
}
private
doSetFolders
(
newFolders
:
URI
[]):
TPromise
<
void
>
{
const
workspace
=
this
.
contextService
.
getWorkspace
();
const
currentWorkspaceFolders
=
this
.
contextService
.
getWorkspace
().
folders
.
map
(
folder
=>
folder
.
uri
.
fsPath
);
const
newWorkspaceFolders
=
this
.
validateFolders
(
newFolders
);
return
!
this
.
contains
(
foldersToRemove
,
currentWorkspaceFolders
[
index
].
uri
);
// keep entries which are unrelated
});
// See if there are any changes
if
(
equals
(
currentWorkspaceFolders
,
newWorkspaceFolders
))
{
return
TPromise
.
as
(
void
0
);
if
(
newStoredFolders
.
length
!==
currentStoredFolders
.
length
)
{
return
this
.
doSetFolders
(
newStoredFolders
);
}
// Apply to config
if
(
newWorkspaceFolders
.
length
)
{
const
workspaceConfigFolder
=
dirname
(
workspace
.
configuration
.
fsPath
);
const
value
:
IStoredWorkspaceFolder
[]
=
newWorkspaceFolders
.
map
(
newWorkspaceFolder
=>
{
if
(
isEqualOrParent
(
newWorkspaceFolder
,
workspaceConfigFolder
,
!
isLinux
))
{
newWorkspaceFolder
=
relative
(
workspaceConfigFolder
,
newWorkspaceFolder
)
||
'
.
'
;
// absolute paths get converted to relative ones to workspace location if possible
}
return
TPromise
.
as
(
void
0
);
}
return
{
path
:
newWorkspaceFolder
};
});
private
doSetFolders
(
folders
:
IStoredWorkspaceFolder
[]):
TPromise
<
void
>
{
if
(
folders
.
length
)
{
const
workspace
=
this
.
contextService
.
getWorkspace
();
return
this
.
jsonEditingService
.
write
(
workspace
.
configuration
,
{
key
:
'
folders
'
,
value
},
true
);
return
this
.
jsonEditingService
.
write
(
workspace
.
configuration
,
{
key
:
'
folders
'
,
value
:
folders
},
true
);
}
else
{
// TODO: Sandeep - Removing all folders?
}
return
TPromise
.
as
(
null
);
return
TPromise
.
as
(
void
0
);
}
private
validateFolders
(
folders
:
URI
[]):
string
[]
{
if
(
!
folders
)
{
return
[];
}
private
isSupported
():
boolean
{
// TODO@Ben multi root
return
(
this
.
environmentService
.
appQuality
!==
'
stable
'
// not yet enabled in stable
&&
this
.
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
WORKSPACE
// we need a multi folder workspace to begin with
);
}
private
contains
(
resources
:
URI
[],
toCheck
:
URI
):
boolean
{
return
resources
.
some
(
resource
=>
{
if
(
isLinux
)
{
return
resource
.
toString
()
===
toCheck
.
toString
();
}
// Prevent duplicates
return
distinct
(
folders
.
map
(
folder
=>
folder
.
fsPath
),
folder
=>
isLinux
?
folder
:
folder
.
toLowerCase
()
);
return
resource
.
toString
().
toLowerCase
()
===
toCheck
.
toString
().
toLowerCase
();
}
);
}
}
}
\ No newline at end of file
src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts
浏览文件 @
1967cd3d
...
...
@@ -16,6 +16,7 @@ import { ConfigurationModel } from 'vs/platform/configuration/common/configurati
import
{
TestThreadService
}
from
'
./testThreadService
'
;
import
{
mock
}
from
'
vs/workbench/test/electron-browser/api/mock
'
;
import
{
WorkspaceFolder
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IStoredWorkspaceFolder
}
from
'
vs/platform/workspaces/common/workspaces
'
;
suite
(
'
ExtHostConfiguration
'
,
function
()
{
...
...
@@ -132,7 +133,7 @@ suite('ExtHostConfiguration', function () {
new
class
extends
mock
<
MainThreadConfigurationShape
>
()
{
},
new
ExtHostWorkspace
(
new
TestThreadService
(),
{
'
id
'
:
'
foo
'
,
'
folders
'
:
[
aWorkspaceFolder
(
'
foo
'
,
0
)],
'
folders
'
:
[
aWorkspaceFolder
(
{
path
:
'
foo
'
}
,
0
)],
'
name
'
:
'
foo
'
}),
{
...
...
@@ -204,7 +205,7 @@ suite('ExtHostConfiguration', function () {
new
class
extends
mock
<
MainThreadConfigurationShape
>
()
{
},
new
ExtHostWorkspace
(
new
TestThreadService
(),
{
'
id
'
:
'
foo
'
,
'
folders
'
:
[
aWorkspaceFolder
(
firstRoot
.
path
,
0
),
aWorkspaceFolder
(
secondRoot
.
path
,
1
)],
'
folders
'
:
[
aWorkspaceFolder
(
{
path
:
firstRoot
.
path
},
0
),
aWorkspaceFolder
({
path
:
secondRoot
.
path
}
,
1
)],
'
name
'
:
'
foo
'
}),
{
...
...
@@ -404,9 +405,9 @@ suite('ExtHostConfiguration', function () {
.
then
(()
=>
assert
.
ok
(
false
),
err
=>
{
/* expecting rejection */
});
});
function
aWorkspaceFolder
(
raw
:
string
,
index
:
number
,
name
:
string
=
''
):
WorkspaceFolder
{
function
aWorkspaceFolder
(
raw
:
IStoredWorkspaceFolder
,
index
:
number
,
name
:
string
=
''
):
WorkspaceFolder
{
return
{
uri
:
URI
.
file
(
raw
),
uri
:
URI
.
file
(
raw
.
path
),
index
,
raw
,
name
...
...
src/vs/workbench/test/electron-browser/api/extHostWorkspace.test.ts
浏览文件 @
1967cd3d
...
...
@@ -199,7 +199,9 @@ suite('ExtHostWorkspace', function () {
return
{
uri
,
index
,
raw
:
uri
.
toString
(),
raw
:
{
path
:
uri
.
toString
()
},
name
:
name
||
basename
(
uri
.
path
)
};
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录