Make setContext an API command (#168215)

Fixes #46445: Make `setContext` an API command
This commit is contained in:
Alexandru Dima 2022-12-06 21:17:10 +01:00 committed by GitHub
parent 07892e4ef2
commit bafda10a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View file

@ -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';
@ -619,7 +619,7 @@ function stringifyURIs(contextValue: any): any {
});
}
CommandsRegistry.registerCommand(SET_CONTEXT_COMMAND_ID, setContext);
CommandsRegistry.registerCommand('_setContext', setContext);
CommandsRegistry.registerCommand({
id: 'getContextKeyInfo',

View file

@ -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;

View file

@ -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
)
];