fixes for theming semantic tokens

pull/85384/head
Martin Aeschlimann 2019-11-22 13:52:24 +01:00
parent a78363abd0
commit 1803c7fd76
4 changed files with 14 additions and 9 deletions

View File

@ -34,16 +34,16 @@ export function activate(context: vscode.ExtensionContext): any {
result.push(startCharacter + length); result.push(startCharacter + length);
const segments = property.split('.'); const [type, ...modifiers] = property.split('.');
let tokenType = legend.tokenTypes.indexOf(segments[0]); let tokenType = legend.tokenTypes.indexOf(type);
if (tokenType === -1) { if (tokenType === -1) {
tokenType = 0; tokenType = 0;
} }
result.push(tokenType); result.push(tokenType);
let tokenModifiers = 0; let tokenModifiers = 0;
for (let i = 1; i < segments.length; i++) { for (let i = 0; i < modifiers.length; i++) {
const index = legend.tokenTypes.indexOf(segments[0]); const index = legend.tokenModifiers.indexOf(modifiers[i]);
if (index !== -1) { if (index !== -1) {
tokenModifiers = tokenModifiers | 1 << index; tokenModifiers = tokenModifiers | 1 << index;
} }

View File

@ -476,6 +476,7 @@ class ModelSemanticColoring extends Disposable {
this._register(this._model.onDidChangeContent(e => this._fetchSemanticTokens.schedule())); this._register(this._model.onDidChangeContent(e => this._fetchSemanticTokens.schedule()));
this._register(SemanticColoringProviderRegistry.onDidChange(e => this._fetchSemanticTokens.schedule())); this._register(SemanticColoringProviderRegistry.onDidChange(e => this._fetchSemanticTokens.schedule()));
this._register(themeService.onThemeChange(_ => this._fetchSemanticTokens.schedule()));
this._fetchSemanticTokens.schedule(0); this._fetchSemanticTokens.schedule(0);
} }
@ -554,12 +555,13 @@ class ModelSemanticColoring extends Disposable {
const tokenTypeIndex = srcTokens[srcOffset + 3]; const tokenTypeIndex = srcTokens[srcOffset + 3];
const tokenType = legend.tokenTypes[tokenTypeIndex]; const tokenType = legend.tokenTypes[tokenTypeIndex];
const tokenModifierSet = srcTokens[srcOffset + 4]; let tokenModifierSet = srcTokens[srcOffset + 4];
let tokenModifiers: string[] = []; let tokenModifiers: string[] = [];
for (let modifierIndex = 0; tokenModifierSet !== 0 && modifierIndex < legend.tokenModifiers.length; modifierIndex++) { for (let modifierIndex = 0; tokenModifierSet !== 0 && modifierIndex < legend.tokenModifiers.length; modifierIndex++) {
if (tokenModifierSet & 1) { if (tokenModifierSet & 1) {
tokenModifiers.push(legend.tokenTypes[modifierIndex]); tokenModifiers.push(legend.tokenModifiers[modifierIndex]);
} }
tokenModifierSet = tokenModifierSet >> 1;
} }
const metadata = this._themeService.getTheme().getTokenStyleMetadata(tokenType, tokenModifiers); const metadata = this._themeService.getTheme().getTokenStyleMetadata(tokenType, tokenModifiers);

View File

@ -364,10 +364,12 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
this.currentColorTheme = themeData; this.currentColorTheme = themeData;
themeData.setCustomColors(this.colorCustomizations); themeData.setCustomColors(this.colorCustomizations);
themeData.setCustomTokenColors(this.tokenColorCustomizations); themeData.setCustomTokenColors(this.tokenColorCustomizations);
themeData.setCustomTokenStyleRules(this.tokenStylesCustomizations);
return Promise.resolve(themeData); return Promise.resolve(themeData);
} }
themeData.setCustomColors(this.colorCustomizations); themeData.setCustomColors(this.colorCustomizations);
themeData.setCustomTokenColors(this.tokenColorCustomizations); themeData.setCustomTokenColors(this.tokenColorCustomizations);
themeData.setCustomTokenStyleRules(this.tokenStylesCustomizations);
this.updateDynamicCSSRules(themeData); this.updateDynamicCSSRules(themeData);
return this.applyTheme(themeData, settingsTarget); return this.applyTheme(themeData, settingsTarget);
}, error => { }, error => {
@ -380,6 +382,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
await this.currentColorTheme.reload(this.extensionResourceLoaderService); await this.currentColorTheme.reload(this.extensionResourceLoaderService);
this.currentColorTheme.setCustomColors(this.colorCustomizations); this.currentColorTheme.setCustomColors(this.colorCustomizations);
this.currentColorTheme.setCustomTokenColors(this.tokenColorCustomizations); this.currentColorTheme.setCustomTokenColors(this.tokenColorCustomizations);
this.currentColorTheme.setCustomTokenStyleRules(this.tokenStylesCustomizations);
this.updateDynamicCSSRules(this.currentColorTheme); this.updateDynamicCSSRules(this.currentColorTheme);
this.applyTheme(this.currentColorTheme, undefined, false); this.applyTheme(this.currentColorTheme, undefined, false);
} }

View File

@ -340,12 +340,12 @@ export class ColorThemeData implements IColorTheme {
} }
public setCustomTokenStyleRules(tokenStylingRules: IExperimentalTokenStyleCustomizations) { public setCustomTokenStyleRules(tokenStylingRules: IExperimentalTokenStyleCustomizations) {
this.tokenStylingRules = []; this.customTokenStylingRules = [];
readCustomTokenStyleRules(tokenStylingRules, this.tokenStylingRules); readCustomTokenStyleRules(tokenStylingRules, this.customTokenStylingRules);
const themeSpecificColors = tokenStylingRules[`[${this.settingsId}]`] as IExperimentalTokenStyleCustomizations; const themeSpecificColors = tokenStylingRules[`[${this.settingsId}]`] as IExperimentalTokenStyleCustomizations;
if (types.isObject(themeSpecificColors)) { if (types.isObject(themeSpecificColors)) {
readCustomTokenStyleRules(themeSpecificColors, this.tokenStylingRules); readCustomTokenStyleRules(themeSpecificColors, this.customTokenStylingRules);
} }
this.tokenColorIndex = undefined; this.tokenColorIndex = undefined;