Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4fe0932f
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,发现更多精彩内容 >>
提交
4fe0932f
编写于
9月 04, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce implicit usage of Promise.cancel() (#56137)
上级
8a06f711
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
12 deletion
+43
-12
src/vs/editor/contrib/goToDefinition/goToDefinition.ts
src/vs/editor/contrib/goToDefinition/goToDefinition.ts
+29
-1
src/vs/editor/contrib/goToDefinition/goToDefinitionMouse.ts
src/vs/editor/contrib/goToDefinition/goToDefinitionMouse.ts
+14
-11
未找到文件。
src/vs/editor/contrib/goToDefinition/goToDefinition.ts
浏览文件 @
4fe0932f
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
{
flatten
,
coalesce
}
from
'
vs/base/common/arrays
'
;
import
{
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
asWinJsPromise
,
asThenable
}
from
'
vs/base/common/async
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
onUnexpectedExternalError
}
from
'
vs/base/common/errors
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
...
...
@@ -36,6 +36,28 @@ function getDefinitions<T>(
.
then
(
references
=>
coalesce
(
references
));
}
function
getDefinitions2
<
T
>
(
model
:
ITextModel
,
position
:
Position
,
registry
:
LanguageFeatureRegistry
<
T
>
,
provide
:
(
provider
:
T
,
model
:
ITextModel
,
position
:
Position
)
=>
DefinitionLink
|
DefinitionLink
[]
|
Thenable
<
DefinitionLink
|
DefinitionLink
[]
>
):
Thenable
<
DefinitionLink
[]
>
{
const
provider
=
registry
.
ordered
(
model
);
// get results
const
promises
=
provider
.
map
((
provider
):
Thenable
<
DefinitionLink
|
DefinitionLink
[]
>
=>
{
return
asThenable
(()
=>
{
return
provide
(
provider
,
model
,
position
);
}).
then
(
undefined
,
err
=>
{
onUnexpectedExternalError
(
err
);
return
null
;
});
});
return
TPromise
.
join
(
promises
)
.
then
(
flatten
)
.
then
(
references
=>
coalesce
(
references
));
}
export
function
getDefinitionsAtPosition
(
model
:
ITextModel
,
position
:
Position
):
TPromise
<
DefinitionLink
[]
>
{
return
getDefinitions
(
model
,
position
,
DefinitionProviderRegistry
,
(
provider
,
model
,
position
,
token
)
=>
{
...
...
@@ -43,6 +65,12 @@ export function getDefinitionsAtPosition(model: ITextModel, position: Position):
});
}
export
function
getDefinitionsAtPosition2
(
model
:
ITextModel
,
position
:
Position
,
token
:
CancellationToken
):
Thenable
<
DefinitionLink
[]
>
{
return
getDefinitions2
(
model
,
position
,
DefinitionProviderRegistry
,
(
provider
,
model
,
position
)
=>
{
return
provider
.
provideDefinition
(
model
,
position
,
token
);
});
}
export
function
getImplementationsAtPosition
(
model
:
ITextModel
,
position
:
Position
):
TPromise
<
DefinitionLink
[]
>
{
return
getDefinitions
(
model
,
position
,
ImplementationProviderRegistry
,
(
provider
,
model
,
position
,
token
)
=>
{
return
provider
.
provideImplementation
(
model
,
position
,
token
);
...
...
src/vs/editor/contrib/goToDefinition/goToDefinitionMouse.ts
浏览文件 @
4fe0932f
...
...
@@ -7,7 +7,8 @@
import
'
vs/css!./goToDefinitionMouse
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
Throttler
}
from
'
vs/base/common/async
'
;
import
{
createCancelablePromise
,
CancelablePromise
}
from
'
vs/base/common/async
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
MarkdownString
}
from
'
vs/base/common/htmlContent
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
...
...
@@ -17,7 +18,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import
{
DefinitionProviderRegistry
,
DefinitionLink
}
from
'
vs/editor/common/modes
'
;
import
{
ICodeEditor
,
IMouseTarget
,
MouseTargetType
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
registerEditorContribution
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
getDefinitionsAtPosition
}
from
'
./goToDefinition
'
;
import
{
getDefinitionsAtPosition
2
}
from
'
./goToDefinition
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
ITextModelService
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
registerThemingParticipant
}
from
'
vs/platform/theme/common/themeService
'
;
...
...
@@ -37,7 +38,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
private
toUnhook
:
IDisposable
[];
private
decorations
:
string
[];
private
currentWordUnderMouse
:
IWordAtPosition
;
private
throttler
:
Throttler
;
private
previousPromise
:
CancelablePromise
<
DefinitionLink
[]
>
;
constructor
(
editor
:
ICodeEditor
,
...
...
@@ -47,7 +48,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
this
.
toUnhook
=
[];
this
.
decorations
=
[];
this
.
editor
=
editor
;
this
.
throttler
=
new
Throttler
()
;
this
.
previousPromise
=
null
;
let
linkGesture
=
new
ClickLinkGesture
(
editor
);
this
.
toUnhook
.
push
(
linkGesture
);
...
...
@@ -100,12 +101,14 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
// Find definition and decorate word if found
let
state
=
new
EditorState
(
this
.
editor
,
CodeEditorStateFlag
.
Position
|
CodeEditorStateFlag
.
Value
|
CodeEditorStateFlag
.
Selection
|
CodeEditorStateFlag
.
Scroll
);
this
.
throttler
.
queue
(()
=>
{
return
state
.
validate
(
this
.
editor
)
?
this
.
findDefinition
(
mouseEvent
.
target
)
:
TPromise
.
wrap
<
DefinitionLink
[]
>
(
null
);
if
(
this
.
previousPromise
)
{
this
.
previousPromise
.
cancel
();
this
.
previousPromise
=
null
;
}
this
.
previousPromise
=
createCancelablePromise
(
token
=>
this
.
findDefinition
(
mouseEvent
.
target
,
token
));
})
.
then
(
results
=>
{
this
.
previousPromise
.
then
(
results
=>
{
if
(
!
results
||
!
results
.
length
||
!
state
.
validate
(
this
.
editor
))
{
this
.
removeDecorations
();
return
;
...
...
@@ -275,13 +278,13 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
DefinitionProviderRegistry
.
has
(
this
.
editor
.
getModel
());
}
private
findDefinition
(
target
:
IMouseTarget
):
TPromis
e
<
DefinitionLink
[]
>
{
private
findDefinition
(
target
:
IMouseTarget
,
token
:
CancellationToken
):
Thenabl
e
<
DefinitionLink
[]
>
{
const
model
=
this
.
editor
.
getModel
();
if
(
!
model
)
{
return
TPromise
.
as
(
null
);
}
return
getDefinitionsAtPosition
(
model
,
target
.
positio
n
);
return
getDefinitionsAtPosition
2
(
model
,
target
.
position
,
toke
n
);
}
private
gotoDefinition
(
target
:
IMouseTarget
,
sideBySide
:
boolean
):
TPromise
<
any
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录