Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
98ea8943
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,体验更适合开发者的 AI 搜索 >>
提交
98ea8943
编写于
4月 03, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more and better cancellation token sources
上级
c3d0e7a9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
24 addition
and
24 deletion
+24
-24
src/vs/editor/browser/core/editorState.ts
src/vs/editor/browser/core/editorState.ts
+12
-6
src/vs/editor/contrib/codeAction/codeAction.ts
src/vs/editor/contrib/codeAction/codeAction.ts
+1
-3
src/vs/editor/contrib/documentSymbols/outlineModel.ts
src/vs/editor/contrib/documentSymbols/outlineModel.ts
+4
-6
src/vs/editor/contrib/format/format.ts
src/vs/editor/contrib/format/format.ts
+7
-9
未找到文件。
src/vs/editor/browser/core/editorState.ts
浏览文件 @
98ea8943
...
...
@@ -7,7 +7,7 @@ import * as strings from 'vs/base/common/strings';
import
{
ICodeEditor
,
IActiveCodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
CancellationTokenSource
,
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
...
...
@@ -74,13 +74,16 @@ export class EditorState {
}
}
/**
* A cancellation token source that cancels when the editor changes as expressed
* by the provided flags
*/
export
class
EditorStateCancellationTokenSource
extends
CancellationTokenSource
{
private
readonly
_listener
:
IDisposable
[]
=
[];
constructor
(
readonly
editor
:
IActiveCodeEditor
,
flags
:
CodeEditorStateFlag
)
{
super
();
constructor
(
readonly
editor
:
IActiveCodeEditor
,
flags
:
CodeEditorStateFlag
,
parent
?:
CancellationToken
)
{
super
(
parent
);
if
(
flags
&
CodeEditorStateFlag
.
Position
)
{
this
.
_listener
.
push
(
editor
.
onDidChangeCursorPosition
(
_
=>
this
.
cancel
()));
...
...
@@ -103,12 +106,15 @@ export class EditorStateCancellationTokenSource extends CancellationTokenSource
}
}
/**
* A cancellation token source that cancels when the provided model changes
*/
export
class
TextModelCancellationTokenSource
extends
CancellationTokenSource
{
private
_listener
:
IDisposable
;
constructor
(
model
:
ITextModel
)
{
super
();
constructor
(
model
:
ITextModel
,
parent
?:
CancellationToken
)
{
super
(
parent
);
this
.
_listener
=
model
.
onDidChangeContent
(()
=>
this
.
cancel
());
}
...
...
src/vs/editor/contrib/codeAction/codeAction.ts
浏览文件 @
98ea8943
...
...
@@ -56,9 +56,7 @@ export function getCodeActions(
trigger
:
trigger
.
type
===
'
manual
'
?
CodeActionTriggerKind
.
Manual
:
CodeActionTriggerKind
.
Automatic
};
const
cts
=
new
TextModelCancellationTokenSource
(
model
);
token
.
onCancellationRequested
(()
=>
cts
.
cancel
());
const
cts
=
new
TextModelCancellationTokenSource
(
model
,
token
);
const
providers
=
getCodeActionProviders
(
model
,
filter
);
const
promises
=
providers
.
map
(
provider
=>
{
...
...
src/vs/editor/contrib/documentSymbols/outlineModel.ts
浏览文件 @
98ea8943
...
...
@@ -274,9 +274,7 @@ export class OutlineModel extends TreeElement {
static
_create
(
textModel
:
ITextModel
,
token
:
CancellationToken
):
Promise
<
OutlineModel
>
{
const
chainedCancellation
=
new
CancellationTokenSource
();
token
.
onCancellationRequested
(()
=>
chainedCancellation
.
cancel
());
const
cts
=
new
CancellationTokenSource
(
token
);
const
result
=
new
OutlineModel
(
textModel
);
const
provider
=
DocumentSymbolProviderRegistry
.
ordered
(
textModel
);
const
promises
=
provider
.
map
((
provider
,
index
)
=>
{
...
...
@@ -284,7 +282,7 @@ export class OutlineModel extends TreeElement {
let
id
=
TreeElement
.
findId
(
`provider_
${
index
}
`
,
result
);
let
group
=
new
OutlineGroup
(
id
,
result
,
provider
,
index
);
return
Promise
.
resolve
(
provider
.
provideDocumentSymbols
(
result
.
textModel
,
c
hainedCancellation
.
token
)).
then
(
result
=>
{
return
Promise
.
resolve
(
provider
.
provideDocumentSymbols
(
result
.
textModel
,
c
ts
.
token
)).
then
(
result
=>
{
for
(
const
info
of
result
||
[])
{
OutlineModel
.
_makeOutlineElement
(
info
,
group
);
}
...
...
@@ -304,12 +302,12 @@ export class OutlineModel extends TreeElement {
const
listener
=
DocumentSymbolProviderRegistry
.
onDidChange
(()
=>
{
const
newProvider
=
DocumentSymbolProviderRegistry
.
ordered
(
textModel
);
if
(
!
equals
(
newProvider
,
provider
))
{
c
hainedCancellation
.
cancel
();
c
ts
.
cancel
();
}
});
return
Promise
.
all
(
promises
).
then
(()
=>
{
if
(
c
hainedCancellation
.
token
.
isCancellationRequested
&&
!
token
.
isCancellationRequested
)
{
if
(
c
ts
.
token
.
isCancellationRequested
&&
!
token
.
isCancellationRequested
)
{
return
OutlineModel
.
_create
(
textModel
,
token
);
}
else
{
return
result
.
_compact
();
...
...
src/vs/editor/contrib/format/format.ts
浏览文件 @
98ea8943
...
...
@@ -5,10 +5,10 @@
import
{
alert
}
from
'
vs/base/browser/ui/aria/aria
'
;
import
{
isNonEmptyArray
}
from
'
vs/base/common/arrays
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
CancellationToken
,
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
illegalArgument
,
onUnexpectedExternalError
}
from
'
vs/base/common/errors
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
CodeEditorStateFlag
,
EditorState
}
from
'
vs/editor/browser/core/editorState
'
;
import
{
CodeEditorStateFlag
,
EditorState
,
EditorStateCancellationTokenSource
,
TextModelCancellationTokenSource
}
from
'
vs/editor/browser/core/editorState
'
;
import
{
IActiveCodeEditor
,
isCodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
registerLanguageCommand
,
ServicesAccessor
}
from
'
vs/editor/browser/editorExtensions
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
...
...
@@ -227,26 +227,24 @@ export async function formatDocumentWithProvider(
const
workerService
=
accessor
.
get
(
IEditorWorkerService
);
let
model
:
ITextModel
;
let
validate
:
()
=>
boolean
;
let
cts
:
CancellationTokenSource
;
if
(
isCodeEditor
(
editorOrModel
))
{
model
=
editorOrModel
.
getModel
();
const
state
=
new
EditorState
(
editorOrModel
,
CodeEditorStateFlag
.
Value
|
CodeEditorStateFlag
.
Position
);
validate
=
()
=>
state
.
validate
(
editorOrModel
);
cts
=
new
EditorStateCancellationTokenSource
(
editorOrModel
,
CodeEditorStateFlag
.
Value
|
CodeEditorStateFlag
.
Position
,
token
);
}
else
{
model
=
editorOrModel
;
const
versionNow
=
editorOrModel
.
getVersionId
();
validate
=
()
=>
versionNow
===
editorOrModel
.
getVersionId
();
cts
=
new
TextModelCancellationTokenSource
(
editorOrModel
,
token
);
}
const
rawEdits
=
await
provider
.
provideDocumentFormattingEdits
(
model
,
model
.
getFormattingOptions
(),
token
cts
.
token
);
const
edits
=
await
workerService
.
computeMoreMinimalEdits
(
model
.
uri
,
rawEdits
);
if
(
!
validate
()
)
{
if
(
cts
.
token
.
isCancellationRequested
)
{
return
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录