Skip to content

Commit

Permalink
Use CodeActionKind.intersects internally
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Jan 22, 2019
1 parent 401dd1c commit 3ff312e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/vs/editor/contrib/codeAction/codeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export function getCodeActions(
}

// Avoid calling providers that we know will not return code actions of interest
return provider.providedCodeActionKinds.some(providedKind => {
return provider.providedCodeActionKinds.map(kind => new CodeActionKind(kind)).some(providedKind => {
// Filter out actions by kind
// The provided kind can be either a subset of a superset of the filtered kind
if (trigger.filter && trigger.filter.kind && !(trigger.filter.kind.contains(providedKind) || new CodeActionKind(providedKind).contains(trigger.filter.kind.value))) {
if (trigger.filter && trigger.filter.kind && !trigger.filter.kind.intersects(providedKind)) {
return false;
}

Expand Down Expand Up @@ -71,11 +71,11 @@ export function getCodeActions(

function isValidAction(filter: CodeActionFilter | undefined, action: CodeAction): boolean {
return action
&& isValidActionKind(filter, action.kind)
&& isValidActionKind(filter, action.kind ? new CodeActionKind(action.kind) : undefined)
&& (filter && filter.onlyIncludePreferredActions ? !!action.isPreferred : true);
}

function isValidActionKind(filter: CodeActionFilter | undefined, kind: string | undefined): boolean {
function isValidActionKind(filter: CodeActionFilter | undefined, kind: CodeActionKind | undefined): boolean {
// Filter out actions by kind
if (filter && filter.kind && (!kind || !filter.kind.contains(kind))) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/codeAction/codeActionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class RefactorAction extends EditorAction {
});
return showCodeActionsForEditorSelection(editor,
nls.localize('editor.action.refactor.noneMessage', "No refactorings available"),
{ kind: CodeActionKind.Refactor.contains(args.kind.value) ? args.kind : CodeActionKind.Empty },
{ kind: CodeActionKind.Refactor.contains(args.kind) ? args.kind : CodeActionKind.Empty },
args.apply);
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ export class SourceAction extends EditorAction {
});
return showCodeActionsForEditorSelection(editor,
nls.localize('editor.action.source.noneMessage', "No source actions available"),
{ kind: CodeActionKind.Source.contains(args.kind.value) ? args.kind : CodeActionKind.Empty, includeSourceActions: true },
{ kind: CodeActionKind.Source.contains(args.kind) ? args.kind : CodeActionKind.Empty, includeSourceActions: true },
args.apply);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/vs/editor/contrib/codeAction/codeActionTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export class CodeActionKind {
public readonly value: string
) { }

public contains(other: string): boolean {
return this.value === other || startsWith(other, this.value + CodeActionKind.sep);
public contains(other: CodeActionKind): boolean {
return this.value === other.value || startsWith(other.value, this.value + CodeActionKind.sep);
}

public intersects(other: CodeActionKind): boolean {
return this.contains(other) || other.contains(this);
}
}

Expand Down

0 comments on commit 3ff312e

Please sign in to comment.