Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
f2c2d9c6
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,发现更多精彩内容 >>
提交
f2c2d9c6
编写于
9月 25, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tweak URI to keep it compatible with gitlens, fyi @eamodio
上级
c43a66e7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
105 addition
and
92 deletion
+105
-92
src/vs/base/common/uri.ts
src/vs/base/common/uri.ts
+105
-92
未找到文件。
src/vs/base/common/uri.ts
浏览文件 @
f2c2d9c6
...
...
@@ -139,7 +139,7 @@ export default class URI {
* invalid characters and semantics. Will *not* look at the scheme of this URI.
*/
get
fsPath
():
string
{
throw
new
Error
(
'
not implemented
'
);
return
_makeFsPath
(
this
);
}
// ---- modify to new -------------------------
...
...
@@ -261,7 +261,7 @@ export default class URI {
* @param skipEncoding Do not encode the result, default is `false`
*/
public
toString
(
skipEncoding
:
boolean
=
false
):
string
{
throw
new
Error
(
'
not implemented
'
);
return
_asFormatted
(
this
,
skipEncoding
);
}
public
toJSON
():
any
{
...
...
@@ -308,6 +308,20 @@ export default class URI {
}
}
interface
UriComponents
{
scheme
:
string
;
authority
:
string
;
path
:
string
;
query
:
string
;
fragment
:
string
;
}
interface
UriState
extends
UriComponents
{
$mid
:
number
;
fsPath
:
string
;
external
:
string
;
}
// tslint:disable-next-line:class-name
class
_URI
extends
URI
{
...
...
@@ -317,21 +331,7 @@ class _URI extends URI {
get
fsPath
():
string
{
if
(
!
this
.
_fsPath
)
{
let
value
:
string
;
if
(
this
.
authority
&&
this
.
path
&&
this
.
scheme
===
'
file
'
)
{
// unc path: file://shares/c$/far/boo
value
=
`//
${
this
.
authority
}${
this
.
path
}
`
;
}
else
if
(
_driveLetterPath
.
test
(
this
.
path
))
{
// windows drive letter: file:///c:/far/boo
value
=
this
.
path
[
1
].
toLowerCase
()
+
this
.
path
.
substr
(
2
);
}
else
{
// other path
value
=
this
.
path
;
}
if
(
platform
.
isWindows
)
{
value
=
value
.
replace
(
/
\/
/g
,
'
\\
'
);
}
this
.
_fsPath
=
value
;
this
.
_fsPath
=
_makeFsPath
(
this
);
}
return
this
.
_fsPath
;
}
...
...
@@ -339,98 +339,111 @@ class _URI extends URI {
public
toString
(
skipEncoding
:
boolean
=
false
):
string
{
if
(
!
skipEncoding
)
{
if
(
!
this
.
_formatted
)
{
this
.
_formatted
=
_
URI
.
_
asFormatted
(
this
,
false
);
this
.
_formatted
=
_asFormatted
(
this
,
false
);
}
return
this
.
_formatted
;
}
else
{
// we don't cache that
return
_
URI
.
_
asFormatted
(
this
,
true
);
return
_asFormatted
(
this
,
true
);
}
}
}
private
static
_asFormatted
(
uri
:
URI
,
skipEncoding
:
boolean
):
string
{
/**
* Compute `fsPath` for the given uri
* @param uri
*/
function
_makeFsPath
(
uri
:
URI
):
string
{
let
value
:
string
;
if
(
uri
.
authority
&&
uri
.
path
&&
uri
.
scheme
===
'
file
'
)
{
// unc path: file://shares/c$/far/boo
value
=
`//
${
uri
.
authority
}${
uri
.
path
}
`
;
}
else
if
(
_driveLetterPath
.
test
(
uri
.
path
))
{
// windows drive letter: file:///c:/far/boo
value
=
uri
.
path
[
1
].
toLowerCase
()
+
uri
.
path
.
substr
(
2
);
}
else
{
// other path
value
=
uri
.
path
;
}
if
(
platform
.
isWindows
)
{
value
=
value
.
replace
(
/
\/
/g
,
'
\\
'
);
}
return
value
;
}
const
encoder
=
!
skipEncoding
?
encodeURIComponent2
:
encodeNoop
;
/**
* Create the external version of a uri
*/
function
_asFormatted
(
uri
:
URI
,
skipEncoding
:
boolean
):
string
{
const
parts
:
string
[]
=
[];
const
encoder
=
!
skipEncoding
?
encodeURIComponent2
:
encodeNoop
;
let
{
scheme
,
authority
,
path
,
query
,
fragment
}
=
uri
;
if
(
scheme
)
{
parts
.
push
(
scheme
,
'
:
'
);
}
if
(
authority
||
scheme
===
'
file
'
)
{
parts
.
push
(
'
//
'
);
}
if
(
authority
)
{
let
idx
=
authority
.
indexOf
(
'
@
'
);
if
(
idx
!==
-
1
)
{
const
userinfo
=
authority
.
substr
(
0
,
idx
);
authority
=
authority
.
substr
(
idx
+
1
);
idx
=
userinfo
.
indexOf
(
'
:
'
);
if
(
idx
===
-
1
)
{
parts
.
push
(
encoder
(
userinfo
));
}
else
{
parts
.
push
(
encoder
(
userinfo
.
substr
(
0
,
idx
)),
'
:
'
,
encoder
(
userinfo
.
substr
(
idx
+
1
)));
}
parts
.
push
(
'
@
'
);
}
authority
=
authority
.
toLowerCase
();
idx
=
authority
.
indexOf
(
'
:
'
);
const
parts
:
string
[]
=
[];
let
{
scheme
,
authority
,
path
,
query
,
fragment
}
=
uri
;
if
(
scheme
)
{
parts
.
push
(
scheme
,
'
:
'
);
}
if
(
authority
||
scheme
===
'
file
'
)
{
parts
.
push
(
'
//
'
);
}
if
(
authority
)
{
let
idx
=
authority
.
indexOf
(
'
@
'
);
if
(
idx
!==
-
1
)
{
const
userinfo
=
authority
.
substr
(
0
,
idx
);
authority
=
authority
.
substr
(
idx
+
1
);
idx
=
userinfo
.
indexOf
(
'
:
'
);
if
(
idx
===
-
1
)
{
parts
.
push
(
encoder
(
authority
));
parts
.
push
(
encoder
(
userinfo
));
}
else
{
parts
.
push
(
encoder
(
authority
.
substr
(
0
,
idx
)),
authority
.
substr
(
idx
));
parts
.
push
(
encoder
(
userinfo
.
substr
(
0
,
idx
)),
'
:
'
,
encoder
(
userinfo
.
substr
(
idx
+
1
)
));
}
parts
.
push
(
'
@
'
);
}
if
(
path
)
{
// lower-case windows drive letters in /C:/fff or C:/fff
const
m
=
_upperCaseDrive
.
exec
(
path
);
if
(
m
)
{
if
(
m
[
1
])
{
path
=
'
/
'
+
m
[
2
].
toLowerCase
()
+
path
.
substr
(
3
);
// "/c:".length === 3
}
else
{
path
=
m
[
2
].
toLowerCase
()
+
path
.
substr
(
2
);
// // "c:".length === 2
}
}
// encode every segement but not slashes
// make sure that # and ? are always encoded
// when occurring in paths - otherwise the result
// cannot be parsed back again
let
lastIdx
=
0
;
while
(
true
)
{
let
idx
=
path
.
indexOf
(
_slash
,
lastIdx
);
if
(
idx
===
-
1
)
{
parts
.
push
(
encoder
(
path
.
substring
(
lastIdx
)));
break
;
}
parts
.
push
(
encoder
(
path
.
substring
(
lastIdx
,
idx
)),
_slash
);
lastIdx
=
idx
+
1
;
};
}
if
(
query
)
{
parts
.
push
(
'
?
'
,
encoder
(
query
));
authority
=
authority
.
toLowerCase
();
idx
=
authority
.
indexOf
(
'
:
'
);
if
(
idx
===
-
1
)
{
parts
.
push
(
encoder
(
authority
));
}
else
{
parts
.
push
(
encoder
(
authority
.
substr
(
0
,
idx
)),
authority
.
substr
(
idx
));
}
if
(
fragment
)
{
parts
.
push
(
'
#
'
,
encoder
(
fragment
));
}
if
(
path
)
{
// lower-case windows drive letters in /C:/fff or C:/fff
const
m
=
_upperCaseDrive
.
exec
(
path
);
if
(
m
)
{
if
(
m
[
1
])
{
path
=
'
/
'
+
m
[
2
].
toLowerCase
()
+
path
.
substr
(
3
);
// "/c:".length === 3
}
else
{
path
=
m
[
2
].
toLowerCase
()
+
path
.
substr
(
2
);
// // "c:".length === 2
}
}
return
parts
.
join
(
_empty
);
// encode every segement but not slashes
// make sure that # and ? are always encoded
// when occurring in paths - otherwise the result
// cannot be parsed back again
let
lastIdx
=
0
;
while
(
true
)
{
let
idx
=
path
.
indexOf
(
_slash
,
lastIdx
);
if
(
idx
===
-
1
)
{
parts
.
push
(
encoder
(
path
.
substring
(
lastIdx
)));
break
;
}
parts
.
push
(
encoder
(
path
.
substring
(
lastIdx
,
idx
)),
_slash
);
lastIdx
=
idx
+
1
;
};
}
if
(
query
)
{
parts
.
push
(
'
?
'
,
encoder
(
query
));
}
if
(
fragment
)
{
parts
.
push
(
'
#
'
,
encoder
(
fragment
));
}
}
interface
UriComponents
{
scheme
:
string
;
authority
:
string
;
path
:
string
;
query
:
string
;
fragment
:
string
;
}
interface
UriState
extends
UriComponents
{
$mid
:
number
;
fsPath
:
string
;
external
:
string
;
return
parts
.
join
(
_empty
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录