Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fix tslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinmprabhu committed Feb 16, 2019
1 parent bd25252 commit 72d5422
Showing 1 changed file with 88 additions and 88 deletions.
176 changes: 88 additions & 88 deletions src/goDoctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,47 @@ import { resolve } from 'dns';
* Extracts function out of current selection and replaces the current selection with a call to the extracted function.
*/
export function extractFunction() {
let activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
vscode.window.showInformationMessage('No editor is active.');
return;
}
if (activeEditor.selections.length !== 1) {
vscode.window.showInformationMessage('You need to have a single selection for extracting method');
return;
}
let showInputBoxPromise = vscode.window.showInputBox({ placeHolder: 'Plese enter a name for the extracted function.' });
showInputBoxPromise.then((functionName: string) => {
runGoDoctorExtract(functionName, activeEditor.selection, activeEditor).then(errorMessage => {
if (errorMessage) {
vscode.window.showErrorMessage(errorMessage);
}
});
});
let activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
vscode.window.showInformationMessage('No editor is active.');
return;
}
if (activeEditor.selections.length !== 1) {
vscode.window.showInformationMessage('You need to have a single selection for extracting method');
return;
}
let showInputBoxPromise = vscode.window.showInputBox({ placeHolder: 'Plese enter a name for the extracted function.' });
showInputBoxPromise.then((functionName: string) => {
runGoDoctorExtract(functionName, activeEditor.selection, activeEditor).then(errorMessage => {
if (errorMessage) {
vscode.window.showErrorMessage(errorMessage);
}
});
});
}

/**
* Extracts expression out of current selection into a var in the local scope and
* replaces the current selection with the new var.
*/
export function extractVariable() {
let activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
vscode.window.showInformationMessage('No editor is active.');
return;
}
if (activeEditor.selections.length !== 1) {
vscode.window.showInformationMessage('You need to have a single selection for extracting variable');
return;
}
let showInputBoxPromise = vscode.window.showInputBox({ placeHolder: 'Plese enter a name for the extracted variable.' });
showInputBoxPromise.then((varName: string) => {
runGoDoctorVar(varName, activeEditor.selection, activeEditor).then(errorMessage => {
if (errorMessage) {
vscode.window.showErrorMessage(errorMessage);
}
});
});
let activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
vscode.window.showInformationMessage('No editor is active.');
return;
}
if (activeEditor.selections.length !== 1) {
vscode.window.showInformationMessage('You need to have a single selection for extracting variable');
return;
}
let showInputBoxPromise = vscode.window.showInputBox({ placeHolder: 'Plese enter a name for the extracted variable.' });
showInputBoxPromise.then((varName: string) => {
runGoDoctorVar(varName, activeEditor.selection, activeEditor).then(errorMessage => {
if (errorMessage) {
vscode.window.showErrorMessage(errorMessage);
}
});
});
}

/**
Expand All @@ -66,35 +66,35 @@ export function extractVariable() {
* @returns errorMessage in case the method fails, null otherwise
*/
export function runGoDoctorExtract(functionName: string, selection: vscode.Selection, activeEditor: vscode.TextEditor): Thenable<string> {
let godoctor = getBinPath('godoctor');
let godoctor = getBinPath('godoctor');

return new Promise((resolve, reject) => {
if (typeof functionName === 'undefined') {
return resolve('Function Name is undefined');
}
let args = [
'-w',
'-pos',
`${selection.start.line + 1},${selection.start.character + 1}:${selection.end.line + 1},${selection.end.character + 1}`,
'-file',
activeEditor.document.fileName,
'extract',
functionName,
];
let p = cp.execFile(godoctor, args, { env: getToolsEnvVars(), cwd: dirname(activeEditor.document.fileName) }, (err, stdout, stderr) => {
if (err && (<any>err).code === 'ENOENT') {
promptForMissingTool('godoctor');
return resolve('Could not find godoctor');
}
if (err) {
return resolve(`Could not extract function : \n\n${stderr}`);
}
});
if (p.pid) {
p.stdin.end();
}
return new Promise((resolve, reject) => {
if (typeof functionName === 'undefined') {
return resolve('Function Name is undefined');
}
let args = [
'-w',
'-pos',
`${selection.start.line + 1},${selection.start.character + 1}:${selection.end.line + 1},${selection.end.character + 1}`,
'-file',
activeEditor.document.fileName,
'extract',
functionName,
];
let p = cp.execFile(godoctor, args, { env: getToolsEnvVars(), cwd: dirname(activeEditor.document.fileName) }, (err, stdout, stderr) => {
if (err && (<any>err).code === 'ENOENT') {
promptForMissingTool('godoctor');
return resolve('Could not find godoctor');
}
if (err) {
return resolve(`Could not extract function : \n\n${stderr}`);
}
});
if (p.pid) {
p.stdin.end();
}

});
});
}

/**
Expand All @@ -104,33 +104,33 @@ export function runGoDoctorExtract(functionName: string, selection: vscode.Selec
* @returns errorMessage in case the method fails, null otherwise
*/
export function runGoDoctorVar(varName: string, selection: vscode.Selection, activeEditor: vscode.TextEditor): Thenable<string> {
let godoctor = getBinPath('godoctor');
let godoctor = getBinPath('godoctor');

return new Promise((resolve, reject) => {
if (typeof varName === 'undefined') {
return resolve('Function Name is undefined');
}
let args = [
'-w',
'-pos',
`${selection.start.line + 1},${selection.start.character + 1}:${selection.end.line + 1},${selection.end.character + 1}`,
'-file',
activeEditor.document.fileName,
'var',
varName,
];
let p = cp.execFile(godoctor, args, { env: getToolsEnvVars(), cwd: dirname(activeEditor.document.fileName) }, (err, stdout, stderr) => {
if (err && (<any>err).code === 'ENOENT') {
promptForMissingTool('godoctor');
return resolve('Could not find godoctor');
}
if (err) {
return resolve(`Could not extract variable : \n\n${stderr}`);
}
});
if (p.pid) {
p.stdin.end();
}
return new Promise((resolve, reject) => {
if (typeof varName === 'undefined') {
return resolve('Function Name is undefined');
}
let args = [
'-w',
'-pos',
`${selection.start.line + 1},${selection.start.character + 1}:${selection.end.line + 1},${selection.end.character + 1}`,
'-file',
activeEditor.document.fileName,
'var',
varName,
];
let p = cp.execFile(godoctor, args, { env: getToolsEnvVars(), cwd: dirname(activeEditor.document.fileName) }, (err, stdout, stderr) => {
if (err && (<any>err).code === 'ENOENT') {
promptForMissingTool('godoctor');
return resolve('Could not find godoctor');
}
if (err) {
return resolve(`Could not extract variable : \n\n${stderr}`);
}
});
if (p.pid) {
p.stdin.end();
}

});
});
}

0 comments on commit 72d5422

Please sign in to comment.