mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
parent
86bb14550b
commit
f929531dfb
|
@ -38,7 +38,7 @@ class TypeScriptAutoFixProvider implements vscode.CodeActionProvider {
|
|||
context: vscode.CodeActionContext,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<vscode.CodeAction[] | undefined> {
|
||||
if (!context.only || !(context.only.contains(vscode.CodeActionKind.SourceAutoFix) || vscode.CodeActionKind.SourceAutoFix.contains(context.only))) {
|
||||
if (!context.only || !vscode.CodeActionKind.SourceAutoFix.intersects(context.only)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ export class OrganizeImportsCodeActionProvider implements vscode.CodeActionProvi
|
|||
return [];
|
||||
}
|
||||
|
||||
if (!context.only || !(context.only.contains(vscode.CodeActionKind.SourceOrganizeImports) || vscode.CodeActionKind.SourceOrganizeImports.contains(context.only))) {
|
||||
if (!context.only || !vscode.CodeActionKind.SourceOrganizeImports.intersects(context.only)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
15
src/vs/vscode.d.ts
vendored
15
src/vs/vscode.d.ts
vendored
|
@ -2029,9 +2029,20 @@ declare module 'vscode' {
|
|||
append(parts: string): CodeActionKind;
|
||||
|
||||
/**
|
||||
* Does this kind contain `other`?
|
||||
* Checks if this code action kind intersects `other`.
|
||||
*
|
||||
* The kind `"refactor"` for example contains `"refactor.extract"` and ``"refactor.extract.function"`, but not `"unicorn.refactor.extract"` or `"refactory.extract"`
|
||||
* The kind `"refactor.extract"` for example intersects `refactor`, `"refactor.extract"` and ``"refactor.extract.function"`,
|
||||
* but not `"unicorn.refactor.extract"`, or `"refactor.extractAll"`.
|
||||
*
|
||||
* @param other Kind to check.
|
||||
*/
|
||||
intersects(other: CodeActionKind): boolean;
|
||||
|
||||
/**
|
||||
* Checks if `other` is a sub-kind of this `CodeActionKind`.
|
||||
*
|
||||
* The kind `"refactor.extract"` for example contains `"refactor.extract"` and ``"refactor.extract.function"`,
|
||||
* but not `"unicorn.refactor.extract"`, or `"refactor.extractAll"` or `refactor`.
|
||||
*
|
||||
* @param other Kind to check.
|
||||
*/
|
||||
|
|
|
@ -1032,6 +1032,10 @@ export class CodeActionKind {
|
|||
return new CodeActionKind(this.value ? this.value + CodeActionKind.sep + parts : parts);
|
||||
}
|
||||
|
||||
public intersects(other: CodeActionKind): boolean {
|
||||
return this.contains(other) || other.contains(this);
|
||||
}
|
||||
|
||||
public contains(other: CodeActionKind): boolean {
|
||||
return this.value === other.value || startsWith(other.value, this.value + CodeActionKind.sep);
|
||||
}
|
||||
|
|
|
@ -532,4 +532,24 @@ suite('ExtHostTypes', function () {
|
|||
assert.ok(error instanceof Error);
|
||||
assert.ok(error instanceof types.FileSystemError);
|
||||
});
|
||||
|
||||
test('CodeActionKind contains', () => {
|
||||
assert.ok(types.CodeActionKind.RefactorExtract.contains(types.CodeActionKind.RefactorExtract));
|
||||
assert.ok(types.CodeActionKind.RefactorExtract.contains(types.CodeActionKind.RefactorExtract.append('other')));
|
||||
|
||||
assert.ok(!types.CodeActionKind.RefactorExtract.contains(types.CodeActionKind.Refactor));
|
||||
assert.ok(!types.CodeActionKind.RefactorExtract.contains(types.CodeActionKind.Refactor.append('other')));
|
||||
assert.ok(!types.CodeActionKind.RefactorExtract.contains(types.CodeActionKind.Empty.append('other').append('refactor')));
|
||||
assert.ok(!types.CodeActionKind.RefactorExtract.contains(types.CodeActionKind.Empty.append('refactory')));
|
||||
});
|
||||
|
||||
test('CodeActionKind intersects', () => {
|
||||
assert.ok(types.CodeActionKind.RefactorExtract.intersects(types.CodeActionKind.RefactorExtract));
|
||||
assert.ok(types.CodeActionKind.RefactorExtract.intersects(types.CodeActionKind.Refactor));
|
||||
assert.ok(types.CodeActionKind.RefactorExtract.intersects(types.CodeActionKind.RefactorExtract.append('other')));
|
||||
|
||||
assert.ok(!types.CodeActionKind.RefactorExtract.intersects(types.CodeActionKind.Refactor.append('other')));
|
||||
assert.ok(!types.CodeActionKind.RefactorExtract.intersects(types.CodeActionKind.Empty.append('other').append('refactor')));
|
||||
assert.ok(!types.CodeActionKind.RefactorExtract.intersects(types.CodeActionKind.Empty.append('refactory')));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue