Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
5f0eaf63
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
5f0eaf63
编写于
7月 28, 2021
作者:
D
Daniel Imms
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix file scheme folder links in terminal
Fixes #129457
上级
e9fba4fc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
10 deletion
+83
-10
src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts
...nch/contrib/terminal/browser/links/terminalLinkManager.ts
+6
-1
src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts
...ib/terminal/browser/links/terminalProtocolLinkProvider.ts
+77
-9
未找到文件。
src/vs/workbench/contrib/terminal/browser/links/terminalLinkManager.ts
浏览文件 @
5f0eaf63
...
...
@@ -61,7 +61,12 @@ export class TerminalLinkManager extends DisposableStore {
// Protocol links
const
wrappedActivateCallback
=
this
.
_wrapLinkHandler
((
_
,
link
)
=>
this
.
_handleProtocolLink
(
link
));
const
protocolProvider
=
this
.
_instantiationService
.
createInstance
(
TerminalProtocolLinkProvider
,
this
.
_xterm
,
wrappedActivateCallback
,
this
.
_tooltipCallback
.
bind
(
this
));
const
protocolProvider
=
this
.
_instantiationService
.
createInstance
(
TerminalProtocolLinkProvider
,
this
.
_xterm
,
wrappedActivateCallback
,
this
.
_wrapLinkHandler
.
bind
(
this
),
this
.
_tooltipCallback
.
bind
(
this
),
async
(
link
,
cb
)
=>
cb
(
await
this
.
_resolvePath
(
link
)));
this
.
_standardLinkProviders
.
push
(
protocolProvider
);
// Validated local links
...
...
src/vs/workbench/contrib/terminal/browser/links/terminalProtocolLinkProvider.ts
浏览文件 @
5f0eaf63
...
...
@@ -6,11 +6,15 @@
import
type
{
Terminal
,
IViewportRange
,
IBufferLine
}
from
'
xterm
'
;
import
{
ILinkComputerTarget
,
LinkComputer
}
from
'
vs/editor/common/modes/linkComputer
'
;
import
{
getXtermLineContent
,
convertLinkRangeToBuffer
}
from
'
vs/workbench/contrib/terminal/browser/links/terminalLinkHelpers
'
;
import
{
TerminalLink
,
OPEN_FILE_LABEL
}
from
'
vs/workbench/contrib/terminal/browser/links/terminalLink
'
;
import
{
TerminalLink
,
OPEN_FILE_LABEL
,
FOLDER_IN_WORKSPACE_LABEL
,
FOLDER_NOT_IN_WORKSPACE_LABEL
}
from
'
vs/workbench/contrib/terminal/browser/links/terminalLink
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TerminalBaseLinkProvider
}
from
'
vs/workbench/contrib/terminal/browser/links/terminalBaseLinkProvider
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
XtermLinkMatcherHandler
}
from
'
vs/workbench/contrib/terminal/browser/links/terminalLinkManager
'
;
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IHostService
}
from
'
vs/workbench/services/host/browser/host
'
;
import
{
IUriIdentityService
}
from
'
vs/workbench/services/uriIdentity/common/uriIdentity
'
;
export
class
TerminalProtocolLinkProvider
extends
TerminalBaseLinkProvider
{
private
_linkComputerTarget
:
ILinkComputerTarget
|
undefined
;
...
...
@@ -18,13 +22,19 @@ export class TerminalProtocolLinkProvider extends TerminalBaseLinkProvider {
constructor
(
private
readonly
_xterm
:
Terminal
,
private
readonly
_activateCallback
:
(
event
:
MouseEvent
|
undefined
,
uri
:
string
)
=>
void
,
private
readonly
_wrapLinkHandler
:
(
handler
:
(
event
:
MouseEvent
|
undefined
,
link
:
string
)
=>
void
)
=>
XtermLinkMatcherHandler
,
private
readonly
_tooltipCallback
:
(
link
:
TerminalLink
,
viewportRange
:
IViewportRange
,
modifierDownCallback
?:
()
=>
void
,
modifierUpCallback
?:
()
=>
void
)
=>
void
,
@
IInstantiationService
private
readonly
_instantiationService
:
IInstantiationService
private
readonly
_validationCallback
:
(
link
:
string
,
callback
:
(
result
:
{
uri
:
URI
,
isDirectory
:
boolean
}
|
undefined
)
=>
void
)
=>
void
,
@
IInstantiationService
private
readonly
_instantiationService
:
IInstantiationService
,
@
ICommandService
private
readonly
_commandService
:
ICommandService
,
@
IWorkspaceContextService
private
readonly
_workspaceContextService
:
IWorkspaceContextService
,
@
IHostService
private
readonly
_hostService
:
IHostService
,
@
IUriIdentityService
private
readonly
_uriIdentityService
:
IUriIdentityService
)
{
super
();
}
protected
_provideLinks
(
y
:
number
):
TerminalLink
[]
{
protected
async
_provideLinks
(
y
:
number
):
Promise
<
TerminalLink
[]
>
{
let
startLine
=
y
-
1
;
let
endLine
=
startLine
;
...
...
@@ -45,16 +55,74 @@ export class TerminalProtocolLinkProvider extends TerminalBaseLinkProvider {
this
.
_linkComputerTarget
=
new
TerminalLinkAdapter
(
this
.
_xterm
,
startLine
,
endLine
);
const
links
=
LinkComputer
.
computeLinks
(
this
.
_linkComputerTarget
);
return
links
.
map
(
link
=>
{
const
range
=
convertLinkRangeToBuffer
(
lines
,
this
.
_xterm
.
cols
,
link
.
range
,
startLine
);
const
result
:
TerminalLink
[]
=
[];
for
(
const
link
of
links
)
{
const
bufferRange
=
convertLinkRangeToBuffer
(
lines
,
this
.
_xterm
.
cols
,
link
.
range
,
startLine
);
// Check if the link is within the mouse position
const
uri
=
link
.
url
?
(
typeof
link
.
url
===
'
string
'
?
URI
.
parse
(
link
.
url
)
:
link
.
url
)
:
undefined
;
const
label
=
(
uri
?.
scheme
===
Schemas
.
file
)
?
OPEN_FILE_LABEL
:
undefined
;
return
this
.
_instantiationService
.
createInstance
(
TerminalLink
,
this
.
_xterm
,
range
,
link
.
url
?.
toString
()
||
''
,
this
.
_xterm
.
buffer
.
active
.
viewportY
,
this
.
_activateCallback
,
this
.
_tooltipCallback
,
true
,
label
);
});
if
(
!
uri
)
{
continue
;
}
const
validatedLink
=
await
new
Promise
<
TerminalLink
|
undefined
>
(
r
=>
{
this
.
_validationCallback
(
uri
.
fsPath
,
(
result
)
=>
{
if
(
result
)
{
const
label
=
result
.
isDirectory
?
(
this
.
_isDirectoryInsideWorkspace
(
result
.
uri
)
?
FOLDER_IN_WORKSPACE_LABEL
:
FOLDER_NOT_IN_WORKSPACE_LABEL
)
:
OPEN_FILE_LABEL
;
const
activateCallback
=
this
.
_wrapLinkHandler
((
event
:
MouseEvent
|
undefined
,
text
:
string
)
=>
{
if
(
result
.
isDirectory
)
{
this
.
_handleLocalFolderLink
(
result
.
uri
);
}
else
{
this
.
_activateCallback
(
event
,
result
.
uri
.
path
);
}
});
r
(
this
.
_instantiationService
.
createInstance
(
TerminalLink
,
this
.
_xterm
,
bufferRange
,
uri
.
fsPath
,
this
.
_xterm
.
buffer
.
active
.
viewportY
,
activateCallback
,
this
.
_tooltipCallback
,
true
,
label
));
}
else
{
r
(
undefined
);
}
});
});
if
(
validatedLink
)
{
result
.
push
(
validatedLink
);
}
}
return
result
;
}
private
async
_handleLocalFolderLink
(
uri
:
URI
):
Promise
<
void
>
{
// If the folder is within one of the window's workspaces, focus it in the explorer
if
(
this
.
_isDirectoryInsideWorkspace
(
uri
))
{
await
this
.
_commandService
.
executeCommand
(
'
revealInExplorer
'
,
uri
);
return
;
}
// Open a new window for the folder
this
.
_hostService
.
openWindow
([{
folderUri
:
uri
}],
{
forceNewWindow
:
true
});
}
private
_isDirectoryInsideWorkspace
(
uri
:
URI
)
{
const
folders
=
this
.
_workspaceContextService
.
getWorkspace
().
folders
;
for
(
let
i
=
0
;
i
<
folders
.
length
;
i
++
)
{
if
(
this
.
_uriIdentityService
.
extUri
.
isEqualOrParent
(
uri
,
folders
[
i
].
uri
))
{
return
true
;
}
}
return
false
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录