Reduce nesting

This commit is contained in:
Matt Bierner 2019-07-09 16:48:24 -07:00
parent bc09f14100
commit 55021e2119

View file

@ -44,51 +44,52 @@ export class CodeActionUi extends Disposable {
}
public async update(newState: CodeActionsState.State): Promise<void> {
if (newState.type === CodeActionsState.Type.Triggered) {
let actions: CodeActionSet;
try {
actions = await newState.actions;
} catch (e) {
onUnexpectedError(e);
return;
}
if (newState.type !== CodeActionsState.Type.Triggered) {
this._lightBulbWidget.hide();
return;
}
this._lightBulbWidget.update(actions, newState.position);
let actions: CodeActionSet;
try {
actions = await newState.actions;
} catch (e) {
onUnexpectedError(e);
return;
}
if (!actions.actions.length && newState.trigger.context) {
MessageController.get(this._editor).showMessage(newState.trigger.context.notAvailableMessage, newState.trigger.context.position);
this._activeCodeActions.value = actions;
return;
}
this._lightBulbWidget.update(actions, newState.position);
if (newState.trigger.type === 'manual') {
if (newState.trigger.filter && newState.trigger.filter.kind) {
// Triggered for specific scope
if (actions.actions.length > 0) {
// Apply if we only have one action or requested autoApply
if (newState.trigger.autoApply === CodeActionAutoApply.First || (newState.trigger.autoApply === CodeActionAutoApply.IfSingle && actions.actions.length === 1)) {
try {
await this.delegate.applyCodeAction(actions.actions[0], false);
} finally {
actions.dispose();
}
return;
if (!actions.actions.length && newState.trigger.context) {
MessageController.get(this._editor).showMessage(newState.trigger.context.notAvailableMessage, newState.trigger.context.position);
this._activeCodeActions.value = actions;
return;
}
if (newState.trigger.type === 'manual') {
if (newState.trigger.filter && newState.trigger.filter.kind) {
// Triggered for specific scope
if (actions.actions.length > 0) {
// Apply if we only have one action or requested autoApply
if (newState.trigger.autoApply === CodeActionAutoApply.First || (newState.trigger.autoApply === CodeActionAutoApply.IfSingle && actions.actions.length === 1)) {
try {
await this.delegate.applyCodeAction(actions.actions[0], false);
} finally {
actions.dispose();
}
return;
}
}
this._activeCodeActions.value = actions;
this._codeActionWidget.show(actions, newState.position);
} else {
// auto magically triggered
if (this._codeActionWidget.isVisible) {
// TODO: Figure out if we should update the showing menu?
actions.dispose();
} else {
this._activeCodeActions.value = actions;
}
}
this._activeCodeActions.value = actions;
this._codeActionWidget.show(actions, newState.position);
} else {
this._lightBulbWidget.hide();
// auto magically triggered
if (this._codeActionWidget.isVisible) {
// TODO: Figure out if we should update the showing menu?
actions.dispose();
} else {
this._activeCodeActions.value = actions;
}
}
}