Skip to content

Commit bf8fb5f

Browse files
committed
editor token inspect: resolve scopes like the sem highlight code
1 parent 3942438 commit bf8fb5f

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { findMatchingThemeRule } from 'vs/workbench/services/textMate/common/TMH
2626
import { ITextMateService, IGrammar, IToken, StackElement } from 'vs/workbench/services/textMate/common/textMateService';
2727
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
2828
import { CancellationTokenSource } from 'vs/base/common/cancellation';
29-
import { ColorThemeData, TokenStyleDefinitions, TokenStyleDefinition } from 'vs/workbench/services/themes/common/colorThemeData';
29+
import { ColorThemeData, TokenStyleDefinitions, TokenStyleDefinition, TextMateThemingRuleDefinitions } from 'vs/workbench/services/themes/common/colorThemeData';
3030
import { TokenStylingRule, TokenStyleData, TokenStyle } from 'vs/platform/theme/common/tokenClassificationRegistry';
3131
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3232

@@ -303,7 +303,7 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget {
303303
const allDefValues = []; // remember the order
304304
// first collect to detect when the same rule is used fro multiple properties
305305
for (let property of properties) {
306-
if (semanticTokenInfo.metadata[property]) {
306+
if (semanticTokenInfo.metadata[property] !== undefined) {
307307
const definition = semanticTokenInfo.definitions[property];
308308
const defValue = this._renderTokenStyleDefinition(definition, property);
309309
let properties = propertiesByDefValue[defValue];
@@ -532,11 +532,11 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget {
532532

533533
const isTokenStylingRule = (d: any): d is TokenStylingRule => !!d.value;
534534
if (Array.isArray(definition)) {
535-
for (const d of definition) {
536-
const matchingRule = findMatchingThemeRule(theme, d, false);
537-
if (matchingRule) {
538-
return `${escape(d.join(' '))}<br><code class="tiw-theme-selector">${matchingRule.rawSelector}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
539-
}
535+
const scopesDefinition: TextMateThemingRuleDefinitions = {};
536+
theme.resolveScopes(definition, scopesDefinition);
537+
const matchingRule = scopesDefinition[property];
538+
if (matchingRule && scopesDefinition.scope) {
539+
return `${escape(scopesDefinition.scope.join(' '))}<br><code class="tiw-theme-selector">${matchingRule.scope}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
540540
}
541541
return '';
542542
} else if (isTokenStylingRule(definition)) {

src/vs/workbench/services/themes/common/colorThemeData.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const tokenGroupToScopesMap = {
4444
export type TokenStyleDefinition = TokenStylingRule | ProbeScope[] | TokenStyleValue;
4545
export type TokenStyleDefinitions = { [P in keyof TokenStyleData]?: TokenStyleDefinition | undefined };
4646

47+
export type TextMateThemingRuleDefinitions = { [P in keyof TokenStyleData]?: ITextMateThemingRule | undefined; } & { scope?: ProbeScope; };
48+
4749
const PERSISTED_THEME_STORAGE_KEY = 'colorThemeData';
4850

4951
export class ColorThemeData implements IWorkbenchColorTheme {
@@ -271,7 +273,8 @@ export class ColorThemeData implements IWorkbenchColorTheme {
271273
return colorRegistry.resolveDefaultColor(colorId, this);
272274
}
273275

274-
public resolveScopes(scopes: ProbeScope[]): TokenStyle | undefined {
276+
277+
public resolveScopes(scopes: ProbeScope[], definitions?: TextMateThemingRuleDefinitions): TokenStyle | undefined {
275278

276279
if (!this.themeTokenScopeMatchers) {
277280
this.themeTokenScopeMatchers = this.themeTokenColors.map(getScopeMatcher);
@@ -285,26 +288,37 @@ export class ColorThemeData implements IWorkbenchColorTheme {
285288
let fontStyle: string | undefined = undefined;
286289
let foregroundScore = -1;
287290
let fontStyleScore = -1;
291+
let fontStyleThemingRule: ITextMateThemingRule | undefined = undefined;
292+
let foregroundThemingRule: ITextMateThemingRule | undefined = undefined;
288293

289-
function findTokenStyleForScopeInScopes(scopeMatchers: Matcher<ProbeScope>[], tokenColors: ITextMateThemingRule[]) {
294+
function findTokenStyleForScopeInScopes(scopeMatchers: Matcher<ProbeScope>[], themingRules: ITextMateThemingRule[]) {
290295
for (let i = 0; i < scopeMatchers.length; i++) {
291296
const score = scopeMatchers[i](scope);
292297
if (score >= 0) {
293-
const settings = tokenColors[i].settings;
298+
const themingRule = themingRules[i];
299+
const settings = themingRules[i].settings;
294300
if (score >= foregroundScore && settings.foreground) {
295301
foreground = settings.foreground;
296302
foregroundScore = score;
303+
foregroundThemingRule = themingRule;
297304
}
298305
if (score >= fontStyleScore && types.isString(settings.fontStyle)) {
299306
fontStyle = settings.fontStyle;
300307
fontStyleScore = score;
308+
fontStyleThemingRule = themingRule;
301309
}
302310
}
303311
}
304312
}
305313
findTokenStyleForScopeInScopes(this.themeTokenScopeMatchers, this.themeTokenColors);
306314
findTokenStyleForScopeInScopes(this.customTokenScopeMatchers, this.customTokenColors);
307315
if (foreground !== undefined || fontStyle !== undefined) {
316+
if (definitions) {
317+
definitions.foreground = foregroundThemingRule;
318+
definitions.bold = definitions.italic = definitions.underline = fontStyleThemingRule;
319+
definitions.scope = scope;
320+
}
321+
308322
return TokenStyle.fromSettings(foreground, fontStyle);
309323
}
310324
}

0 commit comments

Comments
 (0)