Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gulp: add trim-whitespace task #78

Merged
merged 1 commit into from
Dec 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var gulp = require('gulp');
var tslint = require('gulp-tslint');
var tsd = require('gulp-tsd');
var shell = require('gulp-shell');
var mocha = require('gulp-mocha');
var gulp = require('gulp'),
tslint = require('gulp-tslint'),
tsd = require('gulp-tsd'),
shell = require('gulp-shell'),
mocha = require('gulp-mocha'),
trimlines = require('gulp-trimlines');

var paths = {
scripts_ts: "src/**/*.ts",
Expand All @@ -21,11 +22,19 @@ gulp.task('tsd', function (callback) {
}, callback));
});

gulp.task('compile', shell.task([
gulp.task('trim-whitespace', function() {
return gulp.src([paths.scripts_ts, paths.tests_ts], { base: "./" })
.pipe(trimlines({
leading: false
}))
.pipe(gulp.dest('./'));
});

gulp.task('compile', ['trim-whitespace'], shell.task([
'node ./node_modules/vscode/bin/compile -p ./',
]));

gulp.task('tslint', function() {
gulp.task('tslint', ['trim-whitespace'], function() {
return gulp.src([paths.scripts_ts, paths.tests_ts])
.pipe(tslint())
.pipe(tslint.report('prose', {
Expand All @@ -44,4 +53,4 @@ gulp.task('test', ['compile'], function () {
});

gulp.task('init', ['tsd']);
gulp.task('default', ['tslint', 'test']);
gulp.task('default', ['trim-whitespace', 'tslint', 'test']);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"gulp-shell": "^0.5.1",
"gulp-tsd": "0.0.4",
"gulp-tslint": "^3.6.0",
"gulp-trimlines": "^1.0.0",
"gulp-typescript": "^2.9.2",
"tsd": "^0.6.5",
"typescript": "^1.6.2",
Expand Down
8 changes: 4 additions & 4 deletions src/cmd_line/commands/quit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ export class QuitCommand extends node.CommandBase {
this._shortName = 'q';
this._arguments = args;
}

get arguments() : QuitCommandArguments {
return this._arguments;
}

execute() : void {
this.quit();
}
}

private quit() {
// See https://github.com/Microsoft/vscode/issues/723
if ((this.activeTextEditor.document.isDirty || this.activeTextEditor.document.isUntitled)
&& !this.arguments.bang) {
throw error.VimError.fromCode(error.ErrorCode.E37);
}

vscode.commands.executeCommand('workbench.action.closeActiveEditor');
};
}
10 changes: 5 additions & 5 deletions src/cmd_line/commands/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WriteCommand extends node.CommandBase {
this._shortName = 'w';
this._arguments = args;
}

get arguments() : WriteCommandArguments {
return this._arguments;
}
Expand All @@ -47,10 +47,10 @@ export class WriteCommand extends node.CommandBase {
util.showError("Not implemented.");
return;
}

if (this.activeTextEditor.document.isUntitled) {
throw error.VimError.fromCode(error.ErrorCode.E32);
}
}

fs.access(this.activeTextEditor.document.fileName, fs.W_OK, (accessErr) => {
if (accessErr) {
Expand All @@ -71,7 +71,7 @@ export class WriteCommand extends node.CommandBase {
});
}

private save() {
private save() {
this.activeTextEditor.document.save().then(
(ok) => {
if (ok) {
Expand All @@ -82,5 +82,5 @@ export class WriteCommand extends node.CommandBase {
},
(e) => util.showError(e)
);
}
}
}
10 changes: 5 additions & 5 deletions src/cmd_line/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function showCmdLine(initialText = "") {
util.showInfo("No active document.");
return;
}

const options : vscode.InputBoxOptions = {
prompt: "Vim command line",
value: initialText
Expand All @@ -23,14 +23,14 @@ function runCmdLine(s : string) : void {
if (!(s && s.trim())) {
return;
}

try {
var cmd = parser.parse(s);
} catch (e) {
util.showError(e);
return;
}

if (cmd.isEmpty) {
return;
}
Expand All @@ -44,7 +44,7 @@ function runCmdLine(s : string) : void {
} catch (ee) {
// ignore
}
util.showError(e);

util.showError(e);
}
}
10 changes: 5 additions & 5 deletions src/cmd_line/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ export interface CommandArgs {
}

export abstract class CommandBase {

protected get activeTextEditor() {
return vscode.window.activeTextEditor;
}

get name() : string {
return this._name;
}
protected _name : string;

get shortName() : string {
return this._shortName;
}
Expand All @@ -119,7 +119,7 @@ export abstract class CommandBase {
get arguments() : CommandArgs {
return this._arguments;
}
protected _arguments : CommandArgs;
protected _arguments : CommandArgs;

abstract execute() : void;
}
4 changes: 2 additions & 2 deletions src/cmd_line/subparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {parseWriteCommandArgs} from './subparsers/write';

// TODO: add type for this dict.
// maps command names to parsers for said commands.
export const commandParsers = {
export const commandParsers = {
'w': parseWriteCommandArgs,
'write': parseWriteCommandArgs,

'quit': parseQuitCommandArgs,
'q': parseQuitCommandArgs
};
32 changes: 16 additions & 16 deletions src/cursor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from "lodash";
import * as _ from "lodash";
import * as vscode from "vscode";
import TextEditor from "./textEditor";

Expand All @@ -10,7 +10,7 @@ export default class Cursor {
return;
}
let curPosition = this.currentPosition();

if (newPosition.line === curPosition.line) {
this.prevColumn = newPosition.character;
}
Expand All @@ -31,7 +31,7 @@ export default class Cursor {
column--;
}

return new vscode.Position(pos.line, column);
return new vscode.Position(pos.line, column);
}

static right() : vscode.Position {
Expand All @@ -52,7 +52,7 @@ export default class Cursor {

if (!Cursor.isLastLine(pos)) {
let nextLineMaxColumn = TextEditor.readLine(++line).length - 1;

if (nextLineMaxColumn < 0) {
nextLineMaxColumn = 0;
}
Expand All @@ -70,7 +70,7 @@ export default class Cursor {
let line = pos.line;
let column = this.prevColumn;

if (!this.isFirstLine(pos)) {
if (!this.isFirstLine(pos)) {
let nextLineMaxColumn = TextEditor.readLine(--line).length - 1;

if (nextLineMaxColumn < 0) {
Expand Down Expand Up @@ -120,45 +120,45 @@ export default class Cursor {
static lineEnd() : vscode.Position {
let pos = this.currentPosition();
const lineLength = TextEditor.readLine(pos.line).length;

return new vscode.Position(pos.line, lineLength);
}

static documentBegin() : vscode.Position {
return new vscode.Position(0, 0);
}

static documentEnd() : vscode.Position {
let line = vscode.window.activeTextEditor.document.lineCount - 1;
if (line < 0) {
line = 0;
}
let column = TextEditor.readLine(line).length;

let column = TextEditor.readLine(line).length;
return new vscode.Position(line, column);
}

private static isLineBeginning(position : vscode.Position) : boolean {
return position.character === 0;
}
}

private static isLineEnd(position : vscode.Position) : boolean {
let lineEnd = TextEditor.readLine(position.line).length - 1;
if (lineEnd < 0) {
lineEnd = 0;
}

if (position.character > lineEnd) {
throw new RangeError;
}

return position.character === lineEnd;
}

private static isFirstLine(position : vscode.Position) : boolean {
return position.line === 0;
}

private static isLastLine(position : vscode.Position): boolean {
return position.line === (vscode.window.activeTextEditor.document.lineCount - 1);
}
Expand Down
16 changes: 8 additions & 8 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,36 @@ const errors : VimErrors = {


export class VimError extends Error {

private _code : number;
private _message : string;

constructor(code : number, message : string) {
super();
this._code = code;
this._message = message;
}

static fromCode(code : ErrorCode) : VimError {
if (errors[code]) {
return new VimError(code, errors[code]);
}

throw new Error("unknown error code: " + code);
}

get code() : number {
return this._code;
}

get message() : string {
return this._message;
}

display() : void {
util.showError(this.toString());
}

toString() : string {
return "E" + this.code.toString() + ": " + this.message;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mode/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export abstract class Mode {
set IsActive(val : boolean) {
this.isActive = val;
}

public HandleDeactivation() : void {
this.keyHistory = [];
}
Expand Down
10 changes: 5 additions & 5 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ export default class ModeHandler {

handleKeyEvent(key : string) : void {
var currentModeName = this.currentMode.Name;

var nextMode : Mode;
var inactiveModes = _.filter(this.modes, (m) => !m.IsActive);

_.forEach(inactiveModes, (m, i) => {
if (m.ShouldBeActivated(key, currentModeName)) {
nextMode = m;
}
}
});

if (nextMode) {
this.currentMode.HandleDeactivation();

nextMode.HandleActivation(key);
this.setCurrentModeByName(nextMode.Name);
return;
Expand Down
Loading