Skip to content

Commit

Permalink
Always require getCodeActions.trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Jan 22, 2019
1 parent 7b095ea commit 8c75f07
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
20 changes: 6 additions & 14 deletions src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
},
"include": [
"./typings",
"./vs/base/browser/**/*.ts",
"./vs/base/common/**/*.ts",
"./vs/base/node/**/*.ts",
"./vs/base/browser/**/*.ts",
"./vs/editor/common/**/*.ts",
"./vs/editor/browser/**/*.ts",
"./vs/editor/test/**/*.ts",
"./vs/editor/contrib/smartSelect/**/*.ts",
"./vs/editor/common/**/*.ts",
"./vs/editor/contrib/codeAction/**/*.ts",
"./vs/editor/contrib/format/**/*.ts",
"./vs/editor/contrib/gotoError/**/*.ts",
"./vs/editor/contrib/inPlaceReplace/**/*.ts",
"./vs/editor/contrib/smartSelect/**/*.ts",
"./vs/editor/contrib/snippet/**/*.ts",
"./vs/editor/contrib/suggest/**/*.ts",
"./vs/editor/contrib/snippet/**/*.ts"
"./vs/editor/test/**/*.ts",
],
"files": [
"./vs/base/parts/contextmenu/common/contextmenu.ts",
Expand Down Expand Up @@ -156,15 +157,6 @@
"./vs/editor/contrib/caretOperations/test/moveCarretCommand.test.ts",
"./vs/editor/contrib/caretOperations/transpose.ts",
"./vs/editor/contrib/clipboard/clipboard.ts",
"./vs/editor/contrib/codeAction/codeAction.ts",
"./vs/editor/contrib/codeAction/codeActionCommands.ts",
"./vs/editor/contrib/codeAction/codeActionContributions.ts",
"./vs/editor/contrib/codeAction/codeActionModel.ts",
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
"./vs/editor/contrib/codeAction/codeActionWidget.ts",
"./vs/editor/contrib/codeAction/lightBulbWidget.ts",
"./vs/editor/contrib/codeAction/test/codeAction.test.ts",
"./vs/editor/contrib/codeAction/test/codeActionModel.test.ts",
"./vs/editor/contrib/codelens/codelens.ts",
"./vs/editor/contrib/codelens/codelensController.ts",
"./vs/editor/contrib/codelens/codelensWidget.ts",
Expand Down
12 changes: 6 additions & 6 deletions src/vs/editor/contrib/codeAction/codeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import { CodeActionFilter, CodeActionKind, CodeActionTrigger } from './codeActio
export function getCodeActions(
model: ITextModel,
rangeOrSelection: Range | Selection,
trigger: CodeActionTrigger | undefined,
trigger: CodeActionTrigger,
token: CancellationToken
): Promise<CodeAction[]> {
const codeActionContext: CodeActionContext = {
only: trigger && trigger.filter && trigger.filter.kind ? trigger.filter.kind.value : undefined,
trigger: trigger && trigger.type === 'manual' ? CodeActionTriggerKind.Manual : CodeActionTriggerKind.Automatic
only: trigger.filter && trigger.filter.kind ? trigger.filter.kind.value : undefined,
trigger: trigger.type === 'manual' ? CodeActionTriggerKind.Manual : CodeActionTriggerKind.Automatic
};

const promises = CodeActionProviderRegistry.all(model)
Expand All @@ -36,12 +36,12 @@ export function getCodeActions(
return provider.providedCodeActionKinds.some(providedKind => {
// Filter out actions by kind
// The provided kind can be either a subset of a superset of the filtered kind
if (trigger && 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.contains(providedKind) || new CodeActionKind(providedKind).contains(trigger.filter.kind.value))) {
return false;
}

// Don't return source actions unless they are explicitly requested
if (trigger && CodeActionKind.Source.contains(providedKind) && (!trigger.filter || !trigger.filter.includeSourceActions)) {
if (CodeActionKind.Source.contains(providedKind) && (!trigger.filter || !trigger.filter.includeSourceActions)) {
return false;
}

Expand All @@ -53,7 +53,7 @@ export function getCodeActions(
if (!Array.isArray(providedCodeActions)) {
return [];
}
return providedCodeActions.filter(action => isValidAction(trigger && trigger.filter, action));
return providedCodeActions.filter(action => isValidAction(trigger.filter, action));
}, (err): CodeAction[] => {
if (isPromiseCanceledError(err)) {
throw err;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/codeAction/test/codeAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ suite('CodeAction', () => {
testData.tsLint.abc
];

const actions = await getCodeActions(model, new Range(1, 1, 2, 1), undefined, CancellationToken.None);
const actions = await getCodeActions(model, new Range(1, 1, 2, 1), { type: 'manual' }, CancellationToken.None);
assert.equal(actions.length, 6);
assert.deepEqual(actions, expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ suite('ExtHostLanguageFeatures', function () {
}));

return rpcProtocol.sync().then(() => {
return getCodeActions(model, model.getFullModelRange(), undefined, CancellationToken.None).then(value => {
return getCodeActions(model, model.getFullModelRange(), { type: 'manual' }, CancellationToken.None).then(value => {
assert.equal(value.length, 2);

const [first, second] = value;
Expand All @@ -697,7 +697,7 @@ suite('ExtHostLanguageFeatures', function () {
}));

return rpcProtocol.sync().then(() => {
return getCodeActions(model, model.getFullModelRange(), undefined, CancellationToken.None).then(value => {
return getCodeActions(model, model.getFullModelRange(), { type: 'manual' }, CancellationToken.None).then(value => {
assert.equal(value.length, 1);

const [first] = value;
Expand All @@ -723,7 +723,7 @@ suite('ExtHostLanguageFeatures', function () {
}));

return rpcProtocol.sync().then(() => {
return getCodeActions(model, model.getFullModelRange(), undefined, CancellationToken.None).then(value => {
return getCodeActions(model, model.getFullModelRange(), { type: 'manual' }, CancellationToken.None).then(value => {
assert.equal(value.length, 1);
});
});
Expand All @@ -743,7 +743,7 @@ suite('ExtHostLanguageFeatures', function () {
}));

return rpcProtocol.sync().then(() => {
return getCodeActions(model, model.getFullModelRange(), undefined, CancellationToken.None).then(value => {
return getCodeActions(model, model.getFullModelRange(), { type: 'manual' }, CancellationToken.None).then(value => {
assert.equal(value.length, 1);
});
});
Expand Down

0 comments on commit 8c75f07

Please sign in to comment.