Show error if TS returns an empty refactoring

Fixes #70526

An empty refactoring response indicates that something went wrong
This commit is contained in:
Matt Bierner 2019-03-14 17:23:12 -07:00
parent 2e108cec4a
commit e5463022e1

View file

@ -4,15 +4,18 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import * as Proto from '../protocol';
import { ITypeScriptServiceClient } from '../typescriptService';
import API from '../utils/api';
import { nulToken } from '../utils/cancellation';
import { Command, CommandManager } from '../utils/commandManager';
import { VersionDependentRegistration } from '../utils/dependentRegistration';
import TelemetryReporter from '../utils/telemetry';
import * as typeConverters from '../utils/typeConverters';
import FormattingOptionsManager from './fileConfigurationManager';
import { nulToken } from '../utils/cancellation';
const localize = nls.loadMessageBundle();
class ApplyRefactoringCommand implements Command {
@ -49,7 +52,12 @@ class ApplyRefactoringCommand implements Command {
action,
};
const response = await this.client.execute('getEditsForRefactor', args, nulToken);
if (response.type !== 'response' || !response.body || !response.body.edits.length) {
if (response.type !== 'response' || !response.body) {
return false;
}
if (!response.body.edits.length) {
vscode.window.showErrorMessage(localize('refactoringFailed', "Could not apply refactoring"));
return false;
}