Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0ee556cb
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,发现更多精彩内容 >>
提交
0ee556cb
编写于
9月 11, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
goto symbol - proper cancellation and editor change handling
上级
ee6a21fa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
23 deletion
+50
-23
src/vs/editor/contrib/quickOpen/quickOpen.ts
src/vs/editor/contrib/quickOpen/quickOpen.ts
+3
-0
src/vs/workbench/parts/quickopen/browser/gotoSymbolHandler.ts
...vs/workbench/parts/quickopen/browser/gotoSymbolHandler.ts
+47
-23
未找到文件。
src/vs/editor/contrib/quickOpen/quickOpen.ts
浏览文件 @
0ee556cb
...
...
@@ -31,6 +31,9 @@ export function getDocumentSymbols(model: ITextModel, flat: boolean, token: Canc
return
Promise
.
all
(
promises
).
then
(()
=>
{
let
flatEntries
:
DocumentSymbol
[]
=
[];
if
(
token
.
isCancellationRequested
)
{
return
flatEntries
;
}
if
(
flat
)
{
flatten
(
flatEntries
,
roots
,
''
);
}
else
{
...
...
src/vs/workbench/parts/quickopen/browser/gotoSymbolHandler.ts
浏览文件 @
0ee556cb
...
...
@@ -27,7 +27,7 @@ import { GroupIdentifier, IEditorInput } from 'vs/workbench/common/editor';
import
{
IEditorService
,
SIDE_GROUP
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IEditorGroup
}
from
'
vs/workbench/services/group/common/editorGroupsService
'
;
import
{
asThenable
}
from
'
vs/base/common/async
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
CancellationToken
,
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
export
const
GOTO_SYMBOL_PREFIX
=
'
@
'
;
export
const
SCOPE_PREFIX
=
'
:
'
;
...
...
@@ -361,21 +361,39 @@ export class GotoSymbolHandler extends QuickOpenHandler {
static
readonly
ID
=
'
workbench.picker.filesymbols
'
;
private
outlineToModelCache
:
{
[
modelId
:
string
]:
OutlineModel
;
};
private
rangeHighlightDecorationId
:
IEditorLineDecoration
;
private
lastKnownEditorViewState
:
IEditorViewState
;
private
cachedOutlineRequest
:
TPromise
<
OutlineModel
>
;
private
pendingOutlineRequest
:
CancellationTokenSource
;
constructor
(
@
IEditorService
private
editorService
:
IEditorService
)
{
super
();
this
.
outlineToModelCache
=
{};
this
.
registerListeners
();
}
private
registerListeners
():
void
{
this
.
editorService
.
onDidActiveEditorChange
(()
=>
this
.
onDidActiveEditorChange
());
}
private
onDidActiveEditorChange
():
void
{
this
.
clearOutlineRequest
();
this
.
lastKnownEditorViewState
=
void
0
;
this
.
rangeHighlightDecorationId
=
void
0
;
}
getResults
(
searchValue
:
string
,
token
:
CancellationToken
):
TPromise
<
QuickOpenModel
>
{
searchValue
=
searchValue
.
trim
();
// Support to cancel pending outline requests
if
(
!
this
.
pendingOutlineRequest
)
{
this
.
pendingOutlineRequest
=
new
CancellationTokenSource
();
}
// Remember view state to be able to restore on cancel
if
(
!
this
.
lastKnownEditorViewState
)
{
const
activeTextEditorWidget
=
this
.
editorService
.
activeTextEditorWidget
;
...
...
@@ -383,7 +401,7 @@ export class GotoSymbolHandler extends QuickOpenHandler {
}
// Resolve Outline Model
return
this
.
doGetActiveOutline
(
token
).
then
(
outline
=>
{
return
this
.
getOutline
(
).
then
(
outline
=>
{
if
(
token
.
isCancellationRequested
)
{
return
outline
;
}
...
...
@@ -460,7 +478,15 @@ export class GotoSymbolHandler extends QuickOpenHandler {
return
results
;
}
private
doGetActiveOutline
(
token
:
CancellationToken
):
TPromise
<
OutlineModel
>
{
private
getOutline
():
TPromise
<
OutlineModel
>
{
if
(
!
this
.
cachedOutlineRequest
)
{
this
.
cachedOutlineRequest
=
this
.
doGetActiveOutline
();
}
return
this
.
cachedOutlineRequest
;
}
private
doGetActiveOutline
():
TPromise
<
OutlineModel
>
{
const
activeTextEditorWidget
=
this
.
editorService
.
activeTextEditorWidget
;
if
(
activeTextEditorWidget
)
{
let
model
=
activeTextEditorWidget
.
getModel
();
...
...
@@ -469,20 +495,8 @@ export class GotoSymbolHandler extends QuickOpenHandler {
}
if
(
model
&&
types
.
isFunction
((
<
ITextModel
>
model
).
getLanguageIdentifier
))
{
// Ask cache first
const
modelId
=
(
<
ITextModel
>
model
).
id
;
if
(
this
.
outlineToModelCache
[
modelId
])
{
return
TPromise
.
as
(
this
.
outlineToModelCache
[
modelId
]);
}
return
TPromise
.
wrap
(
asThenable
(()
=>
getDocumentSymbols
(
<
ITextModel
>
model
,
true
,
token
)).
then
(
entries
=>
{
const
model
=
new
OutlineModel
(
this
.
toQuickOpenEntries
(
entries
));
this
.
outlineToModelCache
=
{};
// Clear cache, only keep 1 outline
this
.
outlineToModelCache
[
modelId
]
=
model
;
return
model
;
return
TPromise
.
wrap
(
asThenable
(()
=>
getDocumentSymbols
(
<
ITextModel
>
model
,
true
,
this
.
pendingOutlineRequest
.
token
)).
then
(
entries
=>
{
return
new
OutlineModel
(
this
.
toQuickOpenEntries
(
entries
));
}));
}
}
...
...
@@ -537,7 +551,7 @@ export class GotoSymbolHandler extends QuickOpenHandler {
});
}
clearDecorations
():
void
{
private
clearDecorations
():
void
{
if
(
this
.
rangeHighlightDecorationId
)
{
this
.
editorService
.
visibleControls
.
forEach
(
editor
=>
{
if
(
editor
.
group
.
id
===
this
.
rangeHighlightDecorationId
.
groupId
)
{
...
...
@@ -557,8 +571,8 @@ export class GotoSymbolHandler extends QuickOpenHandler {
onClose
(
canceled
:
boolean
):
void
{
// C
lear Cache
this
.
outlineToModelCache
=
{}
;
// C
ancel any pending/cached outline request now
this
.
clearOutlineRequest
()
;
// Clear Highlight Decorations if present
this
.
clearDecorations
();
...
...
@@ -569,8 +583,18 @@ export class GotoSymbolHandler extends QuickOpenHandler {
if
(
activeTextEditorWidget
)
{
activeTextEditorWidget
.
restoreViewState
(
this
.
lastKnownEditorViewState
);
}
this
.
lastKnownEditorViewState
=
null
;
}
}
private
clearOutlineRequest
():
void
{
if
(
this
.
pendingOutlineRequest
)
{
this
.
pendingOutlineRequest
.
cancel
();
this
.
pendingOutlineRequest
.
dispose
();
this
.
pendingOutlineRequest
=
void
0
;
}
this
.
lastKnownEditorViewState
=
null
;
this
.
cachedOutlineRequest
=
null
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录