Skip to content

Commit f1b07bd

Browse files
authored
Fix: Allows Arrays in Setting for Code Actions on Save (#194930)
* allows arrays to be used in code actions on save * revert changes in non-important files * code cleanup * adding back in for proper intellisense * added more specific logic check * fixes contains issue: * added additional fix for overwritten duplicate subsets. reverting larger, less necessary code
1 parent df114fc commit f1b07bd

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Diff for: src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const codeActionsOnSaveSchema: IConfigurationPropertySchema = {
5252
}
5353
],
5454
markdownDescription: nls.localize('editor.codeActionsOnSave', 'Run CodeActions for the editor on save. CodeActions must be specified and the editor must not be shutting down. Example: `"source.organizeImports": "explicit" `'),
55-
type: 'object',
55+
type: ['object', 'array'],
5656
additionalProperties: {
5757
type: ['string', 'boolean'],
5858
enum: ['always', 'explicit', 'never', true, false],

Diff for: src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant {
281281
const settingsOverrides = { overrideIdentifier: textEditorModel.getLanguageId(), resource: textEditorModel.uri };
282282

283283
// Convert boolean values to strings
284-
const setting = this.configurationService.getValue<{ [kind: string]: string | boolean }>('editor.codeActionsOnSave', settingsOverrides);
284+
const setting = this.configurationService.getValue<{ [kind: string]: string | boolean } | string[]>('editor.codeActionsOnSave', settingsOverrides);
285285
if (!setting) {
286286
return undefined;
287287
}
@@ -290,16 +290,15 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant {
290290
return undefined;
291291
}
292292

293-
const convertedSetting: { [kind: string]: string } = {};
294-
for (const key in setting) {
295-
if (typeof setting[key] === 'boolean') {
296-
convertedSetting[key] = setting[key] ? 'explicit' : 'never';
297-
} else if (typeof setting[key] === 'string') {
298-
convertedSetting[key] = setting[key] as string;
299-
}
293+
if (env.reason !== SaveReason.EXPLICIT && Array.isArray(setting)) {
294+
return undefined;
300295
}
301296

302-
const codeActionsOnSave = this.createCodeActionsOnSave(Object.keys(convertedSetting));
297+
const settingItems: string[] = Array.isArray(setting)
298+
? setting
299+
: Object.keys(setting).filter(x => setting[x] && setting[x] !== 'never');
300+
301+
const codeActionsOnSave = this.createCodeActionsOnSave(settingItems);
303302

304303
if (!Array.isArray(setting)) {
305304
codeActionsOnSave.sort((a, b) => {
@@ -319,14 +318,15 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant {
319318
if (!codeActionsOnSave.length) {
320319
return undefined;
321320
}
322-
323-
const excludedActions = Object.keys(setting)
324-
.filter(x => convertedSetting[x] === 'never' || false)
325-
.map(x => new CodeActionKind(x));
321+
const excludedActions = Array.isArray(setting)
322+
? []
323+
: Object.keys(setting)
324+
.filter(x => setting[x] === 'never' || false)
325+
.map(x => new CodeActionKind(x));
326326

327327
progress.report({ message: localize('codeaction', "Quick Fixes") });
328328

329-
const filteredSaveList = codeActionsOnSave.filter(x => convertedSetting[x.value] === 'always' || (convertedSetting[x.value] === 'explicit') && env.reason === SaveReason.EXPLICIT);
329+
const filteredSaveList = Array.isArray(setting) ? codeActionsOnSave : codeActionsOnSave.filter(x => setting[x.value] === 'always' || ((setting[x.value] === 'explicit' || setting[x.value] === true) && env.reason === SaveReason.EXPLICIT));
330330

331331
await this.applyOnSaveActions(textEditorModel, filteredSaveList, excludedActions, progress, token);
332332
}

0 commit comments

Comments
 (0)