Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ae836215
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 搜索 >>
提交
ae836215
编写于
4月 03, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adopt PauseableEmitter in ContextKeyService and for EditorModeContext, #71642
上级
1c1ff994
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
105 addition
and
76 deletion
+105
-76
src/vs/editor/browser/widget/codeEditorWidget.ts
src/vs/editor/browser/widget/codeEditorWidget.ts
+63
-62
src/vs/platform/contextkey/browser/contextKeyService.ts
src/vs/platform/contextkey/browser/contextKeyService.ts
+37
-14
src/vs/platform/contextkey/common/contextkey.ts
src/vs/platform/contextkey/common/contextkey.ts
+3
-0
src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts
.../keybinding/test/common/abstractKeybindingService.test.ts
+1
-0
src/vs/platform/keybinding/test/common/mockKeybindingService.ts
.../platform/keybinding/test/common/mockKeybindingService.ts
+1
-0
未找到文件。
src/vs/editor/browser/widget/codeEditorWidget.ts
浏览文件 @
ae836215
...
...
@@ -1628,8 +1628,6 @@ class EditorContextKeysManager extends Disposable {
export
class
EditorModeContext
extends
Disposable
{
private
readonly
_editor
:
CodeEditorWidget
;
private
readonly
_langId
:
IContextKey
<
string
>
;
private
readonly
_hasCompletionItemProvider
:
IContextKey
<
boolean
>
;
private
readonly
_hasCodeActionsProvider
:
IContextKey
<
boolean
>
;
...
...
@@ -1651,37 +1649,36 @@ export class EditorModeContext extends Disposable {
private
readonly
_isInWalkThrough
:
IContextKey
<
boolean
>
;
constructor
(
editor
:
CodeEditorWidget
,
contextKeyService
:
IContextKeyService
private
readonly
_
editor
:
CodeEditorWidget
,
private
readonly
_
contextKeyService
:
IContextKeyService
)
{
super
();
this
.
_editor
=
editor
;
this
.
_langId
=
EditorContextKeys
.
languageId
.
bindTo
(
contextKeyService
);
this
.
_hasCompletionItemProvider
=
EditorContextKeys
.
hasCompletionItemProvider
.
bindTo
(
contextKeyService
);
this
.
_hasCodeActionsProvider
=
EditorContextKeys
.
hasCodeActionsProvider
.
bindTo
(
contextKeyService
);
this
.
_hasCodeLensProvider
=
EditorContextKeys
.
hasCodeLensProvider
.
bindTo
(
contextKeyService
);
this
.
_hasDefinitionProvider
=
EditorContextKeys
.
hasDefinitionProvider
.
bindTo
(
contextKeyService
);
this
.
_hasDeclarationProvider
=
EditorContextKeys
.
hasDeclarationProvider
.
bindTo
(
contextKeyService
);
this
.
_hasImplementationProvider
=
EditorContextKeys
.
hasImplementationProvider
.
bindTo
(
contextKeyService
);
this
.
_hasTypeDefinitionProvider
=
EditorContextKeys
.
hasTypeDefinitionProvider
.
bindTo
(
contextKeyService
);
this
.
_hasHoverProvider
=
EditorContextKeys
.
hasHoverProvider
.
bindTo
(
contextKeyService
);
this
.
_hasDocumentHighlightProvider
=
EditorContextKeys
.
hasDocumentHighlightProvider
.
bindTo
(
contextKeyService
);
this
.
_hasDocumentSymbolProvider
=
EditorContextKeys
.
hasDocumentSymbolProvider
.
bindTo
(
contextKeyService
);
this
.
_hasReferenceProvider
=
EditorContextKeys
.
hasReferenceProvider
.
bindTo
(
contextKeyService
);
this
.
_hasRenameProvider
=
EditorContextKeys
.
hasRenameProvider
.
bindTo
(
contextKeyService
);
this
.
_hasSignatureHelpProvider
=
EditorContextKeys
.
hasSignatureHelpProvider
.
bindTo
(
contextKeyService
);
this
.
_hasDocumentFormattingProvider
=
EditorContextKeys
.
hasDocumentFormattingProvider
.
bindTo
(
contextKeyService
);
this
.
_hasDocumentSelectionFormattingProvider
=
EditorContextKeys
.
hasDocumentSelectionFormattingProvider
.
bindTo
(
contextKeyService
);
this
.
_hasMultipleDocumentFormattingProvider
=
EditorContextKeys
.
hasMultipleDocumentFormattingProvider
.
bindTo
(
contextKeyService
);
this
.
_hasMultipleDocumentSelectionFormattingProvider
=
EditorContextKeys
.
hasMultipleDocumentSelectionFormattingProvider
.
bindTo
(
contextKeyService
);
this
.
_isInWalkThrough
=
EditorContextKeys
.
isInEmbeddedEditor
.
bindTo
(
contextKeyService
);
this
.
_langId
=
EditorContextKeys
.
languageId
.
bindTo
(
_
contextKeyService
);
this
.
_hasCompletionItemProvider
=
EditorContextKeys
.
hasCompletionItemProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasCodeActionsProvider
=
EditorContextKeys
.
hasCodeActionsProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasCodeLensProvider
=
EditorContextKeys
.
hasCodeLensProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasDefinitionProvider
=
EditorContextKeys
.
hasDefinitionProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasDeclarationProvider
=
EditorContextKeys
.
hasDeclarationProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasImplementationProvider
=
EditorContextKeys
.
hasImplementationProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasTypeDefinitionProvider
=
EditorContextKeys
.
hasTypeDefinitionProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasHoverProvider
=
EditorContextKeys
.
hasHoverProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasDocumentHighlightProvider
=
EditorContextKeys
.
hasDocumentHighlightProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasDocumentSymbolProvider
=
EditorContextKeys
.
hasDocumentSymbolProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasReferenceProvider
=
EditorContextKeys
.
hasReferenceProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasRenameProvider
=
EditorContextKeys
.
hasRenameProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasSignatureHelpProvider
=
EditorContextKeys
.
hasSignatureHelpProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasDocumentFormattingProvider
=
EditorContextKeys
.
hasDocumentFormattingProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasDocumentSelectionFormattingProvider
=
EditorContextKeys
.
hasDocumentSelectionFormattingProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasMultipleDocumentFormattingProvider
=
EditorContextKeys
.
hasMultipleDocumentFormattingProvider
.
bindTo
(
_
contextKeyService
);
this
.
_hasMultipleDocumentSelectionFormattingProvider
=
EditorContextKeys
.
hasMultipleDocumentSelectionFormattingProvider
.
bindTo
(
_
contextKeyService
);
this
.
_isInWalkThrough
=
EditorContextKeys
.
isInEmbeddedEditor
.
bindTo
(
_
contextKeyService
);
const
update
=
()
=>
this
.
_update
();
// update when model/mode changes
this
.
_register
(
editor
.
onDidChangeModel
(
update
));
this
.
_register
(
editor
.
onDidChangeModelLanguage
(
update
));
this
.
_register
(
_
editor
.
onDidChangeModel
(
update
));
this
.
_register
(
_
editor
.
onDidChangeModelLanguage
(
update
));
// update when registries change
this
.
_register
(
modes
.
CompletionProviderRegistry
.
onDidChange
(
update
));
...
...
@@ -1708,23 +1705,25 @@ export class EditorModeContext extends Disposable {
}
reset
()
{
this
.
_langId
.
reset
();
this
.
_hasCompletionItemProvider
.
reset
();
this
.
_hasCodeActionsProvider
.
reset
();
this
.
_hasCodeLensProvider
.
reset
();
this
.
_hasDefinitionProvider
.
reset
();
this
.
_hasDeclarationProvider
.
reset
();
this
.
_hasImplementationProvider
.
reset
();
this
.
_hasTypeDefinitionProvider
.
reset
();
this
.
_hasHoverProvider
.
reset
();
this
.
_hasDocumentHighlightProvider
.
reset
();
this
.
_hasDocumentSymbolProvider
.
reset
();
this
.
_hasReferenceProvider
.
reset
();
this
.
_hasRenameProvider
.
reset
();
this
.
_hasDocumentFormattingProvider
.
reset
();
this
.
_hasDocumentSelectionFormattingProvider
.
reset
();
this
.
_hasSignatureHelpProvider
.
reset
();
this
.
_isInWalkThrough
.
reset
();
this
.
_contextKeyService
.
bufferChangeEvents
(()
=>
{
this
.
_langId
.
reset
();
this
.
_hasCompletionItemProvider
.
reset
();
this
.
_hasCodeActionsProvider
.
reset
();
this
.
_hasCodeLensProvider
.
reset
();
this
.
_hasDefinitionProvider
.
reset
();
this
.
_hasDeclarationProvider
.
reset
();
this
.
_hasImplementationProvider
.
reset
();
this
.
_hasTypeDefinitionProvider
.
reset
();
this
.
_hasHoverProvider
.
reset
();
this
.
_hasDocumentHighlightProvider
.
reset
();
this
.
_hasDocumentSymbolProvider
.
reset
();
this
.
_hasReferenceProvider
.
reset
();
this
.
_hasRenameProvider
.
reset
();
this
.
_hasDocumentFormattingProvider
.
reset
();
this
.
_hasDocumentSelectionFormattingProvider
.
reset
();
this
.
_hasSignatureHelpProvider
.
reset
();
this
.
_isInWalkThrough
.
reset
();
});
}
private
_update
()
{
...
...
@@ -1733,25 +1732,27 @@ export class EditorModeContext extends Disposable {
this
.
reset
();
return
;
}
this
.
_langId
.
set
(
model
.
getLanguageIdentifier
().
language
);
this
.
_hasCompletionItemProvider
.
set
(
modes
.
CompletionProviderRegistry
.
has
(
model
));
this
.
_hasCodeActionsProvider
.
set
(
modes
.
CodeActionProviderRegistry
.
has
(
model
));
this
.
_hasCodeLensProvider
.
set
(
modes
.
CodeLensProviderRegistry
.
has
(
model
));
this
.
_hasDefinitionProvider
.
set
(
modes
.
DefinitionProviderRegistry
.
has
(
model
));
this
.
_hasDeclarationProvider
.
set
(
modes
.
DeclarationProviderRegistry
.
has
(
model
));
this
.
_hasImplementationProvider
.
set
(
modes
.
ImplementationProviderRegistry
.
has
(
model
));
this
.
_hasTypeDefinitionProvider
.
set
(
modes
.
TypeDefinitionProviderRegistry
.
has
(
model
));
this
.
_hasHoverProvider
.
set
(
modes
.
HoverProviderRegistry
.
has
(
model
));
this
.
_hasDocumentHighlightProvider
.
set
(
modes
.
DocumentHighlightProviderRegistry
.
has
(
model
));
this
.
_hasDocumentSymbolProvider
.
set
(
modes
.
DocumentSymbolProviderRegistry
.
has
(
model
));
this
.
_hasReferenceProvider
.
set
(
modes
.
ReferenceProviderRegistry
.
has
(
model
));
this
.
_hasRenameProvider
.
set
(
modes
.
RenameProviderRegistry
.
has
(
model
));
this
.
_hasSignatureHelpProvider
.
set
(
modes
.
SignatureHelpProviderRegistry
.
has
(
model
));
this
.
_hasDocumentFormattingProvider
.
set
(
modes
.
DocumentFormattingEditProviderRegistry
.
has
(
model
)
||
modes
.
DocumentRangeFormattingEditProviderRegistry
.
has
(
model
));
this
.
_hasDocumentSelectionFormattingProvider
.
set
(
modes
.
DocumentRangeFormattingEditProviderRegistry
.
has
(
model
));
this
.
_hasMultipleDocumentFormattingProvider
.
set
(
modes
.
DocumentFormattingEditProviderRegistry
.
all
(
model
).
length
>
1
||
modes
.
DocumentRangeFormattingEditProviderRegistry
.
all
(
model
).
length
>
1
);
this
.
_hasMultipleDocumentSelectionFormattingProvider
.
set
(
modes
.
DocumentRangeFormattingEditProviderRegistry
.
all
(
model
).
length
>
1
);
this
.
_isInWalkThrough
.
set
(
model
.
uri
.
scheme
===
Schemas
.
walkThroughSnippet
);
this
.
_contextKeyService
.
bufferChangeEvents
(()
=>
{
this
.
_langId
.
set
(
model
.
getLanguageIdentifier
().
language
);
this
.
_hasCompletionItemProvider
.
set
(
modes
.
CompletionProviderRegistry
.
has
(
model
));
this
.
_hasCodeActionsProvider
.
set
(
modes
.
CodeActionProviderRegistry
.
has
(
model
));
this
.
_hasCodeLensProvider
.
set
(
modes
.
CodeLensProviderRegistry
.
has
(
model
));
this
.
_hasDefinitionProvider
.
set
(
modes
.
DefinitionProviderRegistry
.
has
(
model
));
this
.
_hasDeclarationProvider
.
set
(
modes
.
DeclarationProviderRegistry
.
has
(
model
));
this
.
_hasImplementationProvider
.
set
(
modes
.
ImplementationProviderRegistry
.
has
(
model
));
this
.
_hasTypeDefinitionProvider
.
set
(
modes
.
TypeDefinitionProviderRegistry
.
has
(
model
));
this
.
_hasHoverProvider
.
set
(
modes
.
HoverProviderRegistry
.
has
(
model
));
this
.
_hasDocumentHighlightProvider
.
set
(
modes
.
DocumentHighlightProviderRegistry
.
has
(
model
));
this
.
_hasDocumentSymbolProvider
.
set
(
modes
.
DocumentSymbolProviderRegistry
.
has
(
model
));
this
.
_hasReferenceProvider
.
set
(
modes
.
ReferenceProviderRegistry
.
has
(
model
));
this
.
_hasRenameProvider
.
set
(
modes
.
RenameProviderRegistry
.
has
(
model
));
this
.
_hasSignatureHelpProvider
.
set
(
modes
.
SignatureHelpProviderRegistry
.
has
(
model
));
this
.
_hasDocumentFormattingProvider
.
set
(
modes
.
DocumentFormattingEditProviderRegistry
.
has
(
model
)
||
modes
.
DocumentRangeFormattingEditProviderRegistry
.
has
(
model
));
this
.
_hasDocumentSelectionFormattingProvider
.
set
(
modes
.
DocumentRangeFormattingEditProviderRegistry
.
has
(
model
));
this
.
_hasMultipleDocumentFormattingProvider
.
set
(
modes
.
DocumentFormattingEditProviderRegistry
.
all
(
model
).
length
>
1
||
modes
.
DocumentRangeFormattingEditProviderRegistry
.
all
(
model
).
length
>
1
);
this
.
_hasMultipleDocumentSelectionFormattingProvider
.
set
(
modes
.
DocumentRangeFormattingEditProviderRegistry
.
all
(
model
).
length
>
1
);
this
.
_isInWalkThrough
.
set
(
model
.
uri
.
scheme
===
Schemas
.
walkThroughSnippet
);
});
}
}
...
...
src/vs/platform/contextkey/browser/contextKeyService.ts
浏览文件 @
ae836215
...
...
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
Emitter
,
Event
,
PauseableEmitter
}
from
'
vs/base/common/event
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
keys
}
from
'
vs/base/common/map
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
...
...
@@ -165,44 +165,45 @@ class ConfigAwareContextValuesContainer extends Context {
class
ContextKey
<
T
>
implements
IContextKey
<
T
>
{
private
_
parent
:
AbstractContextKeyService
;
private
_
service
:
AbstractContextKeyService
;
private
_key
:
string
;
private
_defaultValue
:
T
|
undefined
;
constructor
(
parent
:
AbstractContextKeyService
,
key
:
string
,
defaultValue
:
T
|
undefined
)
{
this
.
_
parent
=
parent
;
constructor
(
service
:
AbstractContextKeyService
,
key
:
string
,
defaultValue
:
T
|
undefined
)
{
this
.
_
service
=
service
;
this
.
_key
=
key
;
this
.
_defaultValue
=
defaultValue
;
this
.
reset
();
}
public
set
(
value
:
T
):
void
{
this
.
_
parent
.
setContext
(
this
.
_key
,
value
);
this
.
_
service
.
setContext
(
this
.
_key
,
value
);
}
public
reset
():
void
{
if
(
typeof
this
.
_defaultValue
===
'
undefined
'
)
{
this
.
_
parent
.
removeContext
(
this
.
_key
);
this
.
_
service
.
removeContext
(
this
.
_key
);
}
else
{
this
.
_
parent
.
setContext
(
this
.
_key
,
this
.
_defaultValue
);
this
.
_
service
.
setContext
(
this
.
_key
,
this
.
_defaultValue
);
}
}
public
get
():
T
|
undefined
{
return
this
.
_
parent
.
getContextKeyValue
<
T
>
(
this
.
_key
);
return
this
.
_
service
.
getContextKeyValue
<
T
>
(
this
.
_key
);
}
}
class
SimpleContextKeyChangeEvent
implements
IContextKeyChangeEvent
{
constructor
(
private
readonly
_
key
:
string
)
{
}
constructor
(
readonly
key
:
string
)
{
}
affectsSome
(
keys
:
IReadableSet
<
string
>
):
boolean
{
return
keys
.
has
(
this
.
_
key
);
return
keys
.
has
(
this
.
key
);
}
}
class
ArrayContextKeyChangeEvent
implements
IContextKeyChangeEvent
{
constructor
(
private
readonly
_
keys
:
string
[])
{
}
constructor
(
readonly
keys
:
string
[])
{
}
affectsSome
(
keys
:
IReadableSet
<
string
>
):
boolean
{
for
(
const
key
of
this
.
_
keys
)
{
for
(
const
key
of
this
.
keys
)
{
if
(
keys
.
has
(
key
))
{
return
true
;
}
...
...
@@ -211,11 +212,23 @@ class ArrayContextKeyChangeEvent implements IContextKeyChangeEvent {
}
}
class
CompositeContextKeyChangeEvent
implements
IContextKeyChangeEvent
{
constructor
(
readonly
events
:
IContextKeyChangeEvent
[])
{
}
affectsSome
(
keys
:
IReadableSet
<
string
>
):
boolean
{
for
(
const
e
of
this
.
events
)
{
if
(
e
.
affectsSome
(
keys
))
{
return
true
;
}
}
return
false
;
}
}
export
abstract
class
AbstractContextKeyService
implements
IContextKeyService
{
public
_serviceBrand
:
any
;
protected
_isDisposed
:
boolean
;
protected
_onDidChangeContext
=
new
Emitter
<
IContextKeyChangeEvent
>
(
);
protected
_onDidChangeContext
=
new
PauseableEmitter
<
IContextKeyChangeEvent
>
({
merge
:
input
=>
new
CompositeContextKeyChangeEvent
(
input
)
}
);
protected
_myContextId
:
number
;
constructor
(
myContextId
:
number
)
{
...
...
@@ -235,6 +248,16 @@ export abstract class AbstractContextKeyService implements IContextKeyService {
public
get
onDidChangeContext
():
Event
<
IContextKeyChangeEvent
>
{
return
this
.
_onDidChangeContext
.
event
;
}
bufferChangeEvents
(
callback
:
Function
):
void
{
this
.
_onDidChangeContext
.
pause
();
try
{
callback
();
}
finally
{
this
.
_onDidChangeContext
.
resume
();
}
}
public
createScoped
(
domNode
:
IContextKeyServiceTarget
):
IContextKeyService
{
if
(
this
.
_isDisposed
)
{
throw
new
Error
(
`AbstractContextKeyService has been disposed`
);
...
...
@@ -356,7 +379,7 @@ class ScopedContextKeyService extends AbstractContextKeyService {
private
_parent
:
AbstractContextKeyService
;
private
_domNode
:
IContextKeyServiceTarget
|
undefined
;
constructor
(
parent
:
AbstractContextKeyService
,
emitter
:
Emitter
<
IContextKeyChangeEvent
>
,
domNode
?:
IContextKeyServiceTarget
)
{
constructor
(
parent
:
AbstractContextKeyService
,
emitter
:
Pauseable
Emitter
<
IContextKeyChangeEvent
>
,
domNode
?:
IContextKeyServiceTarget
)
{
super
(
parent
.
createChildContext
());
this
.
_parent
=
parent
;
this
.
_onDidChangeContext
=
emitter
;
...
...
src/vs/platform/contextkey/common/contextkey.ts
浏览文件 @
ae836215
...
...
@@ -621,6 +621,9 @@ export interface IContextKeyService {
dispose
():
void
;
onDidChangeContext
:
Event
<
IContextKeyChangeEvent
>
;
bufferChangeEvents
(
callback
:
Function
):
void
;
createKey
<
T
>
(
key
:
string
,
defaultValue
:
T
|
undefined
):
IContextKey
<
T
>
;
contextMatchesRules
(
rules
:
ContextKeyExpr
|
undefined
):
boolean
;
getContextKeyValue
<
T
>
(
key
:
string
):
T
|
undefined
;
...
...
src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts
浏览文件 @
ae836215
...
...
@@ -106,6 +106,7 @@ suite('AbstractKeybindingService', () => {
_serviceBrand
:
undefined
,
dispose
:
undefined
!
,
onDidChangeContext
:
undefined
!
,
bufferChangeEvents
()
{
},
createKey
:
undefined
!
,
contextMatchesRules
:
undefined
!
,
getContextKeyValue
:
undefined
!
,
...
...
src/vs/platform/keybinding/test/common/mockKeybindingService.ts
浏览文件 @
ae836215
...
...
@@ -53,6 +53,7 @@ export class MockContextKeyService implements IContextKeyService {
public
get
onDidChangeContext
():
Event
<
IContextKeyChangeEvent
>
{
return
Event
.
None
;
}
public
bufferChangeEvents
()
{
}
public
getContextKeyValue
(
key
:
string
)
{
const
value
=
this
.
_keys
.
get
(
key
);
if
(
value
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录