Skip to content

Commit

Permalink
Convert to ES6, Promises, async and await.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfn committed Feb 11, 2016
1 parent 3eae649 commit ef706dc
Show file tree
Hide file tree
Showing 41 changed files with 413 additions and 351 deletions.
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
// "runtimeArgs": ["--harmony-default-parameters", "--harmony-rest-parameters"],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "out/src",
Expand All @@ -19,6 +20,7 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
// "runtimeArgs": ["--js-flags=\"--harmony --harmony-default-parameters\""],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "out/test",
Expand Down
8 changes: 5 additions & 3 deletions extension.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use strict"

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below

import * as vscode from 'vscode';
import {showCmdLine} from './src/cmd_line/main';
import * as cc from './src/cmd_line/lexer';
import ModeHandler from "./src/mode/modeHandler";
import {ModeHandler} from "./src/mode/modeHandler";
import {ModeName} from "./src/mode/mode";

var modeHandler : ModeHandler;
Expand All @@ -15,7 +17,7 @@ export function activate(context: vscode.ExtensionContext) {

extensionContext = context;

registerCommand(context, 'extension.showCmdLine', () => showCmdLine());
registerCommand(context, 'extension.showCmdLine', () => showCmdLine(""));

registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("esc"));
registerCommand(context, 'extension.vim_colon', () => handleKeyEvent(":"));
Expand Down Expand Up @@ -107,7 +109,7 @@ export function activate(context: vscode.ExtensionContext) {
}

function registerCommand(context: vscode.ExtensionContext, command: string, callback: (...args: any[]) => any) {
let disposable = vscode.commands.registerCommand(command, callback);
let disposable = vscode.commands.registerCommand(command, callback);
context.subscriptions.push(disposable);
}

Expand Down
18 changes: 10 additions & 8 deletions src/action/deleteAction.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"use strict";

import * as vscode from 'vscode';
import TextEditor from './../textEditor';
import {TextEditor} from './../textEditor';
import {Motion} from './../motion/motion';

export class DeleteAction {
public static Character(motion : Motion) : Thenable<Motion> {
public static async Character(motion : Motion): Promise<Motion> {
let start = motion.position;
let end = start.translate(0, 1);
let end = start.translate(0, 1);
let range = new vscode.Range(start, end);

return TextEditor.delete(range).then(() => {
if (motion.position.isLineEnd()) {
return motion.left().move();
}
});
await TextEditor.delete(range);

if (motion.position.isLineEnd()) {
return motion.left().move();
}
}
}
4 changes: 3 additions & 1 deletion src/cmd_line/commands/quit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

import vscode = require('vscode');

import node = require('../node');
Expand All @@ -15,7 +17,7 @@ export interface QuitCommandArguments extends node.CommandArgs {
export class QuitCommand extends node.CommandBase {
protected _arguments : QuitCommandArguments;

constructor(args : QuitCommandArguments = {}) {
constructor(args : QuitCommandArguments) {
super();
this._name = 'quit';
this._shortName = 'q';
Expand Down
4 changes: 3 additions & 1 deletion src/cmd_line/commands/write.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

// XXX: use graceful-fs ??
import fs = require('fs');

Expand All @@ -22,7 +24,7 @@ export interface WriteCommandArguments extends node.CommandArgs {
export class WriteCommand extends node.CommandBase {
protected _arguments : WriteCommandArguments;

constructor(args : WriteCommandArguments = {}) {
constructor(args : WriteCommandArguments) {
super();
this._name = 'write';
this._shortName = 'w';
Expand Down
2 changes: 2 additions & 0 deletions src/cmd_line/lexer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

import {Scanner} from "./scanner";
import {Token, TokenType} from "./token";

Expand Down
15 changes: 10 additions & 5 deletions src/cmd_line/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"use strict";

import * as vscode from "vscode";
import * as parser from "./parser";
import * as util from "../util";

// Shows the vim command line.
export function showCmdLine(initialText = "") : Thenable<{}> {
export async function showCmdLine(initialText: string): Promise<{}> {
if (!vscode.window.activeTextEditor) {
return util.showInfo("No active document.");
}
Expand All @@ -13,10 +15,13 @@ export function showCmdLine(initialText = "") : Thenable<{}> {
value: initialText
};

return vscode.window.showInputBox(options).then(
runCmdLine,
vscode.window.showErrorMessage
);
try {
runCmdLine(await vscode.window.showInputBox(options));
} catch (e) {
vscode.window.showErrorMessage(e.toString());

return;
}
}

function runCmdLine(s : string) : void {
Expand Down
2 changes: 2 additions & 0 deletions src/cmd_line/node.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

import * as vscode from "vscode";
import * as token from "./token";

Expand Down
2 changes: 2 additions & 0 deletions src/cmd_line/parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

import * as token from './token';
import * as node from './node';
import * as lexer from './lexer';
Expand Down
5 changes: 3 additions & 2 deletions src/cmd_line/scanner.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";

// Provides state and behavior to scan an input string character by character.
export class Scanner {
Expand Down Expand Up @@ -59,7 +60,7 @@ export class Scanner {
}

// skips text while any of chars matches and ignores the text span
skipRun(...chars : string[]) : void {
skipRun(chars : string[]) : void {
if (this.isAtEof) {
return;
}
Expand Down Expand Up @@ -98,7 +99,7 @@ export class Scanner {
this.pos += value.length;
}

expectOneOf(...values : string[]) : void {
expectOneOf(values : string[]) : void {
let match = values.filter(s => this.input.substr(this.pos).startsWith(s));
if (match.length !== 1) {
if (match.length > 1) {
Expand Down
2 changes: 2 additions & 0 deletions src/cmd_line/subparser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

import {parseQuitCommandArgs} from './subparsers/quit';
import {parseWriteCommandArgs} from './subparsers/write';

Expand Down
4 changes: 3 additions & 1 deletion src/cmd_line/subparsers/quit.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use strict";

import * as node from "../commands/quit";
import {Scanner} from '../scanner';
import {VimError, ErrorCode} from '../../error';

export function parseQuitCommandArgs(args : string) : node.QuitCommand {
if (!args) {
return new node.QuitCommand();
return new node.QuitCommand({});
}
var scannedArgs : node.QuitCommandArguments = {};
var scanner = new Scanner(args);
Expand Down
6 changes: 4 additions & 2 deletions src/cmd_line/subparsers/write.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"use strict";

import {WriteCommand, WriteCommandArguments} from '../commands/write';
import {Scanner} from '../scanner';

export function parseWriteCommandArgs(args : string) : WriteCommand {
if (!args) {
return new WriteCommand();
return new WriteCommand({});
}
var scannedArgs : WriteCommandArguments = {};
var scanner = new Scanner(args);
Expand Down Expand Up @@ -33,7 +35,7 @@ export function parseWriteCommandArgs(args : string) : WriteCommand {
// :write ++opt=value
scanner.expect('+');
scanner.ignore();
scanner.expectOneOf('bin', 'nobin', 'ff', 'enc');
scanner.expectOneOf(['bin', 'nobin', 'ff', 'enc']);
scannedArgs.opt = scanner.emit();
scanner.expect('=');
scanner.ignore();
Expand Down
2 changes: 2 additions & 0 deletions src/cmd_line/token.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

// Tokens for the Vim command line.

export enum TokenType {
Expand Down
4 changes: 3 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";

import {KeyboardLayout} from "./keyboard";

export default class Configuration {
export class Configuration {

keyboardLayout : KeyboardLayout;

Expand Down
2 changes: 2 additions & 0 deletions src/error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

import * as util from "./util";

interface VimErrors {
Expand Down
2 changes: 2 additions & 0 deletions src/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

import * as vscode from "vscode";

export class KeyboardLayout {
Expand Down
22 changes: 12 additions & 10 deletions src/mode/mode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

import {Motion} from './../motion/motion';

export enum ModeName {
Expand All @@ -12,40 +14,40 @@ export abstract class Mode {
private _motion : Motion;
protected keyHistory : string[];

constructor(name: ModeName, motion : Motion) {
constructor(name: ModeName, motion: Motion) {
this._name = name;
this._motion = motion;
this._isActive = false;
this.keyHistory = [];
}

get Name(): ModeName {
get name(): ModeName {
return this._name;
}

get Motion() : Motion {
get motion() : Motion {
return this._motion;
}

set Motion(val : Motion) {
set motion(val : Motion) {
this._motion = val;
}

get IsActive() : boolean {
get isActive() : boolean {
return this._isActive;
}

set IsActive(val : boolean) {
set isActive(val : boolean) {
this._isActive = val;
}

public HandleDeactivation() : void {
public handleDeactivation() : void {
this.keyHistory = [];
}

abstract ShouldBeActivated(key : string, currentMode : ModeName) : boolean;
abstract shouldBeActivated(key : string, currentMode : ModeName) : boolean;

abstract HandleActivation(key : string) : Thenable<{}>;
abstract handleActivation(key : string) : Promise<{}>;

abstract HandleKeyEvent(key : string) : Thenable<{}>;
abstract handleKeyEvent(key : string) : Promise<{}>;
}
Loading

0 comments on commit ef706dc

Please sign in to comment.