Skip to content

Commit bfcddca

Browse files
authored
Merge pull request #41 from edgardmessias/add_output_channel
Added specific output channel (Close #37)
2 parents 5656ea4 + 6650e60 commit bfcddca

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/extension.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1-
import { ExtensionContext, Disposable } from "vscode";
1+
import { ExtensionContext, Disposable, window } from "vscode";
22
import { Svn } from "./svn";
33
import { SvnContentProvider } from "./svnContentProvider";
44
import { SvnCommands } from "./commands";
55
import { Model } from "./model";
6+
import { toDisposable } from "./util";
67

78
function activate(context: ExtensionContext) {
89
const disposables: Disposable[] = [];
10+
11+
12+
const outputChannel = window.createOutputChannel('SVN');
13+
disposables.push(outputChannel);
14+
915
const svn = new Svn();
1016
const model = new Model(svn);
1117
const contentProvider = new SvnContentProvider(model);
1218
const commands = new SvnCommands(model);
1319
disposables.push(model);
1420

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

1723
context.subscriptions.push(
1824
new Disposable(() => Disposable.from(...disposables).dispose())
1925
);
26+
27+
const onOutput = (str: string) => outputChannel.append(str);
28+
svn.onOutput.addListener('log', onOutput);
29+
disposables.push(toDisposable(() => svn.onOutput.removeListener('log', onOutput)));
30+
2031
}
2132
exports.activate = activate;
2233

src/svn.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,32 @@ import { window } from "vscode";
22
import * as cp from "child_process";
33
import * as iconv from "iconv-lite";
44
import * as jschardet from "jschardet";
5+
import { EventEmitter } from 'events';
56

67
interface CpOptions {
78
cwd?: string;
89
encoding?: string;
10+
log?: boolean;
911
}
1012

1113
export class Svn {
14+
private _onOutput = new EventEmitter();
15+
get onOutput(): EventEmitter { return this._onOutput; }
16+
17+
private log(output: string): void {
18+
this._onOutput.emit('log', output);
19+
}
20+
1221
async exec(cwd: string, args: any[], options: CpOptions = {}) {
1322
if (cwd) {
1423
options.cwd = cwd;
1524
}
1625

26+
27+
if (options.log !== false) {
28+
this.log(`svn ${args.join(' ')}\n`);
29+
}
30+
1731
let process = cp.spawn("svn", args, options);
1832

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

4357
stdout = iconv.decode(stdout, encoding);
4458

59+
if (options.log !== false && stderr.length > 0) {
60+
this.log(`${stderr}\n`);
61+
}
62+
4563
return { exitCode, stdout, stderr };
4664
}
4765

0 commit comments

Comments
 (0)