mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
initial support (#92681)
This commit is contained in:
parent
662fef21e1
commit
14514ea39a
|
@ -26,11 +26,19 @@ const codeActionsOnSaveDefaultProperties = Object.freeze<IJSONSchemaMap>({
|
|||
});
|
||||
|
||||
const codeActionsOnSaveSchema: IConfigurationPropertySchema = {
|
||||
type: 'object',
|
||||
properties: codeActionsOnSaveDefaultProperties,
|
||||
'additionalProperties': {
|
||||
type: 'boolean'
|
||||
},
|
||||
oneOf: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: codeActionsOnSaveDefaultProperties,
|
||||
additionalProperties: {
|
||||
type: 'boolean'
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'array',
|
||||
items: { type: 'string' }
|
||||
}
|
||||
],
|
||||
default: {},
|
||||
description: nls.localize('codeActionsOnSave', "Code action kinds to be run on save."),
|
||||
scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,
|
||||
|
|
|
@ -241,14 +241,20 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant {
|
|||
const model = editorModel.textEditorModel;
|
||||
|
||||
const settingsOverrides = { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.resource };
|
||||
const setting = this.configurationService.getValue<{ [kind: string]: boolean }>('editor.codeActionsOnSave', settingsOverrides);
|
||||
const setting = this.configurationService.getValue<{ [kind: string]: boolean } | string[]>('editor.codeActionsOnSave', settingsOverrides);
|
||||
if (!setting) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const codeActionsOnSave = Object.keys(setting)
|
||||
.filter(x => setting[x]).map(x => new CodeActionKind(x))
|
||||
.sort((a, b) => {
|
||||
const settingItems: string[] = Array.isArray(setting)
|
||||
? setting
|
||||
: Object.keys(setting).filter(x => setting[x]);
|
||||
|
||||
const codeActionsOnSave = settingItems
|
||||
.map(x => new CodeActionKind(x));
|
||||
|
||||
if (!Array.isArray(setting)) {
|
||||
codeActionsOnSave.sort((a, b) => {
|
||||
if (CodeActionKind.SourceFixAll.contains(a)) {
|
||||
if (CodeActionKind.SourceFixAll.contains(b)) {
|
||||
return 0;
|
||||
|
@ -260,14 +266,17 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant {
|
|||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
if (!codeActionsOnSave.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const excludedActions = Object.keys(setting)
|
||||
.filter(x => setting[x] === false)
|
||||
.map(x => new CodeActionKind(x));
|
||||
const excludedActions = Array.isArray(setting)
|
||||
? []
|
||||
: Object.keys(setting)
|
||||
.filter(x => setting[x] === false)
|
||||
.map(x => new CodeActionKind(x));
|
||||
|
||||
progress.report({ message: localize('codeaction', "Quick Fixes") });
|
||||
await this.applyOnSaveActions(model, codeActionsOnSave, excludedActions, progress, token);
|
||||
|
|
Loading…
Reference in a new issue