File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1- import { ExtensionContext , Disposable } from "vscode" ;
1+ import { ExtensionContext , Disposable , window } from "vscode" ;
22import { Svn } from "./svn" ;
33import { SvnContentProvider } from "./svnContentProvider" ;
44import { SvnCommands } from "./commands" ;
55import { Model } from "./model" ;
6+ import { toDisposable } from "./util" ;
67
78function 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}
2132exports . activate = activate ;
2233
Original file line number Diff line number Diff line change @@ -2,18 +2,32 @@ import { window } from "vscode";
22import * as cp from "child_process" ;
33import * as iconv from "iconv-lite" ;
44import * as jschardet from "jschardet" ;
5+ import { EventEmitter } from 'events' ;
56
67interface CpOptions {
78 cwd ?: string ;
89 encoding ?: string ;
10+ log ?: boolean ;
911}
1012
1113export 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
You can’t perform that action at this time.
0 commit comments