提交 bf8fb5f8 编写于 作者: M Martin Aeschlimann

editor token inspect: resolve scopes like the sem highlight code

上级 39424388
...@@ -26,7 +26,7 @@ import { findMatchingThemeRule } from 'vs/workbench/services/textMate/common/TMH ...@@ -26,7 +26,7 @@ import { findMatchingThemeRule } from 'vs/workbench/services/textMate/common/TMH
import { ITextMateService, IGrammar, IToken, StackElement } from 'vs/workbench/services/textMate/common/textMateService'; import { ITextMateService, IGrammar, IToken, StackElement } from 'vs/workbench/services/textMate/common/textMateService';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { ColorThemeData, TokenStyleDefinitions, TokenStyleDefinition } from 'vs/workbench/services/themes/common/colorThemeData'; import { ColorThemeData, TokenStyleDefinitions, TokenStyleDefinition, TextMateThemingRuleDefinitions } from 'vs/workbench/services/themes/common/colorThemeData';
import { TokenStylingRule, TokenStyleData, TokenStyle } from 'vs/platform/theme/common/tokenClassificationRegistry'; import { TokenStylingRule, TokenStyleData, TokenStyle } from 'vs/platform/theme/common/tokenClassificationRegistry';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
...@@ -303,7 +303,7 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget { ...@@ -303,7 +303,7 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget {
const allDefValues = []; // remember the order const allDefValues = []; // remember the order
// first collect to detect when the same rule is used fro multiple properties // first collect to detect when the same rule is used fro multiple properties
for (let property of properties) { for (let property of properties) {
if (semanticTokenInfo.metadata[property]) { if (semanticTokenInfo.metadata[property] !== undefined) {
const definition = semanticTokenInfo.definitions[property]; const definition = semanticTokenInfo.definitions[property];
const defValue = this._renderTokenStyleDefinition(definition, property); const defValue = this._renderTokenStyleDefinition(definition, property);
let properties = propertiesByDefValue[defValue]; let properties = propertiesByDefValue[defValue];
...@@ -532,11 +532,11 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget { ...@@ -532,11 +532,11 @@ class InspectEditorTokensWidget extends Disposable implements IContentWidget {
const isTokenStylingRule = (d: any): d is TokenStylingRule => !!d.value; const isTokenStylingRule = (d: any): d is TokenStylingRule => !!d.value;
if (Array.isArray(definition)) { if (Array.isArray(definition)) {
for (const d of definition) { const scopesDefinition: TextMateThemingRuleDefinitions = {};
const matchingRule = findMatchingThemeRule(theme, d, false); theme.resolveScopes(definition, scopesDefinition);
if (matchingRule) { const matchingRule = scopesDefinition[property];
return `${escape(d.join(' '))}<br><code class="tiw-theme-selector">${matchingRule.rawSelector}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`; if (matchingRule && scopesDefinition.scope) {
} return `${escape(scopesDefinition.scope.join(' '))}<br><code class="tiw-theme-selector">${matchingRule.scope}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
} }
return ''; return '';
} else if (isTokenStylingRule(definition)) { } else if (isTokenStylingRule(definition)) {
......
...@@ -44,6 +44,8 @@ const tokenGroupToScopesMap = { ...@@ -44,6 +44,8 @@ const tokenGroupToScopesMap = {
export type TokenStyleDefinition = TokenStylingRule | ProbeScope[] | TokenStyleValue; export type TokenStyleDefinition = TokenStylingRule | ProbeScope[] | TokenStyleValue;
export type TokenStyleDefinitions = { [P in keyof TokenStyleData]?: TokenStyleDefinition | undefined }; export type TokenStyleDefinitions = { [P in keyof TokenStyleData]?: TokenStyleDefinition | undefined };
export type TextMateThemingRuleDefinitions = { [P in keyof TokenStyleData]?: ITextMateThemingRule | undefined; } & { scope?: ProbeScope; };
const PERSISTED_THEME_STORAGE_KEY = 'colorThemeData'; const PERSISTED_THEME_STORAGE_KEY = 'colorThemeData';
export class ColorThemeData implements IWorkbenchColorTheme { export class ColorThemeData implements IWorkbenchColorTheme {
...@@ -271,7 +273,8 @@ export class ColorThemeData implements IWorkbenchColorTheme { ...@@ -271,7 +273,8 @@ export class ColorThemeData implements IWorkbenchColorTheme {
return colorRegistry.resolveDefaultColor(colorId, this); return colorRegistry.resolveDefaultColor(colorId, this);
} }
public resolveScopes(scopes: ProbeScope[]): TokenStyle | undefined {
public resolveScopes(scopes: ProbeScope[], definitions?: TextMateThemingRuleDefinitions): TokenStyle | undefined {
if (!this.themeTokenScopeMatchers) { if (!this.themeTokenScopeMatchers) {
this.themeTokenScopeMatchers = this.themeTokenColors.map(getScopeMatcher); this.themeTokenScopeMatchers = this.themeTokenColors.map(getScopeMatcher);
...@@ -285,19 +288,24 @@ export class ColorThemeData implements IWorkbenchColorTheme { ...@@ -285,19 +288,24 @@ export class ColorThemeData implements IWorkbenchColorTheme {
let fontStyle: string | undefined = undefined; let fontStyle: string | undefined = undefined;
let foregroundScore = -1; let foregroundScore = -1;
let fontStyleScore = -1; let fontStyleScore = -1;
let fontStyleThemingRule: ITextMateThemingRule | undefined = undefined;
let foregroundThemingRule: ITextMateThemingRule | undefined = undefined;
function findTokenStyleForScopeInScopes(scopeMatchers: Matcher<ProbeScope>[], tokenColors: ITextMateThemingRule[]) { function findTokenStyleForScopeInScopes(scopeMatchers: Matcher<ProbeScope>[], themingRules: ITextMateThemingRule[]) {
for (let i = 0; i < scopeMatchers.length; i++) { for (let i = 0; i < scopeMatchers.length; i++) {
const score = scopeMatchers[i](scope); const score = scopeMatchers[i](scope);
if (score >= 0) { if (score >= 0) {
const settings = tokenColors[i].settings; const themingRule = themingRules[i];
const settings = themingRules[i].settings;
if (score >= foregroundScore && settings.foreground) { if (score >= foregroundScore && settings.foreground) {
foreground = settings.foreground; foreground = settings.foreground;
foregroundScore = score; foregroundScore = score;
foregroundThemingRule = themingRule;
} }
if (score >= fontStyleScore && types.isString(settings.fontStyle)) { if (score >= fontStyleScore && types.isString(settings.fontStyle)) {
fontStyle = settings.fontStyle; fontStyle = settings.fontStyle;
fontStyleScore = score; fontStyleScore = score;
fontStyleThemingRule = themingRule;
} }
} }
} }
...@@ -305,6 +313,12 @@ export class ColorThemeData implements IWorkbenchColorTheme { ...@@ -305,6 +313,12 @@ export class ColorThemeData implements IWorkbenchColorTheme {
findTokenStyleForScopeInScopes(this.themeTokenScopeMatchers, this.themeTokenColors); findTokenStyleForScopeInScopes(this.themeTokenScopeMatchers, this.themeTokenColors);
findTokenStyleForScopeInScopes(this.customTokenScopeMatchers, this.customTokenColors); findTokenStyleForScopeInScopes(this.customTokenScopeMatchers, this.customTokenColors);
if (foreground !== undefined || fontStyle !== undefined) { if (foreground !== undefined || fontStyle !== undefined) {
if (definitions) {
definitions.foreground = foregroundThemingRule;
definitions.bold = definitions.italic = definitions.underline = fontStyleThemingRule;
definitions.scope = scope;
}
return TokenStyle.fromSettings(foreground, fontStyle); return TokenStyle.fromSettings(foreground, fontStyle);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册