@codingame/monaco-vscode-keybindings-service-override 1.85.0 → 1.85.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/keybindings.js CHANGED
@@ -27,6 +27,7 @@ import getServiceOverride$1, { initFile } from '@codingame/monaco-vscode-files-s
27
27
  import { onRenderWorkbench } from 'vscode/lifecycle';
28
28
  import 'vscode/vscode/vs/workbench/browser/workbench.contribution';
29
29
  import './vscode/src/vs/workbench/contrib/keybindings/browser/keybindings.contribution.js';
30
+ import './vscode/src/vs/workbench/contrib/commands/common/commands.contribution.js';
30
31
 
31
32
  const defaultUserKeybindindsFile = ( URI.from({ scheme: Schemas.vscodeUserData, path: '/User/keybindings.json' }));
32
33
  async function initUserKeybindings(configurationJson, options, file = defaultUserKeybindindsFile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-keybindings-service-override",
3
- "version": "1.85.0",
3
+ "version": "1.85.1",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,8 +18,8 @@
18
18
  "module": "index.js",
19
19
  "types": "index.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@1.85.0",
21
+ "vscode": "npm:@codingame/monaco-vscode-api@1.85.1",
22
22
  "monaco-editor": "0.45.0",
23
- "@codingame/monaco-vscode-files-service-override": "1.85.0"
23
+ "@codingame/monaco-vscode-files-service-override": "1.85.1"
24
24
  }
25
25
  }
@@ -0,0 +1,146 @@
1
+ import * as nls from 'monaco-editor/esm/vs/nls.js';
2
+ import { registerAction2, Action2 } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
3
+ import { ICommandService } from 'monaco-editor/esm/vs/platform/commands/common/commands.js';
4
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
5
+ import { INotificationService } from 'monaco-editor/esm/vs/platform/notification/common/notification.js';
6
+
7
+ class RunCommands extends Action2 {
8
+ constructor() {
9
+ super({
10
+ id: 'runCommands',
11
+ title: { value: ( nls.localizeWithPath(
12
+ 'vs/workbench/contrib/commands/common/commands.contribution',
13
+ 'runCommands',
14
+ "Run Commands"
15
+ )), original: 'Run Commands' },
16
+ f1: false,
17
+ metadata: {
18
+ description: ( nls.localizeWithPath(
19
+ 'vs/workbench/contrib/commands/common/commands.contribution',
20
+ 'runCommands.description',
21
+ "Run several commands"
22
+ )),
23
+ args: [
24
+ {
25
+ name: 'args',
26
+ schema: {
27
+ type: 'object',
28
+ required: ['commands'],
29
+ properties: {
30
+ commands: {
31
+ type: 'array',
32
+ description: ( nls.localizeWithPath(
33
+ 'vs/workbench/contrib/commands/common/commands.contribution',
34
+ 'runCommands.commands',
35
+ "Commands to run"
36
+ )),
37
+ items: {
38
+ anyOf: [
39
+ {
40
+ $ref: 'vscode://schemas/keybindings#/definitions/commandNames'
41
+ },
42
+ {
43
+ type: 'string',
44
+ },
45
+ {
46
+ type: 'object',
47
+ required: ['command'],
48
+ properties: {
49
+ command: {
50
+ 'anyOf': [
51
+ {
52
+ $ref: 'vscode://schemas/keybindings#/definitions/commandNames'
53
+ },
54
+ {
55
+ type: 'string'
56
+ },
57
+ ]
58
+ }
59
+ },
60
+ $ref: 'vscode://schemas/keybindings#/definitions/commandsSchemas'
61
+ }
62
+ ]
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ]
69
+ }
70
+ });
71
+ }
72
+ async run(accessor, args) {
73
+ const notificationService = accessor.get(INotificationService);
74
+ if (!this._isCommandArgs(args)) {
75
+ notificationService.error(( nls.localizeWithPath(
76
+ 'vs/workbench/contrib/commands/common/commands.contribution',
77
+ 'runCommands.invalidArgs',
78
+ "'runCommands' has received an argument with incorrect type. Please, review the argument passed to the command."
79
+ )));
80
+ return;
81
+ }
82
+ if (args.commands.length === 0) {
83
+ notificationService.warn(( nls.localizeWithPath(
84
+ 'vs/workbench/contrib/commands/common/commands.contribution',
85
+ 'runCommands.noCommandsToRun',
86
+ "'runCommands' has not received commands to run. Did you forget to pass commands in the 'runCommands' argument?"
87
+ )));
88
+ return;
89
+ }
90
+ const commandService = accessor.get(ICommandService);
91
+ const logService = accessor.get(ILogService);
92
+ let i = 0;
93
+ try {
94
+ for (; i < args.commands.length; ++i) {
95
+ const cmd = args.commands[i];
96
+ logService.debug(`runCommands: executing ${i}-th command: ${JSON.stringify(cmd)}`);
97
+ const r = await this._runCommand(commandService, cmd);
98
+ logService.debug(`runCommands: executed ${i}-th command with return value: ${JSON.stringify(r)}`);
99
+ }
100
+ }
101
+ catch (err) {
102
+ logService.debug(`runCommands: executing ${i}-th command resulted in an error: ${err instanceof Error ? err.message : JSON.stringify(err)}`);
103
+ notificationService.error(err);
104
+ }
105
+ }
106
+ _isCommandArgs(args) {
107
+ if (!args || typeof args !== 'object') {
108
+ return false;
109
+ }
110
+ if (!('commands' in args) || !Array.isArray(args.commands)) {
111
+ return false;
112
+ }
113
+ for (const cmd of args.commands) {
114
+ if (typeof cmd === 'string') {
115
+ continue;
116
+ }
117
+ if (typeof cmd === 'object' && typeof cmd.command === 'string') {
118
+ continue;
119
+ }
120
+ return false;
121
+ }
122
+ return true;
123
+ }
124
+ _runCommand(commandService, cmd) {
125
+ let commandID, commandArgs;
126
+ if (typeof cmd === 'string') {
127
+ commandID = cmd;
128
+ }
129
+ else {
130
+ commandID = cmd.command;
131
+ commandArgs = cmd.args;
132
+ }
133
+ if (commandArgs === undefined) {
134
+ return commandService.executeCommand(commandID);
135
+ }
136
+ else {
137
+ if (Array.isArray(commandArgs)) {
138
+ return commandService.executeCommand(commandID, ...commandArgs);
139
+ }
140
+ else {
141
+ return commandService.executeCommand(commandID, commandArgs);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ registerAction2(RunCommands);