Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e82d8bb6
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,发现更多精彩内容 >>
提交
e82d8bb6
编写于
2月 05, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Strict null checking goToDefinition
上级
8446e3fb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
32 deletion
+38
-32
src/vs/editor/browser/editorExtensions.ts
src/vs/editor/browser/editorExtensions.ts
+3
-3
src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts
...s/editor/contrib/goToDefinition/goToDefinitionCommands.ts
+23
-18
src/vs/editor/contrib/goToDefinition/goToDefinitionMouse.ts
src/vs/editor/contrib/goToDefinition/goToDefinitionMouse.ts
+12
-11
未找到文件。
src/vs/editor/browser/editorExtensions.ts
浏览文件 @
e82d8bb6
...
...
@@ -184,9 +184,9 @@ export interface IActionOptions extends ICommandOptions {
}
export
abstract
class
EditorAction
extends
EditorCommand
{
public
label
:
string
;
public
alias
:
string
;
private
menuOpts
:
IEditorCommandMenuOptions
|
undefined
;
public
readonly
label
:
string
;
public
readonly
alias
:
string
;
private
readonly
menuOpts
:
IEditorCommandMenuOptions
|
undefined
;
constructor
(
opts
:
IActionOptions
)
{
super
(
opts
);
...
...
src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts
浏览文件 @
e82d8bb6
...
...
@@ -51,6 +51,9 @@ export class DefinitionAction extends EditorAction {
}
public
run
(
accessor
:
ServicesAccessor
,
editor
:
ICodeEditor
):
Promise
<
void
>
{
if
(
!
editor
.
hasModel
())
{
return
Promise
.
resolve
(
undefined
);
}
const
notificationService
=
accessor
.
get
(
INotificationService
);
const
editorService
=
accessor
.
get
(
ICodeEditorService
);
const
progressService
=
accessor
.
get
(
IProgressService
);
...
...
@@ -112,14 +115,14 @@ export class DefinitionAction extends EditorAction {
return
getDefinitionsAtPosition
(
model
,
position
,
token
);
}
protected
_getNoResultFoundMessage
(
info
?:
IWordAtPosition
):
string
{
protected
_getNoResultFoundMessage
(
info
:
IWordAtPosition
|
null
):
string
{
return
info
&&
info
.
word
?
nls
.
localize
(
'
noResultWord
'
,
"
No definition found for '{0}'
"
,
info
.
word
)
:
nls
.
localize
(
'
generic.noResults
'
,
"
No definition found
"
);
}
protected
_getMetaTitle
(
model
:
ReferencesModel
):
string
{
return
model
.
references
.
length
>
1
&&
nls
.
localize
(
'
meta.title
'
,
"
– {0} definitions
"
,
model
.
references
.
length
)
;
return
model
.
references
.
length
>
1
?
nls
.
localize
(
'
meta.title
'
,
"
– {0} definitions
"
,
model
.
references
.
length
)
:
''
;
}
private
async
_onResult
(
editorService
:
ICodeEditorService
,
editor
:
ICodeEditor
,
model
:
ReferencesModel
):
Promise
<
void
>
{
...
...
@@ -129,21 +132,23 @@ export class DefinitionAction extends EditorAction {
if
(
this
.
_configuration
.
openInPeek
)
{
this
.
_openInPeek
(
editorService
,
editor
,
model
);
}
else
{
}
else
if
(
editor
.
hasModel
())
{
const
next
=
model
.
nearestReference
(
editor
.
getModel
().
uri
,
editor
.
getPosition
());
const
targetEditor
=
await
this
.
_openReference
(
editor
,
editorService
,
next
,
this
.
_configuration
.
openToSide
);
if
(
targetEditor
&&
model
.
references
.
length
>
1
)
{
this
.
_openInPeek
(
editorService
,
targetEditor
,
model
);
}
else
{
model
.
dispose
();
if
(
next
)
{
const
targetEditor
=
await
this
.
_openReference
(
editor
,
editorService
,
next
,
this
.
_configuration
.
openToSide
);
if
(
targetEditor
&&
model
.
references
.
length
>
1
)
{
this
.
_openInPeek
(
editorService
,
targetEditor
,
model
);
}
else
{
model
.
dispose
();
}
}
}
}
private
_openReference
(
editor
:
ICodeEditor
,
editorService
:
ICodeEditorService
,
reference
:
Location
|
LocationLink
,
sideBySide
:
boolean
):
Promise
<
ICodeEditor
>
{
private
_openReference
(
editor
:
ICodeEditor
,
editorService
:
ICodeEditorService
,
reference
:
Location
|
LocationLink
,
sideBySide
:
boolean
):
Promise
<
ICodeEditor
|
null
>
{
// range is the target-selection-range when we have one
// and the the fallback is the 'full' range
let
range
:
IRange
=
undefined
;
let
range
:
IRange
|
undefined
=
undefined
;
if
(
isLocationLink
(
reference
))
{
range
=
reference
.
targetSelectionRange
;
}
...
...
@@ -265,14 +270,14 @@ export class DeclarationAction extends DefinitionAction {
return
getDeclarationsAtPosition
(
model
,
position
,
token
);
}
protected
_getNoResultFoundMessage
(
info
?:
IWordAtPosition
):
string
{
protected
_getNoResultFoundMessage
(
info
:
IWordAtPosition
|
null
):
string
{
return
info
&&
info
.
word
?
nls
.
localize
(
'
decl.noResultWord
'
,
"
No declaration found for '{0}'
"
,
info
.
word
)
:
nls
.
localize
(
'
decl.generic.noResults
'
,
"
No declaration found
"
);
}
protected
_getMetaTitle
(
model
:
ReferencesModel
):
string
{
return
model
.
references
.
length
>
1
&&
nls
.
localize
(
'
decl.meta.title
'
,
"
– {0} declarations
"
,
model
.
references
.
length
)
;
return
model
.
references
.
length
>
1
?
nls
.
localize
(
'
decl.meta.title
'
,
"
– {0} declarations
"
,
model
.
references
.
length
)
:
''
;
}
}
...
...
@@ -295,14 +300,14 @@ export class GoToDeclarationAction extends DeclarationAction {
});
}
protected
_getNoResultFoundMessage
(
info
?:
IWordAtPosition
):
string
{
protected
_getNoResultFoundMessage
(
info
:
IWordAtPosition
|
null
):
string
{
return
info
&&
info
.
word
?
nls
.
localize
(
'
decl.noResultWord
'
,
"
No declaration found for '{0}'
"
,
info
.
word
)
:
nls
.
localize
(
'
decl.generic.noResults
'
,
"
No declaration found
"
);
}
protected
_getMetaTitle
(
model
:
ReferencesModel
):
string
{
return
model
.
references
.
length
>
1
&&
nls
.
localize
(
'
decl.meta.title
'
,
"
– {0} declarations
"
,
model
.
references
.
length
)
;
return
model
.
references
.
length
>
1
?
nls
.
localize
(
'
decl.meta.title
'
,
"
– {0} declarations
"
,
model
.
references
.
length
)
:
''
;
}
}
...
...
@@ -329,14 +334,14 @@ export class ImplementationAction extends DefinitionAction {
return
getImplementationsAtPosition
(
model
,
position
,
token
);
}
protected
_getNoResultFoundMessage
(
info
?:
IWordAtPosition
):
string
{
protected
_getNoResultFoundMessage
(
info
:
IWordAtPosition
|
null
):
string
{
return
info
&&
info
.
word
?
nls
.
localize
(
'
goToImplementation.noResultWord
'
,
"
No implementation found for '{0}'
"
,
info
.
word
)
:
nls
.
localize
(
'
goToImplementation.generic.noResults
'
,
"
No implementation found
"
);
}
protected
_getMetaTitle
(
model
:
ReferencesModel
):
string
{
return
model
.
references
.
length
>
1
&&
nls
.
localize
(
'
meta.implementations.title
'
,
"
– {0} implementations
"
,
model
.
references
.
length
)
;
return
model
.
references
.
length
>
1
?
nls
.
localize
(
'
meta.implementations.title
'
,
"
– {0} implementations
"
,
model
.
references
.
length
)
:
''
;
}
}
...
...
@@ -387,14 +392,14 @@ export class TypeDefinitionAction extends DefinitionAction {
return
getTypeDefinitionsAtPosition
(
model
,
position
,
token
);
}
protected
_getNoResultFoundMessage
(
info
?:
IWordAtPosition
):
string
{
protected
_getNoResultFoundMessage
(
info
:
IWordAtPosition
|
null
):
string
{
return
info
&&
info
.
word
?
nls
.
localize
(
'
goToTypeDefinition.noResultWord
'
,
"
No type definition found for '{0}'
"
,
info
.
word
)
:
nls
.
localize
(
'
goToTypeDefinition.generic.noResults
'
,
"
No type definition found
"
);
}
protected
_getMetaTitle
(
model
:
ReferencesModel
):
string
{
return
model
.
references
.
length
>
1
&&
nls
.
localize
(
'
meta.typeDefinitions.title
'
,
"
– {0} type definitions
"
,
model
.
references
.
length
)
;
return
model
.
references
.
length
>
1
?
nls
.
localize
(
'
meta.typeDefinitions.title
'
,
"
– {0} type definitions
"
,
model
.
references
.
length
)
:
''
;
}
}
...
...
src/vs/editor/contrib/goToDefinition/goToDefinitionMouse.ts
浏览文件 @
e82d8bb6
...
...
@@ -34,8 +34,8 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
private
editor
:
ICodeEditor
;
private
toUnhook
:
IDisposable
[];
private
decorations
:
string
[];
private
currentWordUnderMouse
:
IWordAtPosition
;
private
previousPromise
:
CancelablePromise
<
LocationLink
[]
>
;
private
currentWordUnderMouse
:
IWordAtPosition
|
null
;
private
previousPromise
:
CancelablePromise
<
LocationLink
[]
|
null
>
|
null
;
constructor
(
editor
:
ICodeEditor
,
...
...
@@ -51,7 +51,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
this
.
toUnhook
.
push
(
linkGesture
);
this
.
toUnhook
.
push
(
linkGesture
.
onMouseMoveOrRelevantKeyDown
(([
mouseEvent
,
keyboardEvent
])
=>
{
this
.
startFindDefinition
(
mouseEvent
,
keyboardEvent
);
this
.
startFindDefinition
(
mouseEvent
,
keyboardEvent
||
undefined
);
}));
this
.
toUnhook
.
push
(
linkGesture
.
onExecute
((
mouseEvent
:
ClickLinkMouseEvent
)
=>
{
...
...
@@ -79,20 +79,20 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
return
;
}
if
(
!
this
.
isEnabled
(
mouseEvent
,
withKey
))
{
if
(
!
this
.
editor
.
hasModel
()
||
!
this
.
isEnabled
(
mouseEvent
,
withKey
))
{
this
.
currentWordUnderMouse
=
null
;
this
.
removeDecorations
();
return
;
}
// Find word at mouse position
let
position
=
mouseEvent
.
target
.
position
;
let
word
=
position
?
this
.
editor
.
getModel
().
getWordAtPosition
(
position
)
:
null
;
const
word
=
mouseEvent
.
target
.
position
?
this
.
editor
.
getModel
().
getWordAtPosition
(
mouseEvent
.
target
.
position
)
:
null
;
if
(
!
word
)
{
this
.
currentWordUnderMouse
=
null
;
this
.
removeDecorations
();
return
;
}
const
position
=
mouseEvent
.
target
.
position
!
;
// Return early if word at position is still the same
if
(
this
.
currentWordUnderMouse
&&
this
.
currentWordUnderMouse
.
startColumn
===
word
.
startColumn
&&
this
.
currentWordUnderMouse
.
endColumn
===
word
.
endColumn
&&
this
.
currentWordUnderMouse
.
word
===
word
.
word
)
{
...
...
@@ -158,9 +158,10 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
wordRange
=
new
Range
(
position
.
lineNumber
,
word
.
startColumn
,
position
.
lineNumber
,
word
.
endColumn
);
}
const
modeId
=
this
.
modeService
.
getModeIdByFilepathOrFirstLine
(
textEditorModel
.
uri
.
fsPath
);
this
.
addDecoration
(
wordRange
,
new
MarkdownString
().
appendCodeblock
(
this
.
modeService
.
getModeIdByFilepathOrFirstLine
(
textEditorModel
.
uri
.
fsPath
)
,
previewValue
)
new
MarkdownString
().
appendCodeblock
(
modeId
?
modeId
:
''
,
previewValue
)
);
ref
.
dispose
();
});
...
...
@@ -274,10 +275,10 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
}
private
isEnabled
(
mouseEvent
:
ClickLinkMouseEvent
,
withKey
?:
ClickLinkKeyboardEvent
):
boolean
{
return
this
.
editor
.
get
Model
()
&&
return
this
.
editor
.
has
Model
()
&&
mouseEvent
.
isNoneOrSingleMouseDown
&&
(
mouseEvent
.
target
.
type
===
MouseTargetType
.
CONTENT_TEXT
)
&&
(
mouseEvent
.
hasTriggerModifier
||
(
withKey
&&
withKey
.
keyCodeIsTriggerKey
))
&&
(
mouseEvent
.
hasTriggerModifier
||
(
withKey
?
withKey
.
keyCodeIsTriggerKey
:
false
))
&&
DefinitionProviderRegistry
.
has
(
this
.
editor
.
getModel
());
}
...
...
@@ -287,11 +288,11 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
return
Promise
.
resolve
(
null
);
}
return
getDefinitionsAtPosition
(
model
,
target
.
position
,
token
);
return
getDefinitionsAtPosition
(
model
,
target
.
position
!
,
token
);
}
private
gotoDefinition
(
target
:
IMouseTarget
,
sideBySide
:
boolean
):
Promise
<
any
>
{
this
.
editor
.
setPosition
(
target
.
position
);
this
.
editor
.
setPosition
(
target
.
position
!
);
const
action
=
new
DefinitionAction
(
new
DefinitionActionConfig
(
sideBySide
,
false
,
true
,
false
),
{
alias
:
undefined
,
label
:
undefined
,
id
:
undefined
,
precondition
:
undefined
});
return
this
.
editor
.
invokeWithinContext
(
accessor
=>
action
.
run
(
accessor
,
this
.
editor
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录