From 5b70dcfb8ee31f0caa163577c7693ba0f06ff7f4 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 21 Nov 2019 12:10:10 +0100 Subject: [PATCH] use token color map in textmate service --- .../textMate/browser/abstractTextMateService.ts | 14 +++++++++----- .../services/textMate/common/TMGrammarFactory.ts | 4 ++-- .../textMate/electron-browser/textMateService.ts | 12 ++++++------ .../textMate/electron-browser/textMateWorker.ts | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/services/textMate/browser/abstractTextMateService.ts b/src/vs/workbench/services/textMate/browser/abstractTextMateService.ts index 0b4e3be1f52..a782f0cd7ac 100644 --- a/src/vs/workbench/services/textMate/browser/abstractTextMateService.ts +++ b/src/vs/workbench/services/textMate/browser/abstractTextMateService.ts @@ -10,6 +10,7 @@ import { onUnexpectedError } from 'vs/base/common/errors'; import { Emitter, Event } from 'vs/base/common/event'; import * as resources from 'vs/base/common/resources'; import * as types from 'vs/base/common/types'; +import { equals as equalArray } from 'vs/base/common/arrays'; import { URI } from 'vs/base/common/uri'; import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token'; import { IState, ITokenizationSupport, LanguageId, TokenMetadata, TokenizationRegistry, StandardTokenType, LanguageIdentifier } from 'vs/editor/common/modes'; @@ -44,6 +45,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex private _grammarFactory: TMGrammarFactory | null; private _tokenizersRegistrations: IDisposable[]; protected _currentTheme: IRawTheme | null; + protected _currentTokenColorMap: string[] | null; constructor( @IModeService private readonly _modeService: IModeService, @@ -65,6 +67,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex this._tokenizersRegistrations = []; this._currentTheme = null; + this._currentTokenColorMap = null; grammarsExtPoint.setHandler((extensions) => { this._grammarDefinitions = null; @@ -245,16 +248,17 @@ export abstract class AbstractTextMateService extends Disposable implements ITex } private _updateTheme(grammarFactory: TMGrammarFactory, colorTheme: IColorTheme, forceUpdate: boolean): void { - if (!forceUpdate && this._currentTheme && AbstractTextMateService.equalsTokenRules(this._currentTheme.settings, colorTheme.tokenColors)) { + if (!forceUpdate && this._currentTheme && this._currentTokenColorMap && AbstractTextMateService.equalsTokenRules(this._currentTheme.settings, colorTheme.tokenColors) && equalArray(this._currentTokenColorMap, colorTheme.tokenColorMap)) { return; } this._currentTheme = { name: colorTheme.label, settings: colorTheme.tokenColors }; - this._doUpdateTheme(grammarFactory, this._currentTheme); + this._currentTokenColorMap = colorTheme.tokenColorMap; + this._doUpdateTheme(grammarFactory, this._currentTheme, this._currentTokenColorMap); } - protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme): void { - grammarFactory.setTheme(theme); - let colorMap = AbstractTextMateService._toColorMap(grammarFactory.getColorMap()); + protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme, tokenColorMap: string[]): void { + grammarFactory.setTheme(theme, tokenColorMap); + let colorMap = AbstractTextMateService._toColorMap(tokenColorMap); let cssRules = generateTokensCSSForColorMap(colorMap); this._styleElement.innerHTML = cssRules; TokenizationRegistry.setColorMap(colorMap); diff --git a/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts b/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts index 38e3101c34b..0a6c9abffe9 100644 --- a/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts +++ b/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts @@ -102,8 +102,8 @@ export class TMGrammarFactory extends Disposable { return this._languageToScope2[languageId] ? true : false; } - public setTheme(theme: IRawTheme): void { - this._grammarRegistry.setTheme(theme); + public setTheme(theme: IRawTheme, colorMap: string[]): void { + this._grammarRegistry.setTheme(theme, colorMap); } public getColorMap(): string[] { diff --git a/src/vs/workbench/services/textMate/electron-browser/textMateService.ts b/src/vs/workbench/services/textMate/electron-browser/textMateService.ts index 6a4a4d4d2e2..f33593da728 100644 --- a/src/vs/workbench/services/textMate/electron-browser/textMateService.ts +++ b/src/vs/workbench/services/textMate/electron-browser/textMateService.ts @@ -206,18 +206,18 @@ export class TextMateService extends AbstractTextMateService { return; } this._workerProxy = proxy; - if (this._currentTheme) { - this._workerProxy.acceptTheme(this._currentTheme); + if (this._currentTheme && this._currentTokenColorMap) { + this._workerProxy.acceptTheme(this._currentTheme, this._currentTokenColorMap); } this._modelService.getModels().forEach((model) => this._onModelAdded(model)); }); } } - protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme): void { - super._doUpdateTheme(grammarFactory, theme); - if (this._currentTheme && this._workerProxy) { - this._workerProxy.acceptTheme(this._currentTheme); + protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme, colorMap: string[]): void { + super._doUpdateTheme(grammarFactory, theme, colorMap); + if (this._currentTheme && this._currentTokenColorMap && this._workerProxy) { + this._workerProxy.acceptTheme(this._currentTheme, this._currentTokenColorMap); } } diff --git a/src/vs/workbench/services/textMate/electron-browser/textMateWorker.ts b/src/vs/workbench/services/textMate/electron-browser/textMateWorker.ts index 6f78679f1fd..6f2725ba9c6 100644 --- a/src/vs/workbench/services/textMate/electron-browser/textMateWorker.ts +++ b/src/vs/workbench/services/textMate/electron-browser/textMateWorker.ts @@ -185,9 +185,9 @@ export class TextMateWorker { return this._grammarCache[languageId]; } - public acceptTheme(theme: IRawTheme): void { + public acceptTheme(theme: IRawTheme, colorMap: string[]): void { if (this._grammarFactory) { - this._grammarFactory.setTheme(theme); + this._grammarFactory.setTheme(theme, colorMap); } } -- GitLab