Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vscode] parse view contribution "when" clause context #6068

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core/src/browser/context-key-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ContextKey<T> {
reset(): void;
get(): T | undefined;
}

export namespace ContextKey {
// tslint:disable-next-line:no-any
export const None: ContextKey<any> = Object.freeze({
Expand Down Expand Up @@ -54,4 +55,11 @@ export class ContextKeyService {
return true;
}

/**
* It should be implemented by an extension, e.g. by the monaco extension.
*/
parseKeys(expression: string): Set<string> {
return new Set<string>();
}

}
4 changes: 4 additions & 0 deletions packages/monaco/src/browser/monaco-context-key-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ export class MonacoContextKeyService extends ContextKeyService {
return expression;
}

parseKeys(expression: string): Set<string> {
return new Set<string>(monaco.contextkey.ContextKeyExpr.deserialize(expression).keys());
}

}
1 change: 1 addition & 0 deletions packages/monaco/src/typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ declare module monaco.contextKeyService {

declare module monaco.contextkey {
export class ContextKeyExpr {
keys(): string[];
static deserialize(when: string): ContextKeyExpr;
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
private readonly views = new Map<string, [string, View]>();
private readonly viewContainers = new Map<string, [string, ViewContainerTitleOptions]>();
private readonly containerViews = new Map<string, string[]>();
private readonly viewClauseContexts = new Map<string, Set<string>>();

private readonly viewDataProviders = new Map<string, ViewDataProvider>();
private readonly viewDataState = new Map<string, object>();
Expand Down Expand Up @@ -138,10 +139,8 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
});
this.contextKeyService.onDidChange(e => {
for (const [, view] of this.views.values()) {
if (view.when === undefined) {
continue;
}
if (e.affects(new Set([view.when]))) {
const clauseContext = this.viewClauseContexts.get(view.id);
if (clauseContext && e.affects(clauseContext)) {
this.updateViewVisibility(view.id);
}
}
Expand Down Expand Up @@ -231,6 +230,9 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
const containerViews = this.containerViews.get(viewContainerId) || [];
containerViews.push(view.id);
this.containerViews.set(viewContainerId, containerViews);
if (view.when) {
this.viewClauseContexts.set(view.id, this.contextKeyService.parseKeys(view.when));
}
this.quickView.registerItem({
label: view.name,
open: async () => {
Expand Down