Fix possible undefined access exception when using apply "first" for a code action and no code actions are returned

Fixes #63101
This commit is contained in:
Matt Bierner 2018-11-14 15:26:25 -08:00
parent 3c6b6e614d
commit 80aeb774f6
2 changed files with 65 additions and 1 deletions

View file

@ -0,0 +1,64 @@
{
"defaultSeverity": "warning",
"extends": [
"tslint:recommended"
],
"rules": {
"member-ordering": false,
"whitespace": false,
"indent": [
true,
"tabs"
],
"interface-name": [
true,
"never-prefix"
],
"variable-name": [
true,
"check-format",
"allow-leading-underscore"
],
"curly": [
true,
"ignore-same-line"
],
"member-access": [
true
],
"max-classes-per-file": false,
"no-empty": false,
"object-literal-sort-keys": false,
"no-unused-expression": true,
"arrow-parens": [
true,
"ban-single-arg-parens"
],
"quotemark": [
true,
"single"
],
"eofline": false,
"semicolon": [
true,
"always"
],
"class-name": true,
"prefer-const": true,
"import-spacing": true,
"ordered-imports": false,
"trailing-comma": [
true,
{
"multiline": {
"objects": "always",
"arrays": "always",
"functions": "ignore",
"typeLiterals": "ignore"
}
}
],
"max-line-length": false,
"no-bitwise": false
}
}

View file

@ -93,7 +93,7 @@ export class QuickFixController implements IEditorContribution {
// Triggered for specific scope
// Apply if we only have one action or requested autoApply, otherwise show menu
e.actions.then(fixes => {
if (e.trigger.autoApply === CodeActionAutoApply.First || (e.trigger.autoApply === CodeActionAutoApply.IfSingle && fixes.length === 1)) {
if (fixes.length > 0 && e.trigger.autoApply === CodeActionAutoApply.First || (e.trigger.autoApply === CodeActionAutoApply.IfSingle && fixes.length === 1)) {
this._onApplyCodeAction(fixes[0]);
} else {
this._codeActionContextMenu.show(e.actions, e.position);