Skip to content

Commit 5b70dcf

Browse files
committed
use token color map in textmate service
1 parent ff72b61 commit 5b70dcf

4 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/vs/workbench/services/textMate/browser/abstractTextMateService.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
1010
import { Emitter, Event } from 'vs/base/common/event';
1111
import * as resources from 'vs/base/common/resources';
1212
import * as types from 'vs/base/common/types';
13+
import { equals as equalArray } from 'vs/base/common/arrays';
1314
import { URI } from 'vs/base/common/uri';
1415
import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
1516
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
4445
private _grammarFactory: TMGrammarFactory | null;
4546
private _tokenizersRegistrations: IDisposable[];
4647
protected _currentTheme: IRawTheme | null;
48+
protected _currentTokenColorMap: string[] | null;
4749

4850
constructor(
4951
@IModeService private readonly _modeService: IModeService,
@@ -65,6 +67,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
6567
this._tokenizersRegistrations = [];
6668

6769
this._currentTheme = null;
70+
this._currentTokenColorMap = null;
6871

6972
grammarsExtPoint.setHandler((extensions) => {
7073
this._grammarDefinitions = null;
@@ -245,16 +248,17 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
245248
}
246249

247250
private _updateTheme(grammarFactory: TMGrammarFactory, colorTheme: IColorTheme, forceUpdate: boolean): void {
248-
if (!forceUpdate && this._currentTheme && AbstractTextMateService.equalsTokenRules(this._currentTheme.settings, colorTheme.tokenColors)) {
251+
if (!forceUpdate && this._currentTheme && this._currentTokenColorMap && AbstractTextMateService.equalsTokenRules(this._currentTheme.settings, colorTheme.tokenColors) && equalArray(this._currentTokenColorMap, colorTheme.tokenColorMap)) {
249252
return;
250253
}
251254
this._currentTheme = { name: colorTheme.label, settings: colorTheme.tokenColors };
252-
this._doUpdateTheme(grammarFactory, this._currentTheme);
255+
this._currentTokenColorMap = colorTheme.tokenColorMap;
256+
this._doUpdateTheme(grammarFactory, this._currentTheme, this._currentTokenColorMap);
253257
}
254258

255-
protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme): void {
256-
grammarFactory.setTheme(theme);
257-
let colorMap = AbstractTextMateService._toColorMap(grammarFactory.getColorMap());
259+
protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme, tokenColorMap: string[]): void {
260+
grammarFactory.setTheme(theme, tokenColorMap);
261+
let colorMap = AbstractTextMateService._toColorMap(tokenColorMap);
258262
let cssRules = generateTokensCSSForColorMap(colorMap);
259263
this._styleElement.innerHTML = cssRules;
260264
TokenizationRegistry.setColorMap(colorMap);

src/vs/workbench/services/textMate/common/TMGrammarFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ export class TMGrammarFactory extends Disposable {
102102
return this._languageToScope2[languageId] ? true : false;
103103
}
104104

105-
public setTheme(theme: IRawTheme): void {
106-
this._grammarRegistry.setTheme(theme);
105+
public setTheme(theme: IRawTheme, colorMap: string[]): void {
106+
this._grammarRegistry.setTheme(theme, colorMap);
107107
}
108108

109109
public getColorMap(): string[] {

src/vs/workbench/services/textMate/electron-browser/textMateService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@ export class TextMateService extends AbstractTextMateService {
206206
return;
207207
}
208208
this._workerProxy = proxy;
209-
if (this._currentTheme) {
210-
this._workerProxy.acceptTheme(this._currentTheme);
209+
if (this._currentTheme && this._currentTokenColorMap) {
210+
this._workerProxy.acceptTheme(this._currentTheme, this._currentTokenColorMap);
211211
}
212212
this._modelService.getModels().forEach((model) => this._onModelAdded(model));
213213
});
214214
}
215215
}
216216

217-
protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme): void {
218-
super._doUpdateTheme(grammarFactory, theme);
219-
if (this._currentTheme && this._workerProxy) {
220-
this._workerProxy.acceptTheme(this._currentTheme);
217+
protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme, colorMap: string[]): void {
218+
super._doUpdateTheme(grammarFactory, theme, colorMap);
219+
if (this._currentTheme && this._currentTokenColorMap && this._workerProxy) {
220+
this._workerProxy.acceptTheme(this._currentTheme, this._currentTokenColorMap);
221221
}
222222
}
223223

src/vs/workbench/services/textMate/electron-browser/textMateWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ export class TextMateWorker {
185185
return this._grammarCache[languageId];
186186
}
187187

188-
public acceptTheme(theme: IRawTheme): void {
188+
public acceptTheme(theme: IRawTheme, colorMap: string[]): void {
189189
if (this._grammarFactory) {
190-
this._grammarFactory.setTheme(theme);
190+
this._grammarFactory.setTheme(theme, colorMap);
191191
}
192192
}
193193

0 commit comments

Comments
 (0)