@@ -86,24 +86,21 @@ export class TsLintRunner {
8686 private readonly configCache = new ConfigCache ( ) ;
8787
8888 constructor (
89- private trace : ( data : string ) => void ,
89+ private readonly trace : ( data : string ) => void ,
9090 ) { }
9191
9292 public runTsLint (
9393 filePath : string ,
9494 contents : string | typescript . Program ,
9595 configuration : RunConfiguration ,
9696 ) : RunResult {
97- this . trace ( 'start validateTextDocument' ) ;
98-
99- this . trace ( 'validateTextDocument: about to load tslint library' ) ;
97+ this . traceMethod ( 'runTsLint' , 'start' ) ;
10098
10199 const warnings : string [ ] = [ ] ;
102-
103100 if ( ! this . document2LibraryCache . has ( filePath ) ) {
104101 this . loadLibrary ( filePath , configuration , warnings ) ;
105102 }
106- this . trace ( 'validateTextDocument: loaded tslint library') ;
103+ this . traceMethod ( 'runTsLint' , 'Loaded tslint library') ;
107104
108105 if ( ! this . document2LibraryCache . has ( filePath ) ) {
109106 return emptyResult ;
@@ -122,16 +119,20 @@ export class TsLintRunner {
122119 } ;
123120 }
124121
125- this . trace ( 'About to validate ' + filePath ) ;
122+ this . traceMethod ( 'runTsLint' , 'About to validate ' + filePath ) ;
126123 return this . doRun ( filePath , contents , library , configuration , warnings ) ;
127124 }
128125
129126 public onConfigFileChange ( _tsLintFilePath : string ) {
130127 this . configCache . flush ( ) ;
131128 }
132129
130+ private traceMethod ( method : string , message : string ) {
131+ this . trace ( `(${ method } ) ${ message } ` ) ;
132+ }
133+
133134 private loadLibrary ( filePath : string , configuration : RunConfiguration , warningsOutput : string [ ] ) : void {
134- this . trace ( ` loadLibrary for ${ filePath } `) ;
135+ this . traceMethod ( ' loadLibrary' , `trying to load ${ filePath } `) ;
135136 const getGlobalPath = ( ) => this . getGlobalPackageManagerPath ( configuration . packageManager ) ;
136137 const directory = dirname ( filePath ) ;
137138
@@ -167,6 +168,8 @@ export class TsLintRunner {
167168 }
168169 }
169170
171+ this . traceMethod ( 'loadLibrary' , `Resolved tslint to ${ tsLintPath } ` ) ;
172+
170173 this . document2LibraryCache . set ( filePath , ( ) => {
171174 let library ;
172175 if ( ! this . tslintPath2Library . has ( tsLintPath ) ) {
@@ -183,7 +186,7 @@ export class TsLintRunner {
183186 }
184187
185188 private getGlobalPackageManagerPath ( packageManager : string = 'npm' ) : string | undefined {
186- this . trace ( `Begin - Resolve Global Package Manager Path for: ${ packageManager } ` ) ;
189+ this . traceMethod ( 'getGlobalPackageManagerPath' , `Begin - Resolve Global Package Manager Path for: ${ packageManager } ` ) ;
187190
188191 if ( ! this . globalPackageManagerPath . has ( packageManager ) ) {
189192 let path : string | undefined ;
@@ -194,18 +197,18 @@ export class TsLintRunner {
194197 }
195198 this . globalPackageManagerPath . set ( packageManager , path ! ) ;
196199 }
197- this . trace ( `Done - Resolve Global Package Manager Path for: ${ packageManager } ` ) ;
200+ this . traceMethod ( 'getGlobalPackageManagerPath' , `Done - Resolve Global Package Manager Path for: ${ packageManager } ` ) ;
198201 return this . globalPackageManagerPath . get ( packageManager ) ;
199202 }
200203
201204 private doRun (
202205 filePath : string ,
203206 contents : string | typescript . Program ,
204- library : typeof import ( 'tslint' ) ,
207+ library : typeof import ( 'tslint' ) ,
205208 configuration : RunConfiguration ,
206209 warnings : string [ ] ,
207210 ) : RunResult {
208- this . trace ( 'start doValidate ' + filePath ) ;
211+ this . traceMethod ( 'doRun' , `starting validation for ${ filePath } ` ) ;
209212 const uri = filePath ;
210213
211214 let cwd = configuration . workspaceFolderPath ;
@@ -214,22 +217,22 @@ export class TsLintRunner {
214217 }
215218
216219 if ( this . fileIsExcluded ( configuration , filePath , cwd ) ) {
217- this . trace ( `No linting: file ${ filePath } is excluded` ) ;
220+ this . traceMethod ( 'doRun' , `No linting: file ${ filePath } is excluded` ) ;
218221 return emptyResult ;
219222 }
220223
221224 if ( cwd ) {
222- this . trace ( `Changed directory to ${ cwd } ` ) ;
225+ this . traceMethod ( 'doRun' , `Changed directory to ${ cwd } ` ) ;
223226 process . chdir ( cwd ) ;
224227 }
225228
226229 const configFile = configuration . configFile || null ;
227230 let linterConfiguration : Configuration | undefined ;
228- this . trace ( 'validateTextDocument: about to getConfiguration') ;
231+ this . traceMethod ( 'doRun' , 'About to getConfiguration') ;
229232 try {
230233 linterConfiguration = this . getConfiguration ( uri , filePath , library , configFile ) ;
231234 } catch ( err ) {
232- this . trace ( `No linting: exception when getting tslint configuration for ${ filePath } , configFile= ${ configFile } ` ) ;
235+ this . traceMethod ( 'doRun' , `No linting: exception when getting tslint configuration for ${ filePath } , configFile= ${ configFile } ` ) ;
233236 warnings . push ( getConfigurationFailureMessage ( err ) ) ;
234237 return {
235238 lintResult : emptyLintResult ,
@@ -238,23 +241,23 @@ export class TsLintRunner {
238241 }
239242
240243 if ( ! linterConfiguration ) {
241- this . trace ( `No linting: no tslint configuration` ) ;
244+ this . traceMethod ( 'doRun' , `No linting: no tslint configuration` ) ;
242245 return emptyResult ;
243246 }
244- this . trace ( 'validateTextDocument: configuration fetched') ;
247+ this . traceMethod ( 'doRun' , 'Configuration fetched') ;
245248
246249 if ( isJsDocument ( filePath ) && ! configuration . jsEnable ) {
247- this . trace ( `No linting: a JS document, but js linting is disabled` ) ;
250+ this . traceMethod ( 'doRun' , `No linting: a JS document, but js linting is disabled` ) ;
248251 return emptyResult ;
249252 }
250253
251254 if ( configuration . validateWithDefaultConfig === false && this . configCache . configuration ! . isDefaultLinterConfig ) {
252- this . trace ( `No linting: linting with default tslint configuration is disabled` ) ;
255+ this . traceMethod ( 'doRun' , `No linting: linting with default tslint configuration is disabled` ) ;
253256 return emptyResult ;
254257 }
255258
256259 if ( isExcludedFromLinterOptions ( linterConfiguration . linterConfiguration , filePath ) ) {
257- this . trace ( `No linting: file is excluded using linterOptions.exclude` ) ;
260+ this . traceMethod ( 'doRun' , `No linting: file is excluded using linterOptions.exclude` ) ;
258261 return emptyResult ;
259262 }
260263
@@ -279,10 +282,10 @@ export class TsLintRunner {
279282
280283 try { // clean up if tslint crashes
281284 const linter = new library . Linter ( options , typeof contents === 'string' ? undefined : contents ) ;
282- this . trace ( `Linting: start linting` ) ;
285+ this . traceMethod ( 'doRun' , `Linting: start linting` ) ;
283286 linter . lint ( filePath , typeof contents === 'string' ? contents : '' , linterConfiguration . linterConfiguration ) ;
284287 result = linter . getResult ( ) ;
285- this . trace ( `Linting: ended linting` ) ;
288+ this . traceMethod ( 'doRun' , `Linting: ended linting` ) ;
286289 } finally {
287290 console . warn = originalConsoleWarn ;
288291 }
@@ -296,7 +299,7 @@ export class TsLintRunner {
296299 }
297300
298301 private getConfiguration ( uri : string , filePath : string , library : typeof tslint , configFileName : string | null ) : Configuration | undefined {
299- this . trace ( 'getConfiguration for' + uri ) ;
302+ this . traceMethod ( 'getConfiguration' , `Starting for ${ uri } ` ) ;
300303
301304 const config = this . configCache . get ( filePath ) ;
302305 if ( config ) {
@@ -366,7 +369,7 @@ export class TsLintRunner {
366369 } else {
367370 newEnv [ nodePathKey ] = nodePath ;
368371 }
369- this . trace ( `NODE_PATH value is: ${ newEnv [ nodePathKey ] } ` ) ;
372+ this . traceMethod ( 'resolveTsLint' , `NODE_PATH value is: ${ newEnv [ nodePathKey ] } ` ) ;
370373 }
371374 newEnv . ELECTRON_RUN_AS_NODE = '1' ;
372375 const spanwResults = cp . spawnSync ( process . argv0 , [ '-e' , app ] , { cwd, env : newEnv } ) ;
0 commit comments