提交 5b70dcfb 编写于 作者: M Martin Aeschlimann

use token color map in textmate service

上级 ff72b610
...@@ -10,6 +10,7 @@ import { onUnexpectedError } from 'vs/base/common/errors'; ...@@ -10,6 +10,7 @@ import { onUnexpectedError } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
import * as resources from 'vs/base/common/resources'; import * as resources from 'vs/base/common/resources';
import * as types from 'vs/base/common/types'; 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 { URI } from 'vs/base/common/uri';
import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token'; import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
import { IState, ITokenizationSupport, LanguageId, TokenMetadata, TokenizationRegistry, StandardTokenType, LanguageIdentifier } from 'vs/editor/common/modes'; 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 ...@@ -44,6 +45,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
private _grammarFactory: TMGrammarFactory | null; private _grammarFactory: TMGrammarFactory | null;
private _tokenizersRegistrations: IDisposable[]; private _tokenizersRegistrations: IDisposable[];
protected _currentTheme: IRawTheme | null; protected _currentTheme: IRawTheme | null;
protected _currentTokenColorMap: string[] | null;
constructor( constructor(
@IModeService private readonly _modeService: IModeService, @IModeService private readonly _modeService: IModeService,
...@@ -65,6 +67,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex ...@@ -65,6 +67,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
this._tokenizersRegistrations = []; this._tokenizersRegistrations = [];
this._currentTheme = null; this._currentTheme = null;
this._currentTokenColorMap = null;
grammarsExtPoint.setHandler((extensions) => { grammarsExtPoint.setHandler((extensions) => {
this._grammarDefinitions = null; this._grammarDefinitions = null;
...@@ -245,16 +248,17 @@ export abstract class AbstractTextMateService extends Disposable implements ITex ...@@ -245,16 +248,17 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
} }
private _updateTheme(grammarFactory: TMGrammarFactory, colorTheme: IColorTheme, forceUpdate: boolean): void { 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; return;
} }
this._currentTheme = { name: colorTheme.label, settings: colorTheme.tokenColors }; 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 { protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme, tokenColorMap: string[]): void {
grammarFactory.setTheme(theme); grammarFactory.setTheme(theme, tokenColorMap);
let colorMap = AbstractTextMateService._toColorMap(grammarFactory.getColorMap()); let colorMap = AbstractTextMateService._toColorMap(tokenColorMap);
let cssRules = generateTokensCSSForColorMap(colorMap); let cssRules = generateTokensCSSForColorMap(colorMap);
this._styleElement.innerHTML = cssRules; this._styleElement.innerHTML = cssRules;
TokenizationRegistry.setColorMap(colorMap); TokenizationRegistry.setColorMap(colorMap);
......
...@@ -102,8 +102,8 @@ export class TMGrammarFactory extends Disposable { ...@@ -102,8 +102,8 @@ export class TMGrammarFactory extends Disposable {
return this._languageToScope2[languageId] ? true : false; return this._languageToScope2[languageId] ? true : false;
} }
public setTheme(theme: IRawTheme): void { public setTheme(theme: IRawTheme, colorMap: string[]): void {
this._grammarRegistry.setTheme(theme); this._grammarRegistry.setTheme(theme, colorMap);
} }
public getColorMap(): string[] { public getColorMap(): string[] {
......
...@@ -206,18 +206,18 @@ export class TextMateService extends AbstractTextMateService { ...@@ -206,18 +206,18 @@ export class TextMateService extends AbstractTextMateService {
return; return;
} }
this._workerProxy = proxy; this._workerProxy = proxy;
if (this._currentTheme) { if (this._currentTheme && this._currentTokenColorMap) {
this._workerProxy.acceptTheme(this._currentTheme); this._workerProxy.acceptTheme(this._currentTheme, this._currentTokenColorMap);
} }
this._modelService.getModels().forEach((model) => this._onModelAdded(model)); this._modelService.getModels().forEach((model) => this._onModelAdded(model));
}); });
} }
} }
protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme): void { protected _doUpdateTheme(grammarFactory: TMGrammarFactory, theme: IRawTheme, colorMap: string[]): void {
super._doUpdateTheme(grammarFactory, theme); super._doUpdateTheme(grammarFactory, theme, colorMap);
if (this._currentTheme && this._workerProxy) { if (this._currentTheme && this._currentTokenColorMap && this._workerProxy) {
this._workerProxy.acceptTheme(this._currentTheme); this._workerProxy.acceptTheme(this._currentTheme, this._currentTokenColorMap);
} }
} }
......
...@@ -185,9 +185,9 @@ export class TextMateWorker { ...@@ -185,9 +185,9 @@ export class TextMateWorker {
return this._grammarCache[languageId]; return this._grammarCache[languageId];
} }
public acceptTheme(theme: IRawTheme): void { public acceptTheme(theme: IRawTheme, colorMap: string[]): void {
if (this._grammarFactory) { if (this._grammarFactory) {
this._grammarFactory.setTheme(theme); this._grammarFactory.setTheme(theme, colorMap);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册