@@ -30,6 +30,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
3030import { IValidGrammarDefinition , IValidEmbeddedLanguagesMap , IValidTokenTypeMap } from 'vs/workbench/services/textMate/common/TMScopeRegistry' ;
3131import { TMGrammarFactory } from 'vs/workbench/services/textMate/common/TMGrammarFactory' ;
3232import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader' ;
33+ import { IProgressService , ProgressLocation } from 'vs/platform/progress/common/progress' ;
3334
3435export abstract class AbstractTextMateService extends Disposable implements ITextMateService {
3536 public _serviceBrand : undefined ;
@@ -41,6 +42,9 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
4142 private readonly _createdModes : string [ ] ;
4243 private readonly _encounteredLanguages : boolean [ ] ;
4344
45+ private _debugMode : boolean ;
46+ private _debugModePrintFunc : ( str : string ) => void ;
47+
4448 private _grammarDefinitions : IValidGrammarDefinition [ ] | null ;
4549 private _grammarFactory : TMGrammarFactory | null ;
4650 private _tokenizersRegistrations : IDisposable [ ] ;
@@ -54,14 +58,18 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
5458 @INotificationService private readonly _notificationService : INotificationService ,
5559 @ILogService private readonly _logService : ILogService ,
5660 @IConfigurationService private readonly _configurationService : IConfigurationService ,
57- @IStorageService private readonly _storageService : IStorageService
61+ @IStorageService private readonly _storageService : IStorageService ,
62+ @IProgressService private readonly _progressService : IProgressService
5863 ) {
5964 super ( ) ;
6065 this . _styleElement = dom . createStyleSheet ( ) ;
6166 this . _styleElement . className = 'vscode-tokens-styles' ;
6267 this . _createdModes = [ ] ;
6368 this . _encounteredLanguages = [ ] ;
6469
70+ this . _debugMode = false ;
71+ this . _debugModePrintFunc = ( ) => { } ;
72+
6573 this . _grammarDefinitions = null ;
6674 this . _grammarFactory = null ;
6775 this . _tokenizersRegistrations = [ ] ;
@@ -174,6 +182,46 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
174182 } ) ;
175183 }
176184
185+ public startDebugMode ( printFn : ( str : string ) => void , onStop : ( ) => void ) : void {
186+ if ( this . _debugMode ) {
187+ this . _notificationService . error ( nls . localize ( 'alreadyDebugging' , "Already Logging." ) ) ;
188+ return ;
189+ }
190+
191+ this . _debugModePrintFunc = printFn ;
192+ this . _debugMode = true ;
193+
194+ if ( this . _debugMode ) {
195+ this . _progressService . withProgress (
196+ {
197+ location : ProgressLocation . Notification ,
198+ buttons : [ nls . localize ( 'stop' , "Stop" ) ]
199+ } ,
200+ ( progress ) => {
201+ progress . report ( {
202+ message : nls . localize ( 'progress1' , "Preparing to log TM Grammar parsing. Press Stop when finished." )
203+ } ) ;
204+
205+ return this . _getVSCodeOniguruma ( ) . then ( ( vscodeOniguruma ) => {
206+ vscodeOniguruma . setDefaultDebugCall ( true ) ;
207+ progress . report ( {
208+ message : nls . localize ( 'progress2' , "Now logging TM Grammar parsing. Press Stop when finished." )
209+ } ) ;
210+ return new Promise < void > ( ( resolve , reject ) => { } ) ;
211+ } ) ;
212+ } ,
213+ ( choice ) => {
214+ this . _getVSCodeOniguruma ( ) . then ( ( vscodeOniguruma ) => {
215+ this . _debugModePrintFunc = ( ) => { } ;
216+ this . _debugMode = false ;
217+ vscodeOniguruma . setDefaultDebugCall ( false ) ;
218+ onStop ( ) ;
219+ } ) ;
220+ }
221+ ) ;
222+ }
223+ }
224+
177225 private _canCreateGrammarFactory ( ) : boolean {
178226 // Check if extension point is ready
179227 return ( this . _grammarDefinitions ? true : false ) ;
@@ -354,7 +402,13 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
354402
355403 private async _doGetVSCodeOniguruma ( ) : Promise < typeof import ( 'vscode-oniguruma' ) > {
356404 const [ vscodeOniguruma , wasm ] = await Promise . all ( [ import ( 'vscode-oniguruma' ) , this . _loadVSCodeOnigurumWASM ( ) ] ) ;
357- await vscodeOniguruma . loadWASM ( wasm ) ;
405+ const options = {
406+ data : wasm ,
407+ print : ( str : string ) => {
408+ this . _debugModePrintFunc ( str ) ;
409+ }
410+ } ;
411+ await vscodeOniguruma . loadWASM ( options ) ;
358412 return vscodeOniguruma ;
359413 }
360414
0 commit comments