Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
49f3723a
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 搜索 >>
提交
49f3723a
编写于
3月 08, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
quick access - allow provide to return disposable and cancel token properly
上级
1edef2f2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
83 addition
and
41 deletion
+83
-41
src/vs/platform/quickinput/browser/helpQuickAccess.ts
src/vs/platform/quickinput/browser/helpQuickAccess.ts
+3
-5
src/vs/platform/quickinput/browser/quickAccess.ts
src/vs/platform/quickinput/browser/quickAccess.ts
+28
-12
src/vs/platform/quickinput/common/quickAccess.ts
src/vs/platform/quickinput/common/quickAccess.ts
+8
-4
src/vs/workbench/browser/parts/quickopen/quickopen.ts
src/vs/workbench/browser/parts/quickopen/quickopen.ts
+6
-6
src/vs/workbench/test/browser/quickAccess.test.ts
src/vs/workbench/test/browser/quickAccess.test.ts
+38
-14
未找到文件。
src/vs/platform/quickinput/browser/helpQuickAccess.ts
浏览文件 @
49f3723a
...
...
@@ -8,8 +8,7 @@ import { IQuickAccessProvider, IQuickAccessRegistry, Extensions } from 'vs/platf
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
once
}
from
'
vs/base/common/functional
'
;
import
{
DisposableStore
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
interface
IHelpQuickAccessPickItem
extends
IQuickPickItem
{
prefix
:
string
;
...
...
@@ -21,9 +20,8 @@ export class HelpQuickAccessProvider implements IQuickAccessProvider {
constructor
(@
IQuickInputService
private
readonly
quickInputService
:
IQuickInputService
)
{
}
provide
(
picker
:
IQuickPick
<
IHelpQuickAccessPickItem
>
,
token
:
CancellationToken
):
void
{
provide
(
picker
:
IQuickPick
<
IHelpQuickAccessPickItem
>
,
token
:
CancellationToken
):
IDisposable
{
const
disposables
=
new
DisposableStore
();
once
(
token
.
onCancellationRequested
)(()
=>
disposables
.
dispose
());
// Open a picker with the selected value if picked
disposables
.
add
(
picker
.
onDidAccept
(()
=>
{
...
...
@@ -50,7 +48,7 @@ export class HelpQuickAccessProvider implements IQuickAccessProvider {
...
editorProviders
];
picker
.
show
()
;
return
disposables
;
}
private
getQuickAccessProviders
():
{
editorProviders
:
IHelpQuickAccessPickItem
[],
globalProviders
:
IHelpQuickAccessPickItem
[]
}
{
...
...
src/vs/platform/quickinput/browser/quickAccess.ts
浏览文件 @
49f3723a
...
...
@@ -10,7 +10,6 @@ import { Registry } from 'vs/platform/registry/common/platform';
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
once
}
from
'
vs/base/common/functional
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
export
class
QuickAccessController
extends
Disposable
implements
IQuickAccessController
{
...
...
@@ -27,23 +26,40 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
}
show
(
value
=
''
):
void
{
const
disposables
=
new
DisposableStore
();
// Hide any previous picker if any
this
.
lastActivePicker
?.
dispos
e
();
this
.
lastActivePicker
?.
hid
e
();
// Find provider for the value to show
const
[
provider
,
prefix
]
=
this
.
getOrInstantiateProvider
(
value
);
// Create a picker for the provider to use with the initial value
// and adjust the filtering to exclude the prefix from filtering
const
picker
=
this
.
lastActivePicker
=
this
.
quickInputService
.
createQuickPick
(
);
const
picker
=
disposables
.
add
(
this
.
quickInputService
.
createQuickPick
()
);
picker
.
value
=
value
;
picker
.
valueSelection
=
[
value
.
length
,
value
.
length
];
picker
.
filterValue
=
(
value
:
string
)
=>
value
.
substring
(
prefix
.
length
);
// Cleanup when picker hides or gets disposed
const
disposables
=
new
DisposableStore
();
once
(
Event
.
any
(
picker
.
onDidHide
,
picker
.
onDispose
))(()
=>
disposables
.
dispose
());
// Remember as last active picker and clean up once picker get's disposed
this
.
lastActivePicker
=
picker
;
disposables
.
add
(
toDisposable
(()
=>
{
if
(
picker
===
this
.
lastActivePicker
)
{
this
.
lastActivePicker
=
undefined
;
}
}));
// Create a cancellation token source that is valid as long as the
// picker has not been closed without picking an item
const
cts
=
disposables
.
add
(
new
CancellationTokenSource
());
once
(
picker
.
onDidHide
)(()
=>
{
if
(
picker
.
selectedItems
.
length
===
0
)
{
cts
.
cancel
();
}
// Start to dispose once picker hides
disposables
.
dispose
();
});
// Whenever the value changes, check if the provider has
// changed and if so - re-create the picker from the beginning
...
...
@@ -54,13 +70,13 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
}
}));
// Create a cancellation token source that is valid
// as long as the picker has not been closed
const
cts
=
new
CancellationTokenSource
();
disposables
.
add
(
toDisposable
(()
=>
cts
.
dispose
(
true
)));
// Ask provider to fill the picker as needed
disposables
.
add
(
provider
.
provide
(
picker
,
cts
.
token
));
// Finally ask provider to fill the picker as needed
provider
.
provide
(
picker
,
cts
.
token
);
// Finally, show the picker. This is important because a provider
// may not call this and then our disposables would leak that rely
// on the onDidHide event.
picker
.
show
();
}
private
getOrInstantiateProvider
(
value
:
string
):
[
IQuickAccessProvider
,
string
/* prefix */
]
{
...
...
src/vs/platform/quickinput/common/quickAccess.ts
浏览文件 @
49f3723a
...
...
@@ -24,12 +24,16 @@ export interface IQuickAccessProvider {
/**
* Called whenever a prefix was typed into quick pick that matches the provider.
*
* @param picker the picker to use for showing provider results.
* @param picker the picker to use for showing provider results. The picker is
* automatically shown after the method returns, no need to call `show()`.
* @param token providers have to check the cancellation token everytime after
* a long running operation because it could be that the picker has been closed
* or changed meanwhile.
* a long running operation or from event handlers because it could be that the
* picker has been closed or changed meanwhile. The token can be used to find out
* that the picker was closed without picking an entry (e.g. was canceled by the user).
* @return a disposable that will automatically be disposed when the picker
* closes or is replaced by another picker.
*/
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
):
void
;
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
):
IDisposable
;
}
export
interface
IQuickAccessProviderHelp
{
...
...
src/vs/workbench/browser/parts/quickopen/quickopen.ts
浏览文件 @
49f3723a
...
...
@@ -11,11 +11,11 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import
{
ContextKeyExpr
,
RawContextKey
,
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ICommandHandler
,
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Disposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IWorkbenchContributionsRegistry
,
Extensions
as
WorkbenchExtensions
}
from
'
vs/workbench/common/contributions
'
;
import
{
LifecyclePhase
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
IQuickAccess
Registry
,
Extensions
as
QuickinputExtensions
,
IQuickAccessProvider
}
from
'
vs/platform/quickinput/common/quickAccess
'
;
import
{
IQuickAccess
Provider
,
IQuickAccessRegistry
,
Extensions
as
QuickInputExtensions
}
from
'
vs/platform/quickinput/common/quickAccess
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
const
inQuickOpenKey
=
'
inQuickOpen
'
;
...
...
@@ -209,19 +209,19 @@ export class LegacyQuickInputQuickOpenController extends Disposable {
Registry
.
as
<
IWorkbenchContributionsRegistry
>
(
WorkbenchExtensions
.
Workbench
).
registerWorkbenchContribution
(
LegacyQuickInputQuickOpenController
,
LifecyclePhase
.
Ready
);
class
SampleQuickAccessProvider
implements
IQuickAccessProvider
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
):
void
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
):
IDisposable
{
picker
.
items
=
[
{
label
:
'
Hello World
'
},
{
label
:
'
Lorem Ipsum
'
},
{
label
:
'
Something Else
'
}
];
picker
.
show
()
;
return
Disposable
.
None
;
}
}
const
quickAccessRegistry
=
Registry
.
as
<
IQuickAccessRegistry
>
(
Quick
i
nputExtensions
.
Quickaccess
);
[
''
,
'
>
'
,
'
@
'
,
'
:
'
,
'
edt
'
,
'
edt active
'
,
'
edt mru
'
,
'
view
'
].
forEach
(
prefix
=>
{
const
quickAccessRegistry
=
Registry
.
as
<
IQuickAccessRegistry
>
(
Quick
I
nputExtensions
.
Quickaccess
);
[
''
/*, '>', '@', ':', 'edt', 'edt active', 'edt mru', 'view'*/
].
forEach
(
prefix
=>
{
const
provider
=
{
ctor
:
SampleQuickAccessProvider
,
prefix
,
...
...
src/vs/workbench/test/browser/quickAccess.test.ts
浏览文件 @
49f3723a
...
...
@@ -10,7 +10,7 @@ import { IQuickPick, IQuickPickItem, IQuickInputService } from 'vs/platform/quic
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
TestServiceAccessor
,
workbenchInstantiationService
}
from
'
vs/workbench/test/browser/workbenchTestServices
'
;
import
{
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
DisposableStore
,
toDisposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
timeout
}
from
'
vs/base/common/async
'
;
suite
(
'
QuickAccess
'
,
()
=>
{
...
...
@@ -20,61 +20,66 @@ suite('QuickAccess', () => {
let
provider1Called
=
false
;
let
provider1Canceled
=
false
;
let
provider1Disposed
=
false
;
let
provider2Called
=
false
;
let
provider2Canceled
=
false
;
let
provider2Disposed
=
false
;
let
provider3Called
=
false
;
let
provider3Canceled
=
false
;
let
provider3Disposed
=
false
;
let
provider4Called
=
false
;
let
provider4Canceled
=
false
;
let
provider4Disposed
=
false
;
class
TestProvider1
implements
IQuickAccessProvider
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
)
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
)
:
IDisposable
{
assert
.
ok
(
picker
);
provider1Called
=
true
;
token
.
onCancellationRequested
(()
=>
provider1Canceled
=
true
);
picker
.
show
(
);
return
toDisposable
(()
=>
provider1Disposed
=
true
);
}
}
class
TestProvider2
implements
IQuickAccessProvider
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
)
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
)
:
IDisposable
{
assert
.
ok
(
picker
);
provider2Called
=
true
;
token
.
onCancellationRequested
(()
=>
provider2Canceled
=
true
);
// Not calling picker show explicitly to test bad provider
// picker.show();
return
toDisposable
(()
=>
provider2Disposed
=
true
);
}
}
class
TestProvider3
implements
IQuickAccessProvider
{
constructor
(@
IQuickInputService
private
readonly
quickInputService
:
IQuickInputService
)
{
}
constructor
(@
IQuickInputService
private
readonly
quickInputService
:
IQuickInputService
,
disposables
:
DisposableStore
)
{
}
async
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
)
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
):
IDisposable
{
assert
.
ok
(
picker
);
provider3Called
=
true
;
token
.
onCancellationRequested
(()
=>
provider3Canceled
=
true
);
picker
.
show
();
// bring up provider #4
await
timeout
(
0
);
this
.
quickInputService
.
quickAccess
.
show
(
providerDescriptor4
.
prefix
);
setTimeout
(()
=>
this
.
quickInputService
.
quickAccess
.
show
(
providerDescriptor4
.
prefix
));
return
toDisposable
(()
=>
provider3Disposed
=
true
);
}
}
class
TestProvider4
implements
IQuickAccessProvider
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
)
{
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
)
:
IDisposable
{
assert
.
ok
(
picker
);
provider4Called
=
true
;
token
.
onCancellationRequested
(()
=>
provider4Canceled
=
true
);
picker
.
show
();
// hide without picking
setTimeout
(()
=>
picker
.
hide
());
return
toDisposable
(()
=>
provider4Disposed
=
true
);
}
}
...
...
@@ -124,6 +129,10 @@ suite('QuickAccess', () => {
assert
.
equal
(
provider2Canceled
,
false
);
assert
.
equal
(
provider3Canceled
,
false
);
assert
.
equal
(
provider4Canceled
,
false
);
assert
.
equal
(
provider1Disposed
,
false
);
assert
.
equal
(
provider2Disposed
,
false
);
assert
.
equal
(
provider3Disposed
,
false
);
assert
.
equal
(
provider4Disposed
,
false
);
provider1Called
=
false
;
accessor
.
quickInputService
.
quickAccess
.
show
(
'
test something
'
);
...
...
@@ -135,8 +144,13 @@ suite('QuickAccess', () => {
assert
.
equal
(
provider2Canceled
,
false
);
assert
.
equal
(
provider3Canceled
,
false
);
assert
.
equal
(
provider4Canceled
,
false
);
assert
.
equal
(
provider1Disposed
,
true
);
assert
.
equal
(
provider2Disposed
,
false
);
assert
.
equal
(
provider3Disposed
,
false
);
assert
.
equal
(
provider4Disposed
,
false
);
provider2Called
=
false
;
provider1Canceled
=
false
;
provider1Disposed
=
false
;
accessor
.
quickInputService
.
quickAccess
.
show
(
'
usedefault
'
);
assert
.
equal
(
provider1Called
,
false
);
...
...
@@ -147,12 +161,22 @@ suite('QuickAccess', () => {
assert
.
equal
(
provider2Canceled
,
true
);
assert
.
equal
(
provider3Canceled
,
false
);
assert
.
equal
(
provider4Canceled
,
false
);
assert
.
equal
(
provider1Disposed
,
false
);
assert
.
equal
(
provider2Disposed
,
true
);
assert
.
equal
(
provider3Disposed
,
false
);
assert
.
equal
(
provider4Disposed
,
false
);
await
timeout
(
1
);
assert
.
equal
(
provider3Canceled
,
true
);
assert
.
equal
(
provider3Disposed
,
true
);
assert
.
equal
(
provider4Called
,
true
);
await
timeout
(
1
);
assert
.
equal
(
provider4Canceled
,
true
);
assert
.
equal
(
provider4Disposed
,
true
);
disposables
.
dispose
();
registry
.
defaultProvider
=
defaultProvider
;
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录