Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1e25b497
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 搜索 >>
提交
1e25b497
编写于
7月 03, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - use cancellation token for outline
上级
21991b49
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
26 deletion
+44
-26
src/vs/editor/contrib/documentSymbols/outlineModel.ts
src/vs/editor/contrib/documentSymbols/outlineModel.ts
+19
-16
src/vs/editor/contrib/documentSymbols/test/outlineModel.test.ts
.../editor/contrib/documentSymbols/test/outlineModel.test.ts
+10
-7
src/vs/workbench/parts/outline/electron-browser/outlinePanel.ts
.../workbench/parts/outline/electron-browser/outlinePanel.ts
+15
-3
未找到文件。
src/vs/editor/contrib/documentSymbols/outlineModel.ts
浏览文件 @
1e25b497
...
...
@@ -6,8 +6,6 @@
import
{
DocumentSymbolProviderRegistry
,
DocumentSymbolProvider
,
DocumentSymbol
}
from
'
vs/editor/common/modes
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
fuzzyScore
,
FuzzyScore
}
from
'
vs/base/common/filters
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
...
...
@@ -17,6 +15,7 @@ import { commonPrefixLength } from 'vs/base/common/strings';
import
{
IMarker
,
MarkerSeverity
}
from
'
vs/platform/markers/common/markers
'
;
import
{
onUnexpectedExternalError
}
from
'
vs/base/common/errors
'
;
import
{
LRUCache
}
from
'
vs/base/common/map
'
;
import
{
CancellationToken
,
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
export
abstract
class
TreeElement
{
abstract
id
:
string
;
...
...
@@ -196,7 +195,7 @@ export class OutlineGroup extends TreeElement {
export
class
OutlineModel
extends
TreeElement
{
private
static
readonly
_requests
=
new
LRUCache
<
string
,
{
promiseCnt
:
number
,
promise
:
T
Promise
<
any
>
,
model
:
OutlineModel
}
>
(
9
,
.
75
);
private
static
readonly
_requests
=
new
LRUCache
<
string
,
{
promiseCnt
:
number
,
source
:
CancellationTokenSource
,
promise
:
Promise
<
any
>
,
model
:
OutlineModel
}
>
(
9
,
.
75
);
private
static
readonly
_keys
=
new
class
{
private
_counter
=
1
;
...
...
@@ -221,15 +220,17 @@ export class OutlineModel extends TreeElement {
};
static
create
(
textModel
:
ITextModel
):
T
Promise
<
OutlineModel
>
{
static
create
(
textModel
:
ITextModel
,
token
:
CancellationToken
):
Promise
<
OutlineModel
>
{
let
key
=
this
.
_keys
.
for
(
textModel
);
let
data
=
OutlineModel
.
_requests
.
get
(
key
);
if
(
!
data
)
{
let
source
=
new
CancellationTokenSource
();
data
=
{
promiseCnt
:
0
,
promise
:
OutlineModel
.
_create
(
textModel
),
source
,
promise
:
OutlineModel
.
_create
(
textModel
,
source
.
token
),
model
:
undefined
,
};
OutlineModel
.
_requests
.
set
(
key
,
data
);
...
...
@@ -237,13 +238,21 @@ export class OutlineModel extends TreeElement {
if
(
data
.
model
)
{
// resolved -> return data
return
TPromise
.
as
(
data
.
model
);
return
Promise
.
resolve
(
data
.
model
);
}
// increase usage counter
data
.
promiseCnt
+=
1
;
return
new
TPromise
((
resolve
,
reject
)
=>
{
token
.
onCancellationRequested
(()
=>
{
// last -> cancel provider request, remove cached promise
if
(
--
data
.
promiseCnt
===
0
)
{
data
.
source
.
cancel
();
OutlineModel
.
_requests
.
delete
(
key
);
}
});
return
new
Promise
((
resolve
,
reject
)
=>
{
data
.
promise
.
then
(
model
=>
{
data
.
model
=
model
;
resolve
(
model
);
...
...
@@ -251,16 +260,10 @@ export class OutlineModel extends TreeElement {
OutlineModel
.
_requests
.
delete
(
key
);
reject
(
err
);
});
},
()
=>
{
// last -> cancel provider request, remove cached promise
if
(
--
data
.
promiseCnt
===
0
)
{
data
.
promise
.
cancel
();
OutlineModel
.
_requests
.
delete
(
key
);
}
});
}
static
_create
(
textModel
:
ITextModel
):
T
Promise
<
OutlineModel
>
{
static
_create
(
textModel
:
ITextModel
,
token
:
CancellationToken
):
Promise
<
OutlineModel
>
{
let
result
=
new
OutlineModel
(
textModel
);
let
promises
=
DocumentSymbolProviderRegistry
.
ordered
(
textModel
).
map
((
provider
,
index
)
=>
{
...
...
@@ -268,7 +271,7 @@ export class OutlineModel extends TreeElement {
let
id
=
TreeElement
.
findId
(
`provider_
${
index
}
`
,
result
);
let
group
=
new
OutlineGroup
(
id
,
result
,
provider
,
index
);
return
asWinJsPromise
(
token
=>
provider
.
provideDocumentSymbols
(
result
.
textModel
,
token
)).
then
(
result
=>
{
return
Promise
.
resolve
(
provider
.
provideDocumentSymbols
(
result
.
textModel
,
token
)).
then
(
result
=>
{
if
(
!
isFalsyOrEmpty
(
result
))
{
for
(
const
info
of
result
)
{
OutlineModel
.
_makeOutlineElement
(
info
,
group
);
...
...
@@ -283,7 +286,7 @@ export class OutlineModel extends TreeElement {
});
});
return
TPromise
.
join
(
promises
).
then
(()
=>
{
return
Promise
.
all
(
promises
).
then
(()
=>
{
let
count
=
0
;
for
(
const
key
in
result
.
_groups
)
{
...
...
src/vs/editor/contrib/documentSymbols/test/outlineModel.test.ts
浏览文件 @
1e25b497
...
...
@@ -12,6 +12,7 @@ import { Range } from 'vs/editor/common/core/range';
import
{
IMarker
,
MarkerSeverity
}
from
'
vs/platform/markers/common/markers
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
CancellationToken
,
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
suite
(
'
OutlineModel
'
,
function
()
{
...
...
@@ -26,16 +27,16 @@ suite('OutlineModel', function () {
}
});
await
OutlineModel
.
create
(
model
);
await
OutlineModel
.
create
(
model
,
CancellationToken
.
None
);
assert
.
equal
(
count
,
1
);
// cached
await
OutlineModel
.
create
(
model
);
await
OutlineModel
.
create
(
model
,
CancellationToken
.
None
);
assert
.
equal
(
count
,
1
);
// new version
model
.
applyEdits
([{
text
:
'
XXX
'
,
range
:
new
Range
(
1
,
1
,
1
,
1
)
}]);
await
OutlineModel
.
create
(
model
);
await
OutlineModel
.
create
(
model
,
CancellationToken
.
None
);
assert
.
equal
(
count
,
2
);
reg
.
dispose
();
...
...
@@ -58,13 +59,15 @@ suite('OutlineModel', function () {
});
assert
.
equal
(
isCancelled
,
false
);
let
p1
=
OutlineModel
.
create
(
model
);
let
p2
=
OutlineModel
.
create
(
model
);
let
s1
=
new
CancellationTokenSource
();
OutlineModel
.
create
(
model
,
s1
.
token
);
let
s2
=
new
CancellationTokenSource
();
OutlineModel
.
create
(
model
,
s2
.
token
);
p
1
.
cancel
();
s
1
.
cancel
();
assert
.
equal
(
isCancelled
,
false
);
p
2
.
cancel
();
s
2
.
cancel
();
assert
.
equal
(
isCancelled
,
true
);
reg
.
dispose
();
...
...
src/vs/workbench/parts/outline/electron-browser/outlinePanel.ts
浏览文件 @
1e25b497
...
...
@@ -13,8 +13,8 @@ import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import
{
ProgressBar
}
from
'
vs/base/browser/ui/progressbar/progressbar
'
;
import
{
Action
,
IAction
,
RadioGroup
}
from
'
vs/base/common/actions
'
;
import
{
firstIndex
}
from
'
vs/base/common/arrays
'
;
import
{
asDisposablePromise
,
setDisposableTimeout
}
from
'
vs/base/common/async
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
asDisposablePromise
,
setDisposableTimeout
,
createCancelablePromise
}
from
'
vs/base/common/async
'
;
import
{
onUnexpectedError
,
isPromiseCanceledError
}
from
'
vs/base/common/errors
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
defaultGenerator
}
from
'
vs/base/common/idGenerator
'
;
import
{
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
...
...
@@ -54,6 +54,7 @@ import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron
import
{
OutlineConfigKeys
,
OutlineViewFiltered
,
OutlineViewFocused
,
OutlineViewId
}
from
'
./outline
'
;
import
{
OutlineController
,
OutlineDataSource
,
OutlineItemComparator
,
OutlineItemCompareType
,
OutlineItemFilter
,
OutlineRenderer
,
OutlineTreeState
}
from
'
../../../../editor/contrib/documentSymbols/outlineTree
'
;
import
{
IResourceInput
}
from
'
vs/platform/editor/common/editor
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
class
RequestState
{
...
...
@@ -440,6 +441,17 @@ export class OutlinePanel extends ViewletPanel {
this
.
_message
.
innerText
=
escape
(
message
);
}
private
static
_createOutlineModel
(
model
:
ITextModel
,
disposables
:
IDisposable
[]):
Promise
<
OutlineModel
>
{
let
promise
=
createCancelablePromise
(
token
=>
OutlineModel
.
create
(
model
,
token
));
disposables
.
push
({
dispose
()
{
promise
.
cancel
();
}
});
return
promise
.
catch
(
err
=>
{
if
(
!
isPromiseCanceledError
(
err
))
{
throw
err
;
}
return
undefined
;
});
}
private
async
_doUpdate
(
editor
:
ICodeEditor
,
event
:
IModelContentChangedEvent
):
Promise
<
void
>
{
dispose
(
this
.
_editorDisposables
);
...
...
@@ -464,7 +476,7 @@ export class OutlinePanel extends ViewletPanel {
);
}
let
model
=
await
asDisposablePromise
(
OutlineModel
.
create
(
textModel
),
undefined
,
this
.
_editorDisposables
).
promise
;
let
model
=
await
OutlinePanel
.
_createOutlineModel
(
textModel
,
this
.
_editorDisposables
)
;
dispose
(
loadingMessage
);
if
(
!
model
)
{
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录