From dd5721b35a73df2feb6665033bcf2b736f3d65a9 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 14 Dec 2018 11:06:23 +0100 Subject: [PATCH] Minor tweaks --- .../textMate/electron-browser/TMSyntax.ts | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts b/src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts index 977980e627a..7220ec1a9a0 100644 --- a/src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts +++ b/src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts @@ -25,6 +25,7 @@ import { IEmbeddedLanguagesMap, ITMSyntaxExtensionPoint, TokenTypesContribution, import { ITextMateService } from 'vs/workbench/services/textMate/electron-browser/textMateService'; import { ITokenColorizationRule, IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { IEmbeddedLanguagesMap as IEmbeddedLanguagesMap2, IGrammar, ITokenTypeMap, Registry, StackElement, StandardTokenType } from 'vscode-textmate'; +import { Disposable } from 'vs/base/common/lifecycle'; export class TMScopeRegistry { @@ -132,46 +133,37 @@ interface ICreateGrammarResult { containsEmbeddedLanguages: boolean; } -export class TextMateService implements ITextMateService { +export class TextMateService extends Disposable implements ITextMateService { public _serviceBrand: any; + private readonly _onDidEncounterLanguage: Emitter = this._register(new Emitter()); + public readonly onDidEncounterLanguage: Event = this._onDidEncounterLanguage.event; + + private readonly _styleElement: HTMLStyleElement; + private _grammarRegistry: Promise<[Registry, StackElement]> | null; - private _modeService: IModeService; - private _themeService: IWorkbenchThemeService; - private _fileService: IFileService; - private _logService: ILogService; private _scopeRegistry: TMScopeRegistry; private _injections: { [scopeName: string]: string[]; }; private _injectedEmbeddedLanguages: { [scopeName: string]: IEmbeddedLanguagesMap[]; }; - private _notificationService: INotificationService; - private _languageToScope: Map; - private _styleElement: HTMLStyleElement; - private _currentTokenColors: ITokenColorizationRule[]; - public readonly onDidEncounterLanguage: Event; - constructor( - @IModeService modeService: IModeService, - @IWorkbenchThemeService themeService: IWorkbenchThemeService, - @IFileService fileService: IFileService, - @INotificationService notificationService: INotificationService, - @ILogService logService: ILogService, - @IExtensionService extensionService: IExtensionService + @IModeService private readonly _modeService: IModeService, + @IWorkbenchThemeService private readonly _themeService: IWorkbenchThemeService, + @IFileService private readonly _fileService: IFileService, + @INotificationService private readonly _notificationService: INotificationService, + @ILogService private readonly _logService: ILogService, + @IExtensionService private readonly _extensionService: IExtensionService ) { + super(); this._styleElement = dom.createStyleSheet(); this._styleElement.className = 'vscode-tokens-styles'; - this._modeService = modeService; - this._themeService = themeService; - this._fileService = fileService; - this._logService = logService; this._scopeRegistry = new TMScopeRegistry(); - this.onDidEncounterLanguage = this._scopeRegistry.onDidEncounterLanguage; + this._scopeRegistry.onDidEncounterLanguage((language) => this._onDidEncounterLanguage.fire(language)); this._injections = {}; this._injectedEmbeddedLanguages = {}; this._languageToScope = new Map(); - this._notificationService = notificationService; this._grammarRegistry = null; @@ -204,7 +196,7 @@ export class TextMateService implements ITextMateService { this._modeService.onDidCreateMode((mode) => { let modeId = mode.getId(); // Modes can be instantiated before the extension points have finished registering - extensionService.whenInstalledExtensionsRegistered().then(() => { + this._extensionService.whenInstalledExtensionsRegistered().then(() => { if (this._languageToScope.has(modeId)) { this.registerDefinition(modeId); } -- GitLab