Skip to content

Commit

Permalink
use async and await to replace promise chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Jul 14, 2016
1 parent 44621c9 commit cdeac3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/cmd_line/commands/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ export class FileCommand extends node.CommandBase {
return active.viewColumn;
}

execute(): void {
async execute(): Promise<void> {
if (!this._arguments.name) {
// Open an empty file
if (this._arguments.position === FilePosition.CurrentWindow) {
vscode.commands.executeCommand("workbench.action.files.newUntitledFile");
await vscode.commands.executeCommand("workbench.action.files.newUntitledFile");
} else {
await vscode.commands.executeCommand("workbench.action.splitEditor");
await vscode.commands.executeCommand("workbench.action.files.newUntitledFile");
await vscode.commands.executeCommand("workbench.action.closeOtherEditors");
}

vscode.commands.executeCommand("workbench.action.splitEditor").then(() => {
vscode.commands.executeCommand("workbench.action.files.newUntitledFile").then(() => {
vscode.commands.executeCommand("workbench.action.closeOtherEditors");
});
});

return;
}

Expand All @@ -70,7 +68,8 @@ export class FileCommand extends node.CommandBase {

if (newFilePath !== currentFilePath) {
let folder = vscode.Uri.file(newFilePath);
vscode.commands.executeCommand("vscode.open", folder, this.getViewColumn(this._arguments.position === FilePosition.NewWindow));
await vscode.commands.executeCommand("vscode.open", folder,
this.getViewColumn(this._arguments.position === FilePosition.NewWindow));
}
}
}
2 changes: 1 addition & 1 deletion src/cmd_line/subparsers/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function parseEditFileCommandArgs(args: string): node.FileCommand {
return new node.FileCommand({});
}

var scanner = new Scanner(args);
let scanner = new Scanner(args);
let name = scanner.nextWord();

return new node.FileCommand({
Expand Down

0 comments on commit cdeac3c

Please sign in to comment.