Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
67b30c0c
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,发现更多精彩内容 >>
未验证
提交
67b30c0c
编写于
2月 04, 2019
作者:
D
Daniel Imms
提交者:
GitHub
2月 04, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #67828 from hhu94/git-diff-links-simple
Add git diff terminal link handler
上级
e6d41395
fb4d028b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
24 deletion
+77
-24
src/vs/workbench/parts/terminal/electron-browser/terminalLinkHandler.ts
...ch/parts/terminal/electron-browser/terminalLinkHandler.ts
+45
-24
src/vs/workbench/parts/terminal/test/electron-browser/terminalLinkHandler.test.ts
...erminal/test/electron-browser/terminalLinkHandler.test.ts
+32
-0
未找到文件。
src/vs/workbench/parts/terminal/electron-browser/terminalLinkHandler.ts
浏览文件 @
67b30c0c
...
...
@@ -63,6 +63,9 @@ export class TerminalLinkHandler {
private
_widgetManager
:
TerminalWidgetManager
;
private
_processCwd
:
string
;
private
_localLinkPattern
:
RegExp
;
private
_gitDiffPreImagePattern
:
RegExp
;
private
_gitDiffPostImagePattern
:
RegExp
;
private
readonly
_tooltipCallback
:
(
event
:
MouseEvent
,
uri
:
string
)
=>
boolean
|
void
;
constructor
(
private
_xterm
:
any
,
...
...
@@ -75,8 +78,23 @@ export class TerminalLinkHandler {
const
baseLocalLinkClause
=
_platform
===
platform
.
Platform
.
Windows
?
winLocalLinkClause
:
unixLocalLinkClause
;
// Append line and column number regex
this
.
_localLinkPattern
=
new
RegExp
(
`
${
baseLocalLinkClause
}
(
${
lineAndColumnClause
}
)`
);
// Matches '--- a/src/file1', capturing 'src/file1' in group 1
this
.
_gitDiffPreImagePattern
=
/^--- a
\/(\S
*
)
/
;
// Matches '+++ b/src/file1', capturing 'src/file1' in group 1
this
.
_gitDiffPostImagePattern
=
/^
\+\+\+
b
\/(\S
*
)
/
;
this
.
_tooltipCallback
=
(
e
:
MouseEvent
)
=>
{
if
(
this
.
_terminalService
&&
this
.
_terminalService
.
configHelper
.
config
.
rendererType
===
'
dom
'
)
{
const
target
=
(
e
.
target
as
HTMLElement
);
this
.
_widgetManager
.
showMessage
(
target
.
offsetLeft
,
target
.
offsetTop
,
this
.
_getLinkHoverString
());
}
else
{
this
.
_widgetManager
.
showMessage
(
e
.
offsetX
,
e
.
offsetY
,
this
.
_getLinkHoverString
());
}
};
this
.
registerWebLinkHandler
();
this
.
registerLocalLinkHandler
();
this
.
registerGitDiffLinkHandlers
();
}
public
setWidgetManager
(
widgetManager
:
TerminalWidgetManager
):
void
{
...
...
@@ -90,14 +108,7 @@ export class TerminalLinkHandler {
public
registerCustomLinkHandler
(
regex
:
RegExp
,
handler
:
(
uri
:
string
)
=>
void
,
matchIndex
?:
number
,
validationCallback
?:
XtermLinkMatcherValidationCallback
):
number
{
const
options
:
ILinkMatcherOptions
=
{
matchIndex
,
tooltipCallback
:
(
e
:
MouseEvent
)
=>
{
if
(
this
.
_terminalService
&&
this
.
_terminalService
.
configHelper
.
config
.
rendererType
===
'
dom
'
)
{
const
target
=
(
e
.
target
as
HTMLElement
);
this
.
_widgetManager
.
showMessage
(
target
.
offsetLeft
,
target
.
offsetTop
,
this
.
_getLinkHoverString
());
}
else
{
this
.
_widgetManager
.
showMessage
(
e
.
offsetX
,
e
.
offsetY
,
this
.
_getLinkHoverString
());
}
},
tooltipCallback
:
this
.
_tooltipCallback
,
leaveCallback
:
()
=>
this
.
_widgetManager
.
closeMessage
(),
willLinkActivate
:
(
e
:
MouseEvent
)
=>
this
.
_isLinkActivationModifierDown
(
e
),
priority
:
CUSTOM_LINK_PRIORITY
...
...
@@ -114,14 +125,7 @@ export class TerminalLinkHandler {
});
this
.
_xterm
.
webLinksInit
(
wrappedHandler
,
{
validationCallback
:
(
uri
:
string
,
callback
:
(
isValid
:
boolean
)
=>
void
)
=>
this
.
_validateWebLink
(
uri
,
callback
),
tooltipCallback
:
(
e
:
MouseEvent
)
=>
{
if
(
this
.
_terminalService
&&
this
.
_terminalService
.
configHelper
.
config
.
rendererType
===
'
dom
'
)
{
const
target
=
(
e
.
target
as
HTMLElement
);
this
.
_widgetManager
.
showMessage
(
target
.
offsetLeft
,
target
.
offsetTop
,
this
.
_getLinkHoverString
());
}
else
{
this
.
_widgetManager
.
showMessage
(
e
.
offsetX
,
e
.
offsetY
,
this
.
_getLinkHoverString
());
}
},
tooltipCallback
:
this
.
_tooltipCallback
,
leaveCallback
:
()
=>
this
.
_widgetManager
.
closeMessage
(),
willLinkActivate
:
(
e
:
MouseEvent
)
=>
this
.
_isLinkActivationModifierDown
(
e
)
});
...
...
@@ -133,20 +137,29 @@ export class TerminalLinkHandler {
});
this
.
_xterm
.
registerLinkMatcher
(
this
.
_localLinkRegex
,
wrappedHandler
,
{
validationCallback
:
(
uri
:
string
,
callback
:
(
isValid
:
boolean
)
=>
void
)
=>
this
.
_validateLocalLink
(
uri
,
callback
),
tooltipCallback
:
(
e
:
MouseEvent
)
=>
{
if
(
this
.
_terminalService
&&
this
.
_terminalService
.
configHelper
.
config
.
rendererType
===
'
dom
'
)
{
const
target
=
(
e
.
target
as
HTMLElement
);
this
.
_widgetManager
.
showMessage
(
target
.
offsetLeft
,
target
.
offsetTop
,
this
.
_getLinkHoverString
());
}
else
{
this
.
_widgetManager
.
showMessage
(
e
.
offsetX
,
e
.
offsetY
,
this
.
_getLinkHoverString
());
}
},
tooltipCallback
:
this
.
_tooltipCallback
,
leaveCallback
:
()
=>
this
.
_widgetManager
.
closeMessage
(),
willLinkActivate
:
(
e
:
MouseEvent
)
=>
this
.
_isLinkActivationModifierDown
(
e
),
priority
:
LOCAL_LINK_PRIORITY
});
}
public
registerGitDiffLinkHandlers
():
void
{
const
wrappedHandler
=
this
.
_wrapLinkHandler
(
url
=>
{
this
.
_handleLocalLink
(
url
);
});
const
options
=
{
matchIndex
:
1
,
validationCallback
:
(
uri
:
string
,
callback
:
(
isValid
:
boolean
)
=>
void
)
=>
this
.
_validateLocalLink
(
uri
,
callback
),
tooltipCallback
:
this
.
_tooltipCallback
,
leaveCallback
:
()
=>
this
.
_widgetManager
.
closeMessage
(),
willLinkActivate
:
(
e
:
MouseEvent
)
=>
this
.
_isLinkActivationModifierDown
(
e
),
priority
:
LOCAL_LINK_PRIORITY
};
this
.
_xterm
.
registerLinkMatcher
(
this
.
_gitDiffPreImagePattern
,
wrappedHandler
,
options
);
this
.
_xterm
.
registerLinkMatcher
(
this
.
_gitDiffPostImagePattern
,
wrappedHandler
,
options
);
}
public
dispose
():
void
{
this
.
_xterm
=
null
;
this
.
_hoverDisposables
=
dispose
(
this
.
_hoverDisposables
);
...
...
@@ -172,6 +185,14 @@ export class TerminalLinkHandler {
return
this
.
_localLinkPattern
;
}
protected
get
_gitDiffPreImageRegex
():
RegExp
{
return
this
.
_gitDiffPreImagePattern
;
}
protected
get
_gitDiffPostImageRegex
():
RegExp
{
return
this
.
_gitDiffPostImagePattern
;
}
private
_handleLocalLink
(
link
:
string
):
PromiseLike
<
any
>
{
return
this
.
_resolvePath
(
link
).
then
(
resolvedLink
=>
{
if
(
!
resolvedLink
)
{
...
...
src/vs/workbench/parts/terminal/test/electron-browser/terminalLinkHandler.test.ts
浏览文件 @
67b30c0c
...
...
@@ -14,6 +14,12 @@ class TestTerminalLinkHandler extends TerminalLinkHandler {
public
get
localLinkRegex
():
RegExp
{
return
this
.
_localLinkRegex
;
}
public
get
gitDiffLinkPreImageRegex
():
RegExp
{
return
this
.
_gitDiffPreImageRegex
;
}
public
get
gitDiffLinkPostImageRegex
():
RegExp
{
return
this
.
_gitDiffPostImageRegex
;
}
public
preprocessPath
(
link
:
string
):
string
|
null
{
return
this
.
_preprocessPath
(
link
);
}
...
...
@@ -217,4 +223,30 @@ suite('Workbench - TerminalLinkHandler', () => {
assert
.
equal
(
linkHandler
.
preprocessPath
(
'
/absolute/path/file3
'
),
'
/absolute/path/file3
'
);
});
});
test
(
'
gitDiffLinkRegex
'
,
()
=>
{
// The platform is irrelevant because the links generated by Git are the same format regardless of platform
const
linkHandler
=
new
TestTerminalLinkHandler
(
new
TestXterm
(),
Platform
.
Linux
,
null
!
,
null
!
,
null
!
,
null
!
);
function
assertAreGoodMatches
(
matches
:
RegExpMatchArray
|
null
)
{
if
(
matches
)
{
assert
.
equal
(
matches
.
length
,
2
);
assert
.
equal
(
matches
[
1
],
'
src/file1
'
);
}
else
{
assert
.
fail
();
}
}
// Happy cases
assertAreGoodMatches
(
'
--- a/src/file1
'
.
match
(
linkHandler
.
gitDiffLinkPreImageRegex
));
assertAreGoodMatches
(
'
--- a/src/file1
'
.
match
(
linkHandler
.
gitDiffLinkPreImageRegex
));
assertAreGoodMatches
(
'
+++ b/src/file1
'
.
match
(
linkHandler
.
gitDiffLinkPostImageRegex
));
assertAreGoodMatches
(
'
+++ b/src/file1
'
.
match
(
linkHandler
.
gitDiffLinkPostImageRegex
));
// Make sure /dev/null isn't a match
assert
.
equal
(
linkHandler
.
gitDiffLinkPreImageRegex
.
test
(
'
--- /dev/null
'
),
false
);
assert
.
equal
(
linkHandler
.
gitDiffLinkPreImageRegex
.
test
(
'
--- /dev/null
'
),
false
);
assert
.
equal
(
linkHandler
.
gitDiffLinkPostImageRegex
.
test
(
'
+++ /dev/null
'
),
false
);
assert
.
equal
(
linkHandler
.
gitDiffLinkPostImageRegex
.
test
(
'
+++ /dev/null
'
),
false
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录