Skip to content

Commit

Permalink
Fixes #46445: Make setContext an API command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Dec 6, 2022
1 parent 1d7f930 commit 66939b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/vs/platform/contextkey/browser/contextKeyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ContextKeyExpression, ContextKeyInfo, ContextKeyValue, IContext, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IReadableSet, RawContextKey, SET_CONTEXT_COMMAND_ID } from 'vs/platform/contextkey/common/contextkey';
import { ContextKeyExpression, ContextKeyInfo, ContextKeyValue, IContext, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IReadableSet, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';

const KEYBINDING_CONTEXT_ATTR = 'data-keybinding-context';
Expand Down Expand Up @@ -619,7 +619,7 @@ function stringifyURIs(contextValue: any): any {
});
}

CommandsRegistry.registerCommand(SET_CONTEXT_COMMAND_ID, setContext);
CommandsRegistry.registerCommand('_setContext', setContext);

CommandsRegistry.registerCommand({
id: 'getContextKeyInfo',
Expand Down
2 changes: 0 additions & 2 deletions src/vs/platform/contextkey/common/contextkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1647,8 +1647,6 @@ export interface IContextKeyService {
updateParent(parentContextKeyService: IContextKeyService): void;
}

export const SET_CONTEXT_COMMAND_ID = 'setContext';

function cmp1(key1: string, key2: string): number {
if (key1 < key2) {
return -1;
Expand Down
9 changes: 9 additions & 0 deletions src/vs/workbench/api/common/extHostApiCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,15 @@ const newCommands: ApiCommand[] = [
'vscode.experimental.editSession.continue', '_workbench.editSessions.actions.continueEditSession', 'Continue the current edit session in a different workspace',
[ApiCommandArgument.Uri.with('workspaceUri', 'The target workspace to continue the current edit session in')],
ApiCommandResult.Void
),
// --- context keys
new ApiCommand(
'setContext', '_setContext', 'Set a custom context key value that can be used in when clauses.',
[
ApiCommandArgument.String.with('name', 'The context key name'),
new ApiCommandArgument('value', 'The context key value', () => true, v => v),
],
ApiCommandResult.Void
)
];

Expand Down

0 comments on commit 66939b4

Please sign in to comment.