Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
501156e3
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,发现更多精彩内容 >>
提交
501156e3
编写于
7月 26, 2018
作者:
I
isidor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uriDisplayService with tests
上级
742767ef
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
86 addition
and
28 deletion
+86
-28
src/vs/platform/uriDisplay/common/uriDisplay.ts
src/vs/platform/uriDisplay/common/uriDisplay.ts
+36
-28
src/vs/platform/uriDisplay/test/uriDisplay.test.ts
src/vs/platform/uriDisplay/test/uriDisplay.test.ts
+50
-0
未找到文件。
src/vs/platform/uriDisplay/common/uriDisplay.ts
浏览文件 @
501156e3
...
...
@@ -12,6 +12,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import
{
isEqual
,
basenameOrAuthority
}
from
'
vs/base/common/resources
'
;
import
{
isLinux
,
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
tildify
,
normalizeDriveLetter
}
from
'
vs/base/common/labels
'
;
import
{
ltrim
}
from
'
vs/base/common/strings
'
;
export
interface
IUriDisplayService
{
_serviceBrand
:
any
;
...
...
@@ -21,18 +22,20 @@ export interface IUriDisplayService {
export
interface
UriDisplayRules
{
label
:
string
;
// myLabel:/${path}
separator
:
'
/
'
|
'
\\
'
|
undefined
;
separator
:
'
/
'
|
'
\\
'
|
''
;
tildify
?:
boolean
;
normalizeDriveLetter
?:
boolean
;
}
const
URI_DISPLAY_SERVICE_ID
=
'
uriDisplay
'
;
const
sepRegexp
=
/
\/
/g
;
const
labelMatchingRegexp
=
/
\$\{
scheme
\}
|
\$\{
authority
\}
|
\$\{
path
\}
/g
;
function
hasDriveLetter
(
path
:
string
):
boolean
{
return
isWindows
&&
path
&&
path
[
1
]
===
'
:
'
;
}
class
UriDisplayService
implements
IUriDisplayService
{
export
class
UriDisplayService
implements
IUriDisplayService
{
_serviceBrand
:
any
;
private
formaters
=
new
Map
<
string
,
UriDisplayRules
>
();
...
...
@@ -46,28 +49,33 @@ class UriDisplayService implements IUriDisplayService {
if
(
!
resource
)
{
return
undefined
;
}
const
formater
=
this
.
formaters
.
get
(
resource
.
scheme
);
if
(
!
formater
)
{
return
resource
.
with
({
query
:
null
,
fragment
:
null
}).
toString
(
true
);
}
if
(
relative
)
{
const
hasMultipleRoots
=
this
.
contextService
.
getWorkspace
().
folders
.
length
>
1
;
const
baseResource
=
this
.
contextService
.
getWorkspaceFolder
(
resource
);
let
pathLabel
:
string
;
if
(
isEqual
(
baseResource
.
uri
,
resource
,
!
isLinux
))
{
pathLabel
=
''
;
// no label if paths are identical
}
else
{
const
baseResourceLabel
=
this
.
formatUri
(
baseResource
.
uri
);
pathLabel
=
this
.
formatUri
(
resource
).
substring
(
baseResourceLabel
.
length
);
}
if
(
hasMultipleRoots
)
{
const
rootName
=
(
baseResource
&&
baseResource
.
name
)
?
baseResource
.
name
:
basenameOrAuthority
(
baseResource
.
uri
);
pathLabel
=
pathLabel
?
(
rootName
+
'
•
'
+
pathLabel
)
:
rootName
;
// always show root basename if there are multiple
if
(
baseResource
)
{
let
relativeLabel
:
string
;
if
(
isEqual
(
baseResource
.
uri
,
resource
,
!
isLinux
))
{
relativeLabel
=
''
;
// no label if resources are identical
}
else
{
const
baseResourceLabel
=
this
.
formatUri
(
baseResource
.
uri
,
formater
);
relativeLabel
=
ltrim
(
this
.
formatUri
(
resource
,
formater
).
substring
(
baseResourceLabel
.
length
),
formater
.
separator
);
}
const
hasMultipleRoots
=
this
.
contextService
.
getWorkspace
().
folders
.
length
>
1
;
if
(
hasMultipleRoots
)
{
const
rootName
=
(
baseResource
&&
baseResource
.
name
)
?
baseResource
.
name
:
basenameOrAuthority
(
baseResource
.
uri
);
relativeLabel
=
relativeLabel
?
(
rootName
+
'
•
'
+
relativeLabel
)
:
rootName
;
// always show root basename if there are multiple
}
return
relativeLabel
;
}
return
pathLabel
;
}
return
this
.
formatUri
(
resource
);
return
this
.
formatUri
(
resource
,
formater
);
}
registerFormater
(
scheme
:
string
,
formater
:
UriDisplayRules
):
IDisposable
{
...
...
@@ -78,26 +86,26 @@ class UriDisplayService implements IUriDisplayService {
};
}
private
formatUri
(
resource
:
URI
):
string
{
const
formater
=
this
.
formaters
.
get
(
resource
.
scheme
);
if
(
!
formater
)
{
return
resource
.
with
({
query
:
null
,
fragment
:
null
}).
toString
(
true
);
}
// TODO@isidor transform
let
label
=
resource
.
path
;
private
formatUri
(
resource
:
URI
,
formater
:
UriDisplayRules
):
string
{
let
label
=
formater
.
label
.
replace
(
labelMatchingRegexp
,
match
=>
{
switch
(
match
)
{
case
'
${scheme}
'
:
return
resource
.
scheme
;
case
'
${authority}
'
:
return
resource
.
authority
;
case
'
${path}
'
:
return
resource
.
path
;
default
:
return
''
;
}
});
// convert c:\something => C:\something
if
(
formater
.
normalizeDriveLetter
&&
hasDriveLetter
(
label
))
{
label
=
normalizeDriveLetter
(
label
);
}
// normalize and tildify (macOS, Linux only)
if
(
formater
.
tildify
)
{
label
=
tildify
(
label
,
this
.
environmentService
.
userHome
);
}
return
label
;
return
label
.
replace
(
sepRegexp
,
formater
.
separator
)
;
}
}
...
...
src/vs/platform/uriDisplay/test/uriDisplay.test.ts
0 → 100644
浏览文件 @
501156e3
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
IUriDisplayService
,
UriDisplayService
}
from
'
vs/platform/uriDisplay/common/uriDisplay
'
;
import
{
TestEnvironmentService
,
TestContextService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
TestWorkspace
}
from
'
vs/platform/workspace/test/common/testWorkspace
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
nativeSep
}
from
'
vs/base/common/paths
'
;
import
{
isWindows
}
from
'
vs/base/common/platform
'
;
suite
(
'
URI Display
'
,
()
=>
{
let
uriDisplayService
:
IUriDisplayService
;
setup
(()
=>
{
uriDisplayService
=
new
UriDisplayService
(
TestEnvironmentService
,
new
TestContextService
());
});
test
(
'
file scheme
'
,
function
()
{
uriDisplayService
.
registerFormater
(
Schemas
.
file
,
{
label
:
'
${path}
'
,
separator
:
nativeSep
,
tildify
:
!
isWindows
,
normalizeDriveLetter
:
isWindows
});
const
uri1
=
TestWorkspace
.
folders
[
0
].
uri
.
with
({
path
:
TestWorkspace
.
folders
[
0
].
uri
.
path
.
concat
(
'
/a/b/c/d
'
)
});
assert
.
equal
(
uriDisplayService
.
getLabel
(
uri1
,
true
),
isWindows
?
'
a
\\
b
\\
c
\\
d
'
:
'
a/b/c/d
'
);
assert
.
equal
(
uriDisplayService
.
getLabel
(
uri1
,
false
),
isWindows
?
'
\\
testWorkspace
\\
a
\\
b
\\
c
\\
d
'
:
'
/testWorkspace/a/b/c/d
'
);
const
uri2
=
URI
.
file
(
'
c:
\\
1/2/3
'
);
assert
.
equal
(
uriDisplayService
.
getLabel
(
uri2
,
false
),
isWindows
?
'
C:
\\
1
\\
2
\\
3
'
:
'
/c:
\\
1/2/3
'
);
});
test
(
'
custom scheme
'
,
function
()
{
uriDisplayService
.
registerFormater
(
Schemas
.
vscode
,
{
label
:
'
LABEL/${path}/${authority}/END
'
,
separator
:
'
/
'
,
tildify
:
true
,
normalizeDriveLetter
:
true
});
const
uri1
=
URI
.
parse
(
'
vscode://microsoft.com/1/2/3/4/5
'
);
assert
.
equal
(
uriDisplayService
.
getLabel
(
uri1
,
false
),
'
LABEL//1/2/3/4/5/microsoft.com/END
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录