|
| 1 | +diff --git a/src/vs/workbench/contrib/commands/common/commands.contribution.ts b/src/vs/workbench/contrib/commands/common/commands.contribution.ts |
| 2 | +index 3fd6b59..04bb34f 100644 |
| 3 | +--- a/src/vs/workbench/contrib/commands/common/commands.contribution.ts |
| 4 | ++++ b/src/vs/workbench/contrib/commands/common/commands.contribution.ts |
| 5 | +@@ -9,2 +9,3 @@ import { Action2, registerAction2 } from '../../../../platform/actions/common/ac |
| 6 | + import { ICommandService } from '../../../../platform/commands/common/commands.js'; |
| 7 | ++import { ConfigurationScope, IConfigurationRegistry } from '../../../../platform/configuration/common/configurationRegistry.js'; |
| 8 | + import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js'; |
| 9 | +@@ -12,2 +13,3 @@ import { ILogService } from '../../../../platform/log/common/log.js'; |
| 10 | + import { INotificationService } from '../../../../platform/notification/common/notification.js'; |
| 11 | ++import { Registry } from '../../../../platform/registry/common/platform.js'; |
| 12 | + |
| 13 | +@@ -156,2 +158,31 @@ class RunCommands extends Action2 { |
| 14 | + |
| 15 | ++Registry.as<IConfigurationRegistry>('base.contributions.configuration') |
| 16 | ++ .registerConfiguration({ |
| 17 | ++ id: 'commands', |
| 18 | ++ order: 30, |
| 19 | ++ title: nls.localize('commandsConfigurationTitle', "Commands"), |
| 20 | ++ type: 'object', |
| 21 | ++ properties: { |
| 22 | ++ 'commands.filters': { |
| 23 | ++ enum: ['off', 'on',], |
| 24 | ++ enumItemLabels: [ |
| 25 | ++ // nls.localize('ask', "Ask"), |
| 26 | ++ nls.localize('off', "Never authorized"), |
| 27 | ++ nls.localize('on', "Always authorized"), |
| 28 | ++ ], |
| 29 | ++ enumDescriptions: [ |
| 30 | ++ // nls.localize('commands.filters.ask', 'Ask the user before executing the command.'), |
| 31 | ++ nls.localize('commands.filters.off', 'The command is never authorized.'), |
| 32 | ++ nls.localize('commands.filters.on', 'The command is always authorized.'), |
| 33 | ++ ], |
| 34 | ++ description: nls.localize('commands.filters', "Controls which commands are authorized to be executed."), |
| 35 | ++ default: { |
| 36 | ++ 'workbench.action.terminal.newLocal': 'off' |
| 37 | ++ }, |
| 38 | ++ scope: ConfigurationScope.APPLICATION, |
| 39 | ++ tags: [] |
| 40 | ++ }, |
| 41 | ++ } |
| 42 | ++ }); |
| 43 | ++ |
| 44 | + registerAction2(RunCommands); |
| 45 | +diff --git a/src/vs/workbench/services/commands/common/commandService.ts b/src/vs/workbench/services/commands/common/commandService.ts |
| 46 | +index 93d1631..f21ca94 100644 |
| 47 | +--- a/src/vs/workbench/services/commands/common/commandService.ts |
| 48 | ++++ b/src/vs/workbench/services/commands/common/commandService.ts |
| 49 | +@@ -9,2 +9,3 @@ import { Disposable } from '../../../../base/common/lifecycle.js'; |
| 50 | + import { CommandsRegistry, ICommandEvent, ICommandService } from '../../../../platform/commands/common/commands.js'; |
| 51 | ++import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js'; |
| 52 | + import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js'; |
| 53 | +@@ -30,3 +31,4 @@ export class CommandService extends Disposable implements ICommandService { |
| 54 | + @IExtensionService private readonly _extensionService: IExtensionService, |
| 55 | +- @ILogService private readonly _logService: ILogService |
| 56 | ++ @ILogService private readonly _logService: ILogService, |
| 57 | ++ @IConfigurationService private readonly configurationService: IConfigurationService |
| 58 | + ) { |
| 59 | +@@ -56,2 +58,20 @@ export class CommandService extends Disposable implements ICommandService { |
| 60 | + const commandIsRegistered = !!CommandsRegistry.getCommand(id); |
| 61 | ++ const commandFilters = this.configurationService.getValue<Record<string, 'ask' | 'off' | 'on'>>('commands.filters') ?? { 'workbench.action.terminal.newLocal': 'off' }; |
| 62 | ++ |
| 63 | ++ const filter = commandFilters[id]; |
| 64 | ++ if (filter === 'off') { |
| 65 | ++ return Promise.reject(new Error(`command '${id}' not authorized`)); |
| 66 | ++ } |
| 67 | ++ // if (filter === 'ask') { |
| 68 | ++ // const result = await showWarningMessage( |
| 69 | ++ // `Are you sure you want to execute the command "${id}"?`, |
| 70 | ++ // { modal: true }, // this makes the dialog modal (blocks other input) |
| 71 | ++ // 'Yes', |
| 72 | ++ // 'No' |
| 73 | ++ // ); |
| 74 | ++ |
| 75 | ++ // if (result === 'No') { |
| 76 | ++ // return Promise.reject(new Error(`command '${id}' not authorized`)); |
| 77 | ++ // } |
| 78 | ++ // } |
| 79 | + |
| 80 | +diff --git a/src/vs/workbench/services/commands/test/common/commandService.test.ts b/src/vs/workbench/services/commands/test/common/commandService.test.ts |
| 81 | +index ca3be11..38b0474 100644 |
| 82 | +--- a/src/vs/workbench/services/commands/test/common/commandService.test.ts |
| 83 | ++++ b/src/vs/workbench/services/commands/test/common/commandService.test.ts |
| 84 | +@@ -12,2 +12,6 @@ import { NullExtensionService } from '../../../extensions/common/extensions.js'; |
| 85 | + import { CommandService } from '../../common/commandService.js'; |
| 86 | ++import { NullPolicyService } from '../../../../../platform/policy/common/policy.js'; |
| 87 | ++import { FileService } from '../../../../../platform/files/common/fileService.js'; |
| 88 | ++import { ConfigurationService } from '../../../../../platform/configuration/common/configurationService.js'; |
| 89 | ++import { URI } from '../../../../../base/common/uri.js'; |
| 90 | + |
| 91 | +@@ -16,4 +20,16 @@ suite('CommandService', function () { |
| 92 | + const store = ensureNoDisposablesAreLeakedInTestSuite(); |
| 93 | ++ const testDisposables = ensureNoDisposablesAreLeakedInTestSuite(); |
| 94 | ++ let nullConfigService: ConfigurationService |
| 95 | + |
| 96 | + setup(function () { |
| 97 | ++ const nullPolicyService = new NullPolicyService(); |
| 98 | ++ const nullLogService = testDisposables.add(new NullLogService()); |
| 99 | ++ const nullFileService = testDisposables.add(new FileService(nullLogService)); |
| 100 | ++ nullConfigService = testDisposables.add(new ConfigurationService( |
| 101 | ++ URI.file('/config.json'), |
| 102 | ++ nullFileService, |
| 103 | ++ nullPolicyService, |
| 104 | ++ nullLogService, |
| 105 | ++ )); |
| 106 | ++ |
| 107 | + store.add(CommandsRegistry.registerCommand('foo', function () { })); |
| 108 | +@@ -30,3 +46,3 @@ suite('CommandService', function () { |
| 109 | + } |
| 110 | +- }, new NullLogService())); |
| 111 | ++ }, new NullLogService(), nullConfigService)); |
| 112 | + |
| 113 | +@@ -50,3 +66,3 @@ suite('CommandService', function () { |
| 114 | + |
| 115 | +- const service = store.add(new CommandService(new InstantiationService(), extensionService, new NullLogService())); |
| 116 | ++ const service = store.add(new CommandService(new InstantiationService(), extensionService, new NullLogService(), nullConfigService)); |
| 117 | + |
| 118 | +@@ -68,3 +84,3 @@ suite('CommandService', function () { |
| 119 | + } |
| 120 | +- }, new NullLogService())); |
| 121 | ++ }, new NullLogService(), nullConfigService)); |
| 122 | + |
| 123 | +@@ -85,3 +101,3 @@ suite('CommandService', function () { |
| 124 | + } |
| 125 | +- }, new NullLogService())); |
| 126 | ++ }, new NullLogService(), nullConfigService)); |
| 127 | + |
| 128 | +@@ -125,3 +141,3 @@ suite('CommandService', function () { |
| 129 | + |
| 130 | +- }, new NullLogService())); |
| 131 | ++ }, new NullLogService(), nullConfigService)); |
| 132 | + |
| 133 | +@@ -166,3 +182,3 @@ suite('CommandService', function () { |
| 134 | + |
| 135 | +- }, new NullLogService())); |
| 136 | ++ }, new NullLogService(), nullConfigService)); |
| 137 | + |
| 138 | +@@ -187,3 +203,3 @@ suite('CommandService', function () { |
| 139 | + }; |
| 140 | +- const service = store.add(new CommandService(new InstantiationService(), extensionService, new NullLogService())); |
| 141 | ++ const service = store.add(new CommandService(new InstantiationService(), extensionService, new NullLogService(), nullConfigService)); |
| 142 | + |
0 commit comments