提交 787603c5 编写于 作者: M Matt Bierner

Move code action sorting into CodeActionSet

上级 0e580b6e
...@@ -16,9 +16,26 @@ import { IModelService } from 'vs/editor/common/services/modelService'; ...@@ -16,9 +16,26 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import { CodeActionKind, CodeActionTrigger, filtersAction, mayIncludeActionsOfKind, CodeActionFilter } from './codeActionTrigger'; import { CodeActionKind, CodeActionTrigger, filtersAction, mayIncludeActionsOfKind, CodeActionFilter } from './codeActionTrigger';
export class CodeActionSet { export class CodeActionSet {
public constructor(
public readonly actions: ReadonlyArray<CodeAction> private static codeActionsComparator(a: CodeAction, b: CodeAction): number {
) { } if (isNonEmptyArray(a.diagnostics)) {
if (isNonEmptyArray(b.diagnostics)) {
return a.diagnostics[0].message.localeCompare(b.diagnostics[0].message);
} else {
return -1;
}
} else if (isNonEmptyArray(b.diagnostics)) {
return 1;
} else {
return 0; // both have no diagnostics
}
}
public readonly actions: ReadonlyArray<CodeAction>;
public constructor(actions: CodeAction[]) {
this.actions = mergeSort(actions, CodeActionSet.codeActionsComparator);
}
public get hasAutoFix() { public get hasAutoFix() {
return this.actions.some(fix => !!fix.kind && CodeActionKind.QuickFix.contains(new CodeActionKind(fix.kind)) && !!fix.isPreferred); return this.actions.some(fix => !!fix.kind && CodeActionKind.QuickFix.contains(new CodeActionKind(fix.kind)) && !!fix.isPreferred);
...@@ -56,7 +73,6 @@ export function getCodeActions( ...@@ -56,7 +73,6 @@ export function getCodeActions(
return Promise.all(promises) return Promise.all(promises)
.then(flatten) .then(flatten)
.then(allCodeActions => mergeSort(allCodeActions, codeActionsComparator))
.then(actions => new CodeActionSet(actions)); .then(actions => new CodeActionSet(actions));
} }
...@@ -75,20 +91,6 @@ function getCodeActionProviders( ...@@ -75,20 +91,6 @@ function getCodeActionProviders(
}); });
} }
function codeActionsComparator(a: CodeAction, b: CodeAction): number {
if (isNonEmptyArray(a.diagnostics)) {
if (isNonEmptyArray(b.diagnostics)) {
return a.diagnostics[0].message.localeCompare(b.diagnostics[0].message);
} else {
return -1;
}
} else if (isNonEmptyArray(b.diagnostics)) {
return 1;
} else {
return 0; // both have no diagnostics
}
}
registerLanguageCommand('_executeCodeActionProvider', function (accessor, args): Promise<ReadonlyArray<CodeAction>> { registerLanguageCommand('_executeCodeActionProvider', function (accessor, args): Promise<ReadonlyArray<CodeAction>> {
const { resource, range, kind } = args; const { resource, range, kind } = args;
if (!(resource instanceof URI) || !Range.isIRange(range)) { if (!(resource instanceof URI) || !Range.isIRange(range)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册