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" ;
2
2
import { Svn } from "./svn" ;
3
3
import { SvnContentProvider } from "./svnContentProvider" ;
4
4
import { SvnCommands } from "./commands" ;
5
5
import { Model } from "./model" ;
6
+ import { toDisposable } from "./util" ;
6
7
7
8
function activate ( context : ExtensionContext ) {
8
9
const disposables : Disposable [ ] = [ ] ;
10
+
11
+
12
+ const outputChannel = window . createOutputChannel ( 'SVN' ) ;
13
+ disposables . push ( outputChannel ) ;
14
+
9
15
const svn = new Svn ( ) ;
10
16
const model = new Model ( svn ) ;
11
17
const contentProvider = new SvnContentProvider ( model ) ;
12
18
const commands = new SvnCommands ( model ) ;
13
19
disposables . push ( model ) ;
14
20
15
- console . log ( "svn-scm is now active!" ) ;
21
+ outputChannel . appendLine ( "svn-scm is now active!" ) ;
16
22
17
23
context . subscriptions . push (
18
24
new Disposable ( ( ) => Disposable . from ( ...disposables ) . dispose ( ) )
19
25
) ;
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
+
20
31
}
21
32
exports . activate = activate ;
22
33
Original file line number Diff line number Diff line change @@ -2,18 +2,32 @@ import { window } from "vscode";
2
2
import * as cp from "child_process" ;
3
3
import * as iconv from "iconv-lite" ;
4
4
import * as jschardet from "jschardet" ;
5
+ import { EventEmitter } from 'events' ;
5
6
6
7
interface CpOptions {
7
8
cwd ?: string ;
8
9
encoding ?: string ;
10
+ log ?: boolean ;
9
11
}
10
12
11
13
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
+
12
21
async exec ( cwd : string , args : any [ ] , options : CpOptions = { } ) {
13
22
if ( cwd ) {
14
23
options . cwd = cwd ;
15
24
}
16
25
26
+
27
+ if ( options . log !== false ) {
28
+ this . log ( `svn ${ args . join ( ' ' ) } \n` ) ;
29
+ }
30
+
17
31
let process = cp . spawn ( "svn" , args , options ) ;
18
32
19
33
let [ exitCode , stdout , stderr ] = await Promise . all < any > ( [
@@ -42,6 +56,10 @@ export class Svn {
42
56
43
57
stdout = iconv . decode ( stdout , encoding ) ;
44
58
59
+ if ( options . log !== false && stderr . length > 0 ) {
60
+ this . log ( `${ stderr } \n` ) ;
61
+ }
62
+
45
63
return { exitCode, stdout, stderr } ;
46
64
}
47
65
You can’t perform that action at this time.
0 commit comments