@@ -28,6 +28,34 @@ interface Request {
2828 _enqueued : number ;
2929}
3030
31+ module Events {
32+ export const StateChanged = 'stateChanged' ;
33+
34+ export const StdOut = 'stdout' ;
35+ export const StdErr = 'stderr' ;
36+
37+ export const Error = 'Error' ;
38+ export const ServerError = 'ServerError' ;
39+
40+ export const UnresolvedDependencies = 'UnresolvedDependencies' ;
41+ export const PackageRestoreStarted = 'PackageRestoreStarted' ;
42+ export const PackageRestoreFinished = 'PackageRestoreFinished' ;
43+
44+ export const ProjectChanged = 'ProjectChanged' ;
45+ export const ProjectAdded = 'ProjectAdded' ;
46+ export const ProjectRemoved = 'ProjectRemoved' ;
47+
48+ export const MsBuildProjectDiagnostics = 'MsBuildProjectDiagnostics' ;
49+
50+ export const BeforeServerStart = 'BeforeServerStart' ;
51+ export const ServerStart = 'ServerStart' ;
52+ export const ServerStop = 'ServerStop' ;
53+
54+ export const MultipleLaunchTargets = 'server:MultipleLaunchTargets' ;
55+
56+ export const Started = 'started' ;
57+ }
58+
3159export abstract class OmnisharpServer {
3260
3361 private _eventBus = new EventEmitter ( ) ;
@@ -57,7 +85,7 @@ export abstract class OmnisharpServer {
5785 private _setState ( value : ServerState ) : void {
5886 if ( typeof value !== 'undefined' && value !== this . _state ) {
5987 this . _state = value ;
60- this . _fireEvent ( 'stateChanged' , this . _state ) ;
88+ this . _fireEvent ( Events . StateChanged , this . _state ) ;
6189 }
6290 }
6391
@@ -72,67 +100,67 @@ export abstract class OmnisharpServer {
72100 // --- eventing
73101
74102 public onStdout ( listener : ( e : string ) => any , thisArg ?: any ) {
75- return this . _addListener ( 'stdout' , listener , thisArg ) ;
103+ return this . _addListener ( Events . StdOut , listener , thisArg ) ;
76104 }
77105
78106 public onStderr ( listener : ( e : string ) => any , thisArg ?: any ) {
79- return this . _addListener ( 'stderr' , listener , thisArg ) ;
107+ return this . _addListener ( Events . StdErr , listener , thisArg ) ;
80108 }
81109
82110 public onError ( listener : ( e : ErrorMessage ) => any , thisArg ?: any ) {
83- return this . _addListener ( ' Error' , listener , thisArg ) ;
111+ return this . _addListener ( Events . Error , listener , thisArg ) ;
84112 }
85113
86114 public onServerError ( listener : ( err : any ) => any , thisArg ?: any ) {
87- return this . _addListener ( ' ServerError' , listener , thisArg ) ;
115+ return this . _addListener ( Events . ServerError , listener , thisArg ) ;
88116 }
89117
90118 public onUnresolvedDependencies ( listener : ( e : UnresolvedDependenciesMessage ) => any , thisArg ?:any ) {
91- return this . _addListener ( ' UnresolvedDependencies' , listener , thisArg ) ;
119+ return this . _addListener ( Events . UnresolvedDependencies , listener , thisArg ) ;
92120 }
93121
94122 public onBeforePackageRestore ( listener : ( ) => any , thisArg ?: any ) {
95- return this . _addListener ( ' PackageRestoreStarted' , listener , thisArg ) ;
123+ return this . _addListener ( Events . PackageRestoreStarted , listener , thisArg ) ;
96124 }
97125
98126 public onPackageRestore ( listener : ( ) => any , thisArg ?: any ) {
99- return this . _addListener ( ' PackageRestoreFinished' , listener , thisArg ) ;
127+ return this . _addListener ( Events . PackageRestoreFinished , listener , thisArg ) ;
100128 }
101129
102130 public onProjectChange ( listener : ( e : ProjectInformationResponse ) => any , thisArg ?: any ) {
103- return this . _addListener ( ' ProjectChanged' , listener , thisArg ) ;
131+ return this . _addListener ( Events . ProjectChanged , listener , thisArg ) ;
104132 }
105133
106134 public onProjectAdded ( listener : ( e : ProjectInformationResponse ) => any , thisArg ?: any ) {
107- return this . _addListener ( ' ProjectAdded' , listener , thisArg ) ;
135+ return this . _addListener ( Events . ProjectAdded , listener , thisArg ) ;
108136 }
109137
110138 public onProjectRemoved ( listener : ( e : ProjectInformationResponse ) => any , thisArg ?: any ) {
111- return this . _addListener ( ' ProjectRemoved' , listener , thisArg ) ;
139+ return this . _addListener ( Events . ProjectRemoved , listener , thisArg ) ;
112140 }
113141
114142 public onMsBuildProjectDiagnostics ( listener : ( e : MSBuildProjectDiagnostics ) => any , thisArg ?: any ) {
115- return this . _addListener ( ' MsBuildProjectDiagnostics' , listener , thisArg ) ;
143+ return this . _addListener ( Events . MsBuildProjectDiagnostics , listener , thisArg ) ;
116144 }
117145
118146 public onBeforeServerStart ( listener : ( e :string ) => any ) {
119- return this . _addListener ( ' BeforeServerStart' , listener ) ;
147+ return this . _addListener ( Events . BeforeServerStart , listener ) ;
120148 }
121149
122150 public onServerStart ( listener : ( e : string ) => any ) {
123- return this . _addListener ( ' ServerStart' , listener ) ;
151+ return this . _addListener ( Events . ServerStart , listener ) ;
124152 }
125153
126154 public onServerStop ( listener : ( ) => any ) {
127- return this . _addListener ( ' ServerStop' , listener ) ;
155+ return this . _addListener ( Events . ServerStop , listener ) ;
128156 }
129157
130158 public onMultipleLaunchTargets ( listener : ( targets : LaunchTarget [ ] ) => any , thisArg ?: any ) {
131- return this . _addListener ( 'server: MultipleLaunchTargets' , listener , thisArg ) ;
159+ return this . _addListener ( Events . MultipleLaunchTargets , listener , thisArg ) ;
132160 }
133161
134162 public onOmnisharpStart ( listener : ( ) => any ) {
135- return this . _addListener ( 'started' , listener ) ;
163+ return this . _addListener ( Events . Started , listener ) ;
136164 }
137165
138166 private _addListener ( event : string , listener : ( e : any ) => any , thisArg ?: any ) : Disposable {
@@ -162,19 +190,19 @@ export abstract class OmnisharpServer {
162190 const cwd = dirname ( solutionPath ) ,
163191 argv = [ '-s' , solutionPath , '--hostPID' , process . pid . toString ( ) , 'dnx:enablePackageRestore=false' ] . concat ( this . _extraArgv ) ;
164192
165- this . _fireEvent ( 'stdout' , `[INFO] Starting OmniSharp at '${ solutionPath } '...\n` ) ;
166- this . _fireEvent ( ' BeforeServerStart' , solutionPath ) ;
193+ this . _fireEvent ( Events . StdOut , `[INFO] Starting OmniSharp at '${ solutionPath } '...\n` ) ;
194+ this . _fireEvent ( Events . BeforeServerStart , solutionPath ) ;
167195
168196 return omnisharpLauncher ( cwd , argv ) . then ( value => {
169197 this . _serverProcess = value . process ;
170- this . _fireEvent ( 'stdout' , `[INFO] Started OmniSharp from '${ value . command } ' with process id ${ value . process . pid } ...\n` ) ;
171- this . _fireEvent ( ' ServerStart' , solutionPath ) ;
198+ this . _fireEvent ( Events . StdOut , `[INFO] Started OmniSharp from '${ value . command } ' with process id ${ value . process . pid } ...\n` ) ;
199+ this . _fireEvent ( Events . ServerStart , solutionPath ) ;
172200 this . _setState ( ServerState . Started ) ;
173201 return this . _doConnect ( ) ;
174202 } ) . then ( _ => {
175203 this . _processQueue ( ) ;
176204 } , err => {
177- this . _fireEvent ( ' ServerError' , err ) ;
205+ this . _fireEvent ( Events . ServerError , err ) ;
178206 throw err ;
179207 } ) ;
180208 }
@@ -189,7 +217,8 @@ export abstract class OmnisharpServer {
189217 // nothing to kill
190218 ret = Promise . resolve < OmnisharpServer > ( undefined ) ;
191219
192- } else if ( / ^ w i n / . test ( process . platform ) ) {
220+ }
221+ else if ( process . platform === 'win32' ) {
193222 // when killing a process in windows its child
194223 // processes are *not* killed but become root
195224 // processes. Therefore we use TASKKILL.EXE
@@ -199,13 +228,16 @@ export abstract class OmnisharpServer {
199228 return reject ( err ) ;
200229 }
201230 } ) ;
231+
202232 killer . on ( 'exit' , resolve ) ;
203233 killer . on ( 'error' , reject ) ;
204234 } ) ;
205- } else {
235+ }
236+ else {
206237 this . _serverProcess . kill ( 'SIGTERM' ) ;
207238 ret = Promise . resolve < OmnisharpServer > ( undefined ) ;
208239 }
240+
209241 return ret . then ( _ => {
210242 this . _start = null ;
211243 this . _serverProcess = null ;
@@ -248,7 +280,7 @@ export abstract class OmnisharpServer {
248280 }
249281 }
250282
251- this . _fireEvent ( 'server: MultipleLaunchTargets' , targets ) ;
283+ this . _fireEvent ( Events . MultipleLaunchTargets , targets ) ;
252284 return Promise . reject < void > ( undefined ) ;
253285 }
254286
@@ -326,17 +358,6 @@ export abstract class OmnisharpServer {
326358 }
327359
328360 protected abstract _makeNextRequest ( path : string , data : any ) : Promise < any > ;
329-
330- // private _statOnRequestStart(request: Request): void {
331- // console.log(`[DEBUG] *enqueuing* request '${request.path}' (queue size is ${this._queue.length})\n`);
332- // }
333-
334- // private _statOnRequestEnd(request: Request, successfully: boolean): void {
335- // var duration = Date.now() - request._enqueued,
336- // state = successfully ? 'successfully' : 'with errors';
337-
338- // console.log(`[DEBUG] request '${request.path}' finished *${state}* after ${duration}ms\n`);
339- // }
340361}
341362
342363namespace WireProtocol {
@@ -370,7 +391,6 @@ export class StdioOmnisharpServer extends OmnisharpServer {
370391
371392 private static _seqPool = 1 ;
372393 private static StartupTimeout = 1000 * 60 ;
373- //private static ResponsePacketTimeout = 1000 * 60 * 15; // helps debugging
374394
375395 private _rl : ReadLine ;
376396 private _activeRequest : { [ seq : number ] : { onSuccess : Function ; onError : Function ; } } = Object . create ( null ) ;
@@ -433,14 +453,15 @@ export class StdioOmnisharpServer extends OmnisharpServer {
433453
434454 const onLineReceived = ( line : string ) => {
435455 if ( line [ 0 ] !== '{' ) {
436- this . _fireEvent ( 'stdout' , `${ line } \n` ) ;
456+ this . _fireEvent ( Events . StdOut , `${ line } \n` ) ;
437457 return ;
438458 }
439459
440460 let packet : WireProtocol . Packet ;
441461 try {
442462 packet = JSON . parse ( line ) ;
443- } catch ( e ) {
463+ }
464+ catch ( e ) {
444465 // not json
445466 return ;
446467 }
@@ -462,6 +483,7 @@ export class StdioOmnisharpServer extends OmnisharpServer {
462483 break ;
463484 }
464485 } ;
486+
465487 this . _rl . addListener ( 'line' , onLineReceived ) ;
466488 this . _callOnStop . push ( ( ) => this . _rl . removeListener ( 'line' , onLineReceived ) ) ;
467489 }
@@ -490,7 +512,7 @@ export class StdioOmnisharpServer extends OmnisharpServer {
490512 if ( packet . Event === 'log' ) {
491513 // handle log events
492514 const entry = < { LogLevel : string ; Name : string ; Message : string ; } > packet . Body ;
493- this . _fireEvent ( 'stdout' , `[${ entry . LogLevel } :${ entry . Name } ] ${ entry . Message } \n` ) ;
515+ this . _fireEvent ( Events . StdOut , `[${ entry . LogLevel } :${ entry . Name } ] ${ entry . Message } \n` ) ;
494516 return ;
495517 } else {
496518 // fwd all other events
0 commit comments