提交 8998f7a5 编写于 作者: A Alex Dima

Adopt new vscode textmate

上级 9cebde96
......@@ -294,8 +294,8 @@
<string>(^|\G)\s*(&lt;!--)</string>
<key>end</key>
<string>(--&gt;)</string>
<key>contentName</key>
<string>block.comment.html</string>
<key>name</key>
<string>comment.block.html</string>
<key>captures</key>
<dict>
<key>1</key>
......@@ -1902,7 +1902,7 @@
<key>match</key>
<string>(`+)([^`]|(?!(?&lt;!`)\1(?!`))`)*+(\1)</string>
<key>name</key>
<string>markup.raw.inline.markdown</string>
<string>markup.inline.raw.markdown</string>
</dict>
</dict>
</dict>
......
......@@ -19,9 +19,28 @@
"support.class",
"support.type",
"entity.name.type",
"entity.name.class",
"storage.type.cs",
"storage.type.generic.cs",
"storage.type.modifier.cs",
"storage.type.variable.cs",
"storage.type.annotation.java",
"storage.type.generic.java",
"storage.type.java",
"entity.other.inherited-class"
"storage.type.object.array.java",
"storage.type.primitive.array.java",
"storage.type.primitive.java",
"storage.type.token.java",
"storage.type.groovy",
"storage.type.annotation.groovy",
"storage.type.parameters.groovy",
"storage.type.generic.groovy",
"storage.type.object.array.groovy",
"storage.type.primitive.array.groovy",
"storage.type.primitive.groovy"
],
"settings": {
"foreground": "#4EC9B0"
......@@ -51,9 +70,8 @@
{
"name": "Variable and parameter name",
"scope": [
"variable.parameter",
"variable",
"variable.name",
"meta.definition.variable.name",
"support.variable"
],
"settings": {
......@@ -61,8 +79,11 @@
}
},
{
"name": "Object keys, TS gammar specific",
"scope": "object-literal.member.key",
"name": "Object keys, TS grammar specific",
"scope": [
"meta.object-literal.key",
"meta.object-literal.key entity.name.function"
],
"settings": {
"foreground": "#9CDCFE"
}
......@@ -70,21 +91,19 @@
{
"name": "CSS property value",
"scope": [
"support.property-value",
"constant.rgb-value",
"support.property-value.scss",
"constant.rgb-value.scss"
"constant.other.color.rgb-value.css",
"constant.other.rgb-value.css",
"meta.property-value.css support.function",
"meta.property-value.css support",
"constant.numeric.color.rgb-value.scss",
"constant.rgb-value.scss",
"meta.property-value.scss support.function",
"meta.property-value.scss support"
],
"settings": {
"foreground": "#CE9178"
}
},
{
"name": "JSX Tag names, workaround for flattening match with function",
"scope": "entity.name.function.tag",
"settings": {
"foreground": "#569cd6"
}
}
]
}
\ No newline at end of file
{
"name": "Dark Visual Studio",
"settings": [
{
"settings": {
"foreground": "#D4D4D4",
"background": "#1E1E1E"
}
},
{
"scope": "emphasis",
"settings": {
......@@ -45,7 +51,11 @@
}
},
{
"scope": "constant.rgb-value",
"scope": [
"constant.other.color.rgb-value.css",
"constant.numeric.color.rgb-value.scss",
"constant.other.rgb-value.css"
],
"settings": {
"foreground": "#d4d4d4"
}
......@@ -57,7 +67,7 @@
}
},
{
"scope": "entity.name.selector",
"scope": "entity.name.tag.css",
"settings": {
"foreground": "#d7ba7d"
}
......@@ -69,7 +79,19 @@
}
},
{
"scope": "entity.other.attribute-name.css",
"scope": [
"entity.other.attribute-name.class.css",
"entity.other.attribute-name.class.mixin.css",
"entity.other.attribute-name.id.css",
"entity.other.attribute-name.parent-selector.css",
"entity.other.attribute-name.pseudo-class.css",
"entity.other.attribute-name.pseudo-element.css",
"source.css.less entity.other.attribute-name.id",
"entity.other.attribute-name.attribute.scss",
"entity.other.attribute-name.scss"
],
"settings": {
"foreground": "#d7ba7d"
}
......@@ -125,13 +147,13 @@
}
},
{
"scope": "markup.punctuation.quote.beginning",
"scope": "beginning.punctuation.definition.quote.markdown",
"settings": {
"foreground": "#608b4e"
}
},
{
"scope": "markup.punctuation.list.beginning",
"scope": "beginning.punctuation.definition.list.markdown",
"settings": {
"foreground": "#6796e6"
}
......@@ -180,7 +202,7 @@
}
},
{
"scope": "meta.header.diff",
"scope": "meta.diff.header",
"settings": {
"foreground": "#569cd6"
}
......@@ -229,7 +251,10 @@
},
{
"name": "JavaScript string interpolation ${}",
"scope": "string.template-expression",
"scope": [
"punctuation.definition.template-expression.begin.ts",
"punctuation.definition.template-expression.end.ts"
],
"settings": {
"foreground": "#569cd6"
}
......@@ -271,8 +296,10 @@
}
},
{
"name": "coloring of the PHP start and end tag (<?php and ?>)",
"scope": ["punctuation.section.embedded.begin.metatag.php", "punctuation.section.embedded.end.metatag.php"],
"scope": [
"punctuation.section.embedded.metatag.begin.php",
"punctuation.section.embedded.metatag.end.php"
],
"settings": {
"foreground": "#569cd6"
}
......
{
"name": "Dark Visual Studio",
"settings": [
{
"settings": {
"foreground": "#FFFFFF",
"background": "#000000"
}
},
{
"scope": "emphasis",
"settings": {
......@@ -14,7 +20,7 @@
}
},
{
"scope": "header",
"scope": "meta.diff.header",
"settings": {
"foreground": "#000080"
}
......@@ -45,7 +51,11 @@
}
},
{
"scope": "constant.rgb-value",
"scope": [
"constant.other.color.rgb-value.css",
"constant.numeric.color.rgb-value.scss",
"constant.other.rgb-value.css"
],
"settings": {
"foreground": "#d4d4d4"
}
......@@ -57,7 +67,7 @@
}
},
{
"scope": "entity.name.selector",
"scope": "entity.name.tag.css",
"settings": {
"foreground": "#d7ba7d"
}
......@@ -69,7 +79,19 @@
}
},
{
"scope": "entity.other.attribute-name.css",
"scope": [
"entity.other.attribute-name.class.css",
"entity.other.attribute-name.class.mixin.css",
"entity.other.attribute-name.id.css",
"entity.other.attribute-name.parent-selector.css",
"entity.other.attribute-name.pseudo-class.css",
"entity.other.attribute-name.pseudo-element.css",
"source.css.less entity.other.attribute-name.id",
"entity.other.attribute-name.attribute.scss",
"entity.other.attribute-name.scss"
],
"settings": {
"foreground": "#d7ba7d"
}
......@@ -130,7 +152,9 @@
},
{
"name": "brackets of XML/HTML tags",
"scope": "punctuation.definition.tag",
"scope": [
"punctuation.definition.tag"
],
"settings": {
"foreground": "#808080"
}
......@@ -203,7 +227,10 @@
},
{
"name": "JavaScript string interpolation ${}",
"scope": "string.template-expression",
"scope": [
"punctuation.definition.template-expression.begin.ts",
"punctuation.definition.template-expression.end.ts"
],
"settings": {
"foreground": "#569cd6"
}
......@@ -265,7 +292,7 @@
},
{
"name": "coloring of the TS this",
"scope": "variable.this",
"scope": "variable.language.this",
"settings": {
"foreground": "#569cd6"
}
......
......@@ -19,9 +19,28 @@
"support.class",
"support.type",
"entity.name.type",
"entity.name.class",
"storage.type.cs",
"storage.type.generic.cs",
"storage.type.modifier.cs",
"storage.type.variable.cs",
"storage.type.annotation.java",
"storage.type.generic.java",
"storage.type.java",
"entity.other.inherited-class"
"storage.type.object.array.java",
"storage.type.primitive.array.java",
"storage.type.primitive.java",
"storage.type.token.java",
"storage.type.groovy",
"storage.type.annotation.groovy",
"storage.type.parameters.groovy",
"storage.type.generic.groovy",
"storage.type.object.array.groovy",
"storage.type.primitive.array.groovy",
"storage.type.primitive.groovy"
],
"settings": {
"foreground": "#267f99"
......@@ -51,9 +70,8 @@
{
"name": "Variable and parameter name",
"scope": [
"variable.parameter",
"variable",
"variable.name",
"meta.definition.variable.name",
"support.variable"
],
"settings": {
......@@ -61,8 +79,11 @@
}
},
{
"name": "Object keys, TS gammar specific",
"scope": "object-literal.member.key",
"name": "Object keys, TS grammar specific",
"scope": [
"meta.object-literal.key",
"meta.object-literal.key entity.name.function"
],
"settings": {
"foreground": "#001080"
}
......@@ -70,21 +91,19 @@
{
"name": "CSS property value",
"scope": [
"support.property-value",
"constant.rgb-value",
"support.property-value.scss",
"constant.rgb-value.scss"
"constant.other.color.rgb-value.css",
"constant.other.rgb-value.css",
"meta.property-value.css support.function",
"meta.property-value.css support",
"constant.numeric.color.rgb-value.scss",
"constant.rgb-value.scss",
"meta.property-value.scss support.function",
"meta.property-value.scss support"
],
"settings": {
"foreground": "#0451a5"
}
},
{
"name": "JSX Tag names, workaround for flattening match with function",
"scope": "entity.name.function.tag",
"settings": {
"foreground": "#800000"
}
}
]
}
\ No newline at end of file
......@@ -14,7 +14,7 @@
}
},
{
"scope": "header",
"scope": "meta.diff.header",
"settings": {
"foreground": "#000080"
}
......@@ -46,7 +46,11 @@
}
},
{
"scope": "constant.rgb-value",
"scope": [
"constant.other.color.rgb-value.css",
"constant.numeric.color.rgb-value.scss",
"constant.other.rgb-value.css"
],
"settings": {
"foreground": "#0451a5"
}
......@@ -71,7 +75,19 @@
}
},
{
"scope": ["entity.other.attribute-name.css", "entity.other.attribute-name.scss"],
"scope": [
"entity.other.attribute-name.class.css",
"entity.other.attribute-name.class.mixin.css",
"entity.other.attribute-name.id.css",
"entity.other.attribute-name.parent-selector.css",
"entity.other.attribute-name.pseudo-class.css",
"entity.other.attribute-name.pseudo-element.css",
"source.css.less entity.other.attribute-name.id",
"entity.other.attribute-name.attribute.scss",
"entity.other.attribute-name.scss"
],
"settings": {
"foreground": "#800000"
}
......@@ -128,7 +144,10 @@
}
},
{
"scope": ["markup.punctuation.quote.beginning", "markup.punctuation.list.beginning"],
"scope": [
"beginning.punctuation.definition.quote.markdown",
"beginning.punctuation.definition.list.markdown"
],
"settings": {
"foreground": "#0451a5"
}
......@@ -201,7 +220,28 @@
}
},
{
"scope": ["string.xml", "string.jade", "string.yaml", "string.html"],
"scope": [
"string.comment.buffered.block.jade",
"string.quoted.jade",
"string.interpolated.jade",
"string.unquoted.plain.in.yaml",
"string.unquoted.plain.out.yaml",
"string.unquoted.block.yaml",
"string.quoted.single.yaml",
"string.quoted.double.xml",
"string.quoted.single.xml",
"string.unquoted.cdata.xml",
"string.quoted.double.html",
"string.quoted.single.html",
"string.unquoted.html",
"string.quoted.single.handlebars",
"string.quoted.double.handlebars"
],
"settings": {
"foreground": "#0000ff"
}
......@@ -214,19 +254,32 @@
},
{
"name": "JavaScript string interpolation ${}",
"scope": "string.template-expression",
"scope": [
"punctuation.definition.template-expression.begin.ts",
"punctuation.definition.template-expression.end.ts"
],
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": "support.property-value",
"scope": [
"support.property-value",
"meta.property-value.css support",
"meta.property-value.scss support"
],
"settings": {
"foreground": "#0451a5"
}
},
{
"scope": ["support.type.property-name.css", "support.type.property-name.less", "support.type.property-name.scss"],
"scope": [
"support.type.property-name.css",
"support.type.property-name.variable.css",
"support.type.property-name.media.css",
"support.type.property-name.less",
"support.type.property-name.scss"
],
"settings": {
"foreground": "#ff0000"
}
......@@ -268,8 +321,10 @@
}
},
{
"name": "coloring of the PHP start and end tag (<?php and ?>)",
"scope": ["punctuation.section.embedded.begin.metatag.php", "punctuation.section.embedded.end.metatag.php"],
"scope": [
"punctuation.section.embedded.metatag.begin.php",
"punctuation.section.embedded.metatag.end.php"
],
"settings": {
"foreground": "#800000"
}
......
......@@ -15,10 +15,11 @@ import { ILineTokens, ITokenizationSupport, TokenizationRegistry } from 'vs/edit
import { TMState } from 'vs/editor/node/textMate/TMState';
import { RawLineTokens } from 'vs/editor/common/modes/supports';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IGrammar, Registry, StackElement, IToken } from 'vscode-textmate';
import { IGrammar, Registry, StackElement, IToken, IEmbeddedLanguagesMap as IEmbeddedLanguagesMap2 } from 'vscode-textmate';
import { ModeTransition } from 'vs/editor/common/core/modeTransition';
import { Token } from 'vs/editor/common/core/token';
import { languagesExtPoint } from 'vs/editor/common/services/modeServiceImpl';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
export interface IEmbeddedLanguagesMap {
[scopeName: string]: string;
......@@ -110,9 +111,9 @@ export class TMLanguageRegistration {
readonly scopeName: string;
readonly grammarFilePath: string;
readonly embeddedLanguages: IEmbeddedLanguagesMap;
private readonly _registry: TMScopeRegistry;
private readonly _embeddedLanguages: IEmbeddedLanguagesMap;
private readonly _embeddedLanguagesRegex: RegExp;
constructor(registry: TMScopeRegistry, scopeName: string, grammarFilePath: string, embeddedLanguages: IEmbeddedLanguagesMap) {
......@@ -121,7 +122,7 @@ export class TMLanguageRegistration {
this.grammarFilePath = grammarFilePath;
// embeddedLanguages handling
this._embeddedLanguages = Object.create(null);
this.embeddedLanguages = Object.create(null);
if (embeddedLanguages) {
// If embeddedLanguages are configured, fill in `this._embeddedLanguages`
......@@ -133,12 +134,12 @@ export class TMLanguageRegistration {
// never hurts to be too careful
continue;
}
this._embeddedLanguages[scope] = language;
this.embeddedLanguages[scope] = language;
}
}
// create the regex
let escapedScopes = Object.keys(this._embeddedLanguages).map((scopeName) => strings.escapeRegExpCharacters(scopeName));
let escapedScopes = Object.keys(this.embeddedLanguages).map((scopeName) => strings.escapeRegExpCharacters(scopeName));
if (escapedScopes.length === 0) {
// no scopes registered
this._embeddedLanguagesRegex = null;
......@@ -167,7 +168,7 @@ export class TMLanguageRegistration {
return null;
}
let language = this._embeddedLanguages[m[1]] || null;
let language = this.embeddedLanguages[m[1]] || null;
if (!language) {
return null;
}
......@@ -177,18 +178,31 @@ export class TMLanguageRegistration {
}
}
function createStyleSheet(): HTMLStyleElement {
let style = document.createElement('style');
style.type = 'text/css';
style.media = 'screen';
document.getElementsByTagName('head')[0].appendChild(style);
return style;
}
export class MainProcessTextMateSyntax {
private _grammarRegistry: Registry;
private _modeService: IModeService;
private _themeService: IThemeService;
private _scopeRegistry: TMScopeRegistry;
private _injections: { [scopeName: string]: string[]; };
private _styleElement: HTMLStyleElement;
public onDidEncounterLanguage: Event<string>;
constructor(
@IModeService modeService: IModeService
@IModeService modeService: IModeService,
@IThemeService themeService: IThemeService
) {
this._styleElement = createStyleSheet();
this._modeService = modeService;
this._themeService = themeService;
this._scopeRegistry = new TMScopeRegistry();
this.onDidEncounterLanguage = this._scopeRegistry.onDidEncounterLanguage;
this._injections = {};
......@@ -201,6 +215,8 @@ export class MainProcessTextMateSyntax {
return this._injections[scopeName];
}
});
this._updateTheme();
this._themeService.onDidColorThemeChange((e) => this._updateTheme());
grammarsExtPoint.setHandler((extensions) => {
for (let i = 0; i < extensions.length; i++) {
......@@ -212,6 +228,26 @@ export class MainProcessTextMateSyntax {
});
}
private static _generateCSS(colorMap: string[]): string {
let rules: string[] = [];
for (let i = 1, len = colorMap.length; i < len; i++) {
let color = colorMap[i];
rules[i] = `.mtk${i} { color: ${color.substr(0, 7)}; }`;
}
rules.push('.mtki { font-style: italic; }');
rules.push('.mtkb { font-weight: bold; }');
rules.push('.mtku { text-decoration: underline; }');
return rules.join('\n');
}
private _updateTheme(): void {
this._grammarRegistry.setTheme(this._themeService.getColorThemeDocument());
let colorMap = this._grammarRegistry.getColorMap();
let cssRules = MainProcessTextMateSyntax._generateCSS(colorMap);
this._styleElement.innerHTML = cssRules;
TokenizationRegistry.setColorMap(colorMap);
}
private _handleGrammarExtensionPointUser(extensionFolderPath: string, syntax: ITMSyntaxExtensionPoint, collector: ExtensionMessageCollector): void {
if (syntax.language && ((typeof syntax.language !== 'string') || !this._modeService.isRegisteredMode(syntax.language))) {
collector.error(nls.localize('invalid.language', "Unknown language in `contributes.{0}.language`. Provided value: {1}", grammarsExtPoint.name, String(syntax.language)));
......@@ -264,8 +300,26 @@ export class MainProcessTextMateSyntax {
}
}
private _resolveEmbeddedLanguages(embeddedLanguages: IEmbeddedLanguagesMap): IEmbeddedLanguagesMap2 {
let scopes = Object.keys(embeddedLanguages);
let result: IEmbeddedLanguagesMap2 = Object.create(null);
for (let i = 0, len = scopes.length; i < len; i++) {
let scope = scopes[i];
let language = embeddedLanguages[scope];
let languageIdentifier = this._modeService.getLanguageIdentifier(language);
if (languageIdentifier) {
result[scope] = languageIdentifier.iid;
}
}
return result;
}
private registerDefinition(modeId: string, scopeName: string): void {
this._grammarRegistry.loadGrammar(scopeName, (err, grammar) => {
let languageRegistration = this._scopeRegistry.getLanguageRegistration(scopeName);
let embeddedLanguages = this._resolveEmbeddedLanguages(languageRegistration.embeddedLanguages);
let languageId = this._modeService.getLanguageIdentifier(modeId).iid;
this._grammarRegistry.loadGrammarWithEmbeddedLanguages(scopeName, languageId, embeddedLanguages, (err, grammar) => {
if (err) {
onUnexpectedError(err);
return;
......@@ -282,9 +336,25 @@ function createTokenizationSupport(languageRegistration: TMLanguageRegistration,
return {
getInitialState: () => new TMState(null),
tokenize: (line, state, offsetDelta) => tokenizer.tokenize(line, <TMState>state, offsetDelta),
tokenize3: () => {
// TODO@tokenization
throw new Error('TODO@tokenization');
tokenize3: (line: string, state: TMState, offsetDelta: number) => {
if (offsetDelta !== 0) {
throw new Error('Unexpected: offsetDelta should be 0.');
}
let textMateResult = grammar.tokenizeLine2(line, state.ruleStack);
let endState: TMState;
// try to save an object if possible
if (state.ruleStack !== null && textMateResult.ruleStack.equals(state.ruleStack)) {
endState = state;
} else {
endState = new TMState(textMateResult.ruleStack);
}
return {
tokens: textMateResult.tokens,
endState: endState
};
}
};
}
......
......@@ -18,6 +18,7 @@ export interface IThemeService {
_serviceBrand: any;
setColorTheme(themeId: string, broadcastToAllWindows: boolean): TPromise<boolean>;
getColorTheme(): string;
getColorThemeDocument(): IThemeDocument;
getColorThemes(): TPromise<IThemeData[]>;
onDidColorThemeChange: Event<string>;
......
......@@ -103,6 +103,7 @@ let iconThemeExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensio
interface IInternalThemeData extends IThemeData {
styleSheetContent?: string;
document?: IThemeDocument;
extensionId: string;
extensionPublisher: string;
extensionName: string;
......@@ -155,6 +156,7 @@ export class ThemeService implements IThemeService {
private knownColorThemes: IInternalThemeData[];
private currentColorTheme: string;
private currentColorThemeDocument: IThemeDocument;
private container: HTMLElement;
private onColorThemeChange: Emitter<string>;
......@@ -168,6 +170,7 @@ export class ThemeService implements IThemeService {
@ITelemetryService private telemetryService: ITelemetryService) {
this.knownColorThemes = [];
this.currentColorThemeDocument = null;
this.onColorThemeChange = new Emitter<string>();
this.knownIconThemes = [];
this.currentIconTheme = '';
......@@ -258,6 +261,7 @@ export class ThemeService implements IThemeService {
} else {
this.sendTelemetry(newTheme);
}
this.currentColorThemeDocument = newTheme.document;
this.onColorThemeChange.fire(newThemeId);
};
......@@ -268,6 +272,10 @@ export class ThemeService implements IThemeService {
return this.currentColorTheme || this.storageService.get(COLOR_THEME_PREF, StorageScope.GLOBAL, DEFAULT_THEME_ID);
}
public getColorThemeDocument(): IThemeDocument {
return this.currentColorThemeDocument;
}
private findThemeData(themeId: string, defaultId?: string): TPromise<IInternalThemeData> {
return this.getColorThemes().then(allThemes => {
let themes = allThemes.filter(t => t.id === themeId);
......@@ -641,6 +649,7 @@ function applyTheme(theme: IInternalThemeData, onApply: (theme: IInternalThemeDa
return TPromise.as(true);
}
return _loadThemeDocument(theme.path).then(themeDocument => {
theme.document = themeDocument;
let styleSheetContent = _processThemeObject(theme.id, themeDocument);
theme.styleSheetContent = styleSheetContent;
_applyRules(styleSheetContent, colorThemeRulesClassName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册