Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a1543727
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a1543727
编写于
7月 28, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #31553
上级
281cf393
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
6 deletion
+35
-6
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+5
-2
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+2
-2
src/vs/workbench/api/node/extHostWorkspace.ts
src/vs/workbench/api/node/extHostWorkspace.ts
+6
-2
src/vs/workbench/test/electron-browser/api/extHostWorkspace.test.ts
...kbench/test/electron-browser/api/extHostWorkspace.test.ts
+22
-0
未找到文件。
src/vs/vscode.d.ts
浏览文件 @
a1543727
...
...
@@ -4739,12 +4739,15 @@ declare module 'vscode' {
* Returns a path that is relative to the workspace folder or folders.
*
* When there are no [workspace folders](#workspace.workspaceFolders) or when the path
* is not
a child of
them, the input is returned.
* is not
contained in
them, the input is returned.
*
* @param pathOrUri A path or uri. When a uri is given its [fsPath](#Uri.fsPath) is used.
* @param includeWorkspaceFolder When `true` and when the given path is contained inside a
* workspace folder the name of the workspace is prepended. Defaults to `true` when there are
* multiple workspace folders and `false` otherwise.
* @return A path relative to the root or the input.
*/
export
function
asRelativePath
(
pathOrUri
:
string
|
Uri
):
string
;
export
function
asRelativePath
(
pathOrUri
:
string
|
Uri
,
includeWorkspaceFolder
?:
boolean
):
string
;
/**
* Creates a file system watcher.
...
...
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
a1543727
...
...
@@ -386,8 +386,8 @@ export function createApiFactory(
apiUsage
.
publicLog
(
'
workspace#onDidChangeWorkspaceFolders
'
);
return
extHostWorkspace
.
onDidChangeWorkspace
(
listener
,
thisArgs
,
disposables
);
},
asRelativePath
:
(
pathOrUri
)
=>
{
return
extHostWorkspace
.
getRelativePath
(
pathOrUri
);
asRelativePath
:
(
pathOrUri
,
includeWorkspace
)
=>
{
return
extHostWorkspace
.
getRelativePath
(
pathOrUri
,
includeWorkspace
);
},
findFiles
:
(
include
,
exclude
,
maxResults
?,
token
?)
=>
{
return
extHostWorkspace
.
findFiles
(
include
,
exclude
,
maxResults
,
token
);
...
...
src/vs/workbench/api/node/extHostWorkspace.ts
浏览文件 @
a1543727
...
...
@@ -117,7 +117,7 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
return
roots
[
0
].
fsPath
;
}
getRelativePath
(
pathOrUri
:
string
|
vscode
.
Uri
):
string
{
getRelativePath
(
pathOrUri
:
string
|
vscode
.
Uri
,
includeWorkspace
?:
boolean
):
string
{
let
path
:
string
;
if
(
typeof
pathOrUri
===
'
string
'
)
{
...
...
@@ -139,8 +139,12 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
return
normalize
(
path
);
}
if
(
typeof
includeWorkspace
===
'
undefined
'
)
{
includeWorkspace
=
this
.
workspace
.
roots
.
length
>
1
;
}
let
result
=
relative
(
folder
.
uri
.
fsPath
,
path
);
if
(
this
.
workspace
.
roots
.
length
>
1
)
{
if
(
includeWorkspace
)
{
result
=
`
${
folder
.
name
}
/
${
result
}
`
;
}
return
normalize
(
result
);
...
...
src/vs/workbench/test/electron-browser/api/extHostWorkspace.test.ts
浏览文件 @
a1543727
...
...
@@ -49,6 +49,28 @@ suite('ExtHostWorkspace', function () {
assert
.
equal
(
ws
.
getRelativePath
(
'
/Coding/Two2/files/out.txt
'
),
'
/Coding/Two2/files/out.txt
'
);
});
test
(
'
slightly inconsistent behaviour of asRelativePath and getWorkspaceFolder, #31553
'
,
function
()
{
const
mrws
=
new
ExtHostWorkspace
(
new
TestThreadService
(),
{
id
:
'
foo
'
,
roots
:
[
URI
.
file
(
'
/Coding/One
'
),
URI
.
file
(
'
/Coding/Two
'
)],
name
:
'
Test
'
});
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/One/file.txt
'
),
'
One/file.txt
'
);
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/One/file.txt
'
,
true
),
'
One/file.txt
'
);
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/One/file.txt
'
,
false
),
'
file.txt
'
);
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/Two/files/out.txt
'
),
'
Two/files/out.txt
'
);
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/Two/files/out.txt
'
,
true
),
'
Two/files/out.txt
'
);
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/Two/files/out.txt
'
,
false
),
'
files/out.txt
'
);
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/Two2/files/out.txt
'
),
'
/Coding/Two2/files/out.txt
'
);
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/Two2/files/out.txt
'
,
true
),
'
/Coding/Two2/files/out.txt
'
);
assert
.
equal
(
mrws
.
getRelativePath
(
'
/Coding/Two2/files/out.txt
'
,
false
),
'
/Coding/Two2/files/out.txt
'
);
const
srws
=
new
ExtHostWorkspace
(
new
TestThreadService
(),
{
id
:
'
foo
'
,
roots
:
[
URI
.
file
(
'
/Coding/One
'
)],
name
:
'
Test
'
});
assert
.
equal
(
srws
.
getRelativePath
(
'
/Coding/One/file.txt
'
),
'
file.txt
'
);
assert
.
equal
(
srws
.
getRelativePath
(
'
/Coding/One/file.txt
'
,
false
),
'
file.txt
'
);
assert
.
equal
(
srws
.
getRelativePath
(
'
/Coding/One/file.txt
'
,
true
),
'
One/file.txt
'
);
assert
.
equal
(
srws
.
getRelativePath
(
'
/Coding/Two2/files/out.txt
'
),
'
/Coding/Two2/files/out.txt
'
);
assert
.
equal
(
srws
.
getRelativePath
(
'
/Coding/Two2/files/out.txt
'
,
true
),
'
/Coding/Two2/files/out.txt
'
);
assert
.
equal
(
srws
.
getRelativePath
(
'
/Coding/Two2/files/out.txt
'
,
false
),
'
/Coding/Two2/files/out.txt
'
);
});
test
(
'
getPath, legacy
'
,
function
()
{
let
ws
=
new
ExtHostWorkspace
(
new
TestThreadService
(),
{
id
:
'
foo
'
,
name
:
'
Test
'
,
roots
:
[]
});
assert
.
equal
(
ws
.
getPath
(),
undefined
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录