Skip to content

Added specific output channel (Close #37) #41

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

Merged
merged 1 commit into from
Nov 27, 2017
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
15 changes: 13 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import { ExtensionContext, Disposable } from "vscode";
import { ExtensionContext, Disposable, window } from "vscode";
import { Svn } from "./svn";
import { SvnContentProvider } from "./svnContentProvider";
import { SvnCommands } from "./commands";
import { Model } from "./model";
import { toDisposable } from "./util";

function activate(context: ExtensionContext) {
const disposables: Disposable[] = [];


const outputChannel = window.createOutputChannel('SVN');
disposables.push(outputChannel);

const svn = new Svn();
const model = new Model(svn);
const contentProvider = new SvnContentProvider(model);
const commands = new SvnCommands(model);
disposables.push(model);

console.log("svn-scm is now active!");
outputChannel.appendLine("svn-scm is now active!");

context.subscriptions.push(
new Disposable(() => Disposable.from(...disposables).dispose())
);

const onOutput = (str: string) => outputChannel.append(str);
svn.onOutput.addListener('log', onOutput);
disposables.push(toDisposable(() => svn.onOutput.removeListener('log', onOutput)));

}
exports.activate = activate;

Expand Down
18 changes: 18 additions & 0 deletions src/svn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@ import { window } from "vscode";
import * as cp from "child_process";
import * as iconv from "iconv-lite";
import * as jschardet from "jschardet";
import { EventEmitter } from 'events';

interface CpOptions {
cwd?: string;
encoding?: string;
log?: boolean;
}

export class Svn {
private _onOutput = new EventEmitter();
get onOutput(): EventEmitter { return this._onOutput; }

private log(output: string): void {
this._onOutput.emit('log', output);
}

async exec(cwd: string, args: any[], options: CpOptions = {}) {
if (cwd) {
options.cwd = cwd;
}


if (options.log !== false) {
this.log(`svn ${args.join(' ')}\n`);
}

let process = cp.spawn("svn", args, options);

let [exitCode, stdout, stderr] = await Promise.all<any>([
Expand Down Expand Up @@ -42,6 +56,10 @@ export class Svn {

stdout = iconv.decode(stdout, encoding);

if (options.log !== false && stderr.length > 0) {
this.log(`${stderr}\n`);
}

return { exitCode, stdout, stderr };
}

Expand Down