Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f651ccac
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,发现更多精彩内容 >>
提交
f651ccac
编写于
11月 15, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extract openers
上级
0083c78a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
71 addition
and
72 deletion
+71
-72
src/vs/editor/browser/services/openerService.ts
src/vs/editor/browser/services/openerService.ts
+71
-72
未找到文件。
src/vs/editor/browser/services/openerService.ts
浏览文件 @
f651ccac
...
...
@@ -16,6 +16,71 @@ import { IOpener, IOpenerService, IValidator, IExternalUriResolver, OpenOptions,
import
{
EditorOpenContext
}
from
'
vs/platform/editor/common/editor
'
;
class
CommandOpener
implements
IOpener
{
constructor
(@
ICommandService
private
readonly
_commandService
:
ICommandService
)
{
}
async
open
(
target
:
URI
|
string
)
{
if
(
!
matchesScheme
(
target
,
Schemas
.
command
))
{
return
false
;
}
// run command or bail out if command isn't known
if
(
typeof
target
===
'
string
'
)
{
target
=
URI
.
parse
(
target
);
}
if
(
!
CommandsRegistry
.
getCommand
(
target
.
path
))
{
throw
new
Error
(
`command '
${
target
.
path
}
' NOT known`
);
}
// execute as command
let
args
:
any
=
[];
try
{
args
=
parse
(
target
.
query
);
if
(
!
Array
.
isArray
(
args
))
{
args
=
[
args
];
}
}
catch
(
e
)
{
// ignore error
}
await
this
.
_commandService
.
executeCommand
(
target
.
path
,
...
args
);
return
true
;
}
}
class
EditorOpener
implements
IOpener
{
constructor
(@
ICodeEditorService
private
readonly
_editorService
:
ICodeEditorService
)
{
}
async
open
(
target
:
URI
|
string
,
options
:
OpenOptions
)
{
if
(
typeof
target
===
'
string
'
)
{
target
=
URI
.
parse
(
target
);
}
let
selection
:
{
startLineNumber
:
number
;
startColumn
:
number
;
}
|
undefined
=
undefined
;
const
match
=
/^L
?(\d
+
)(?:
,
(\d
+
))?
/
.
exec
(
target
.
fragment
);
if
(
match
)
{
// support file:///some/file.js#73,84
// support file:///some/file.js#L73
selection
=
{
startLineNumber
:
parseInt
(
match
[
1
]),
startColumn
:
match
[
2
]
?
parseInt
(
match
[
2
])
:
1
};
// remove fragment
target
=
target
.
with
({
fragment
:
''
});
}
if
(
target
.
scheme
===
Schemas
.
file
)
{
target
=
normalizePath
(
target
);
// workaround for non-normalized paths (https://github.com/Microsoft/vscode/issues/12954)
}
await
this
.
_editorService
.
openCodeEditor
(
{
resource
:
target
,
options
:
{
selection
,
context
:
options
?.
fromUserGesture
?
EditorOpenContext
.
USER
:
EditorOpenContext
.
API
}
},
this
.
_editorService
.
getFocusedCodeEditor
(),
options
?.
openToSide
);
return
true
;
}
}
export
class
OpenerService
implements
IOpenerService
{
_serviceBrand
:
undefined
;
...
...
@@ -25,9 +90,6 @@ export class OpenerService implements IOpenerService {
private
readonly
_resolvers
=
new
LinkedList
<
IExternalUriResolver
>
();
private
_externalOpener
:
IExternalOpener
;
private
_openerAsExternal
:
IOpener
;
private
_openerAsCommand
:
IOpener
;
private
_openerAsEditor
:
IOpener
;
constructor
(
@
ICodeEditorService
editorService
:
ICodeEditorService
,
...
...
@@ -42,7 +104,7 @@ export class OpenerService implements IOpenerService {
};
// Default opener: maito, http(s), command, and catch-all-editors
this
.
_opener
AsExternal
=
{
this
.
_opener
s
.
push
(
{
open
:
async
(
target
:
URI
|
string
,
options
?:
OpenOptions
)
=>
{
if
(
options
?.
openExternal
||
matchesScheme
(
target
,
Schemas
.
mailto
)
||
matchesScheme
(
target
,
Schemas
.
http
)
||
matchesScheme
(
target
,
Schemas
.
https
))
{
// open externally
...
...
@@ -51,70 +113,13 @@ export class OpenerService implements IOpenerService {
}
return
false
;
}
};
this
.
_openerAsCommand
=
{
open
:
async
(
target
)
=>
{
if
(
!
matchesScheme
(
target
,
Schemas
.
command
))
{
return
false
;
}
// run command or bail out if command isn't known
if
(
typeof
target
===
'
string
'
)
{
target
=
URI
.
parse
(
target
);
}
if
(
!
CommandsRegistry
.
getCommand
(
target
.
path
))
{
throw
new
Error
(
`command '
${
target
.
path
}
' NOT known`
);
}
// execute as command
let
args
:
any
=
[];
try
{
args
=
parse
(
target
.
query
);
if
(
!
Array
.
isArray
(
args
))
{
args
=
[
args
];
}
}
catch
(
e
)
{
// ignore error
}
await
commandService
.
executeCommand
(
target
.
path
,
...
args
);
return
true
;
}
};
this
.
_openerAsEditor
=
{
open
:
async
(
target
,
options
:
OpenOptions
)
=>
{
if
(
typeof
target
===
'
string
'
)
{
target
=
URI
.
parse
(
target
);
}
let
selection
:
{
startLineNumber
:
number
;
startColumn
:
number
;
}
|
undefined
=
undefined
;
const
match
=
/^L
?(\d
+
)(?:
,
(\d
+
))?
/
.
exec
(
target
.
fragment
);
if
(
match
)
{
// support file:///some/file.js#73,84
// support file:///some/file.js#L73
selection
=
{
startLineNumber
:
parseInt
(
match
[
1
]),
startColumn
:
match
[
2
]
?
parseInt
(
match
[
2
])
:
1
};
// remove fragment
target
=
target
.
with
({
fragment
:
''
});
}
if
(
target
.
scheme
===
Schemas
.
file
)
{
target
=
normalizePath
(
target
);
// workaround for non-normalized paths (https://github.com/Microsoft/vscode/issues/12954)
}
await
editorService
.
openCodeEditor
(
{
resource
:
target
,
options
:
{
selection
,
context
:
options
?.
fromUserGesture
?
EditorOpenContext
.
USER
:
EditorOpenContext
.
API
}
},
editorService
.
getFocusedCodeEditor
(),
options
?.
openToSide
);
return
true
;
}
};
});
this
.
_openers
.
push
(
new
CommandOpener
(
commandService
));
this
.
_openers
.
push
(
new
EditorOpener
(
editorService
));
}
registerOpener
(
opener
:
IOpener
):
IDisposable
{
const
remove
=
this
.
_openers
.
push
(
opener
);
const
remove
=
this
.
_openers
.
unshift
(
opener
);
return
{
dispose
:
remove
};
}
...
...
@@ -149,13 +154,7 @@ export class OpenerService implements IOpenerService {
}
}
// use default openers
for
(
const
opener
of
[
this
.
_openerAsExternal
,
this
.
_openerAsCommand
,
this
.
_openerAsEditor
])
{
if
(
await
opener
.
open
(
target
,
options
))
{
break
;
}
}
return
true
;
return
false
;
}
async
resolveExternalUri
(
resource
:
URI
,
options
?:
ResolveExternalUriOptions
):
Promise
<
IResolvedExternalUri
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录