未验证 提交 f1cfe2d3 编写于 作者: T turara 提交者: GitHub

Update CodeActionOnSaveParticipant (#108193)

* Update CodeActionOnSaveParticipant

Add filtering CodeActionKind.SourceFixAll derivatives for codeActionsOnSave

* Add CodeActionOnSaveParticipant#createCodeActionsOnSave method to remove subsets.

Fixes #106924.
上级 2b75c3d5
......@@ -287,8 +287,7 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant {
? setting
: Object.keys(setting).filter(x => setting[x]);
const codeActionsOnSave = settingItems
.map(x => new CodeActionKind(x));
const codeActionsOnSave = this.createCodeActionsOnSave(settingItems);
if (!Array.isArray(setting)) {
codeActionsOnSave.sort((a, b) => {
......@@ -319,6 +318,28 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant {
await this.applyOnSaveActions(textEditorModel, codeActionsOnSave, excludedActions, progress, token);
}
private createCodeActionsOnSave(settingItems: string[]): CodeActionKind[] {
const actionSeeds = new Set<string>();
// Remove subsets
const len = settingItems.length;
outer: for (let i = 0; i < len; i++) {
const s1 = settingItems[i];
for (let j = 0; j < len; j++) {
if (j === i) {
continue;
}
const s2 = settingItems[j];
if (s1.startsWith(s2) && s1.length > s2.length) {
continue outer;
}
}
actionSeeds.add(s1);
}
return Array.from(actionSeeds).map(x => new CodeActionKind(x));
}
private async applyOnSaveActions(model: ITextModel, codeActionsOnSave: readonly CodeActionKind[], excludes: readonly CodeActionKind[], progress: IProgress<IProgressStep>, token: CancellationToken): Promise<void> {
const getActionProgress = new class implements IProgress<CodeActionProvider> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册