mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 09:38:26 -05:00
Merge VS Code 1.23.1 (#1520)
This commit is contained in:
@@ -12,11 +12,16 @@ export interface IEmbeddedLanguagesMap {
|
||||
[scopeName: string]: string;
|
||||
}
|
||||
|
||||
export interface TokenTypesContribution {
|
||||
[scopeName: string]: string;
|
||||
}
|
||||
|
||||
export interface ITMSyntaxExtensionPoint {
|
||||
language: string;
|
||||
scopeName: string;
|
||||
path: string;
|
||||
embeddedLanguages: IEmbeddedLanguagesMap;
|
||||
tokenTypes: TokenTypesContribution;
|
||||
injectTo: string[];
|
||||
}
|
||||
|
||||
@@ -44,6 +49,13 @@ export const grammarsExtPoint: IExtensionPoint<ITMSyntaxExtensionPoint[]> = Exte
|
||||
description: nls.localize('vscode.extension.contributes.grammars.embeddedLanguages', 'A map of scope name to language id if this grammar contains embedded languages.'),
|
||||
type: 'object'
|
||||
},
|
||||
tokenTypes: {
|
||||
description: nls.localize('vscode.extension.contributes.grammars.tokenTypes', 'A map of scope name to token types.'),
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
enum: ['string', 'comment', 'other']
|
||||
}
|
||||
},
|
||||
injectTo: {
|
||||
description: nls.localize('vscode.extension.contributes.grammars.injectTo', 'List of language scope names to which this grammar is injected to.'),
|
||||
type: 'array',
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
import * as nls from 'vs/nls';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import * as types from 'vs/base/common/types';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { join, normalize } from 'path';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { ExtensionMessageCollector } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
||||
import { ITokenizationSupport, TokenizationRegistry, IState, LanguageId, TokenMetadata } from 'vs/editor/common/modes';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { StackElement, IGrammar, Registry, IEmbeddedLanguagesMap as IEmbeddedLanguagesMap2 } from 'vscode-textmate';
|
||||
import { StackElement, IGrammar, Registry, IEmbeddedLanguagesMap as IEmbeddedLanguagesMap2, ITokenTypeMap, StandardTokenType } from 'vscode-textmate';
|
||||
import { IWorkbenchThemeService, ITokenColorizationRule } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
import { ITextMateService } from 'vs/workbench/services/textMate/electron-browser/textMateService';
|
||||
import { grammarsExtPoint, IEmbeddedLanguagesMap, ITMSyntaxExtensionPoint } from 'vs/workbench/services/textMate/electron-browser/TMGrammars';
|
||||
import { grammarsExtPoint, IEmbeddedLanguagesMap, ITMSyntaxExtensionPoint, TokenTypesContribution } from 'vs/workbench/services/textMate/electron-browser/TMGrammars';
|
||||
import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
|
||||
import { nullTokenize2 } from 'vs/editor/common/modes/nullMode';
|
||||
import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization';
|
||||
@@ -28,15 +28,15 @@ export class TMScopeRegistry {
|
||||
private _scopeNameToLanguageRegistration: { [scopeName: string]: TMLanguageRegistration; };
|
||||
private _encounteredLanguages: boolean[];
|
||||
|
||||
private _onDidEncounterLanguage: Emitter<LanguageId> = new Emitter<LanguageId>();
|
||||
public onDidEncounterLanguage: Event<LanguageId> = this._onDidEncounterLanguage.event;
|
||||
private readonly _onDidEncounterLanguage: Emitter<LanguageId> = new Emitter<LanguageId>();
|
||||
public readonly onDidEncounterLanguage: Event<LanguageId> = this._onDidEncounterLanguage.event;
|
||||
|
||||
constructor() {
|
||||
this._scopeNameToLanguageRegistration = Object.create(null);
|
||||
this._encounteredLanguages = [];
|
||||
}
|
||||
|
||||
public register(scopeName: string, filePath: string, embeddedLanguages?: IEmbeddedLanguagesMap): void {
|
||||
public register(scopeName: string, filePath: string, embeddedLanguages?: IEmbeddedLanguagesMap, tokenTypes?: TokenTypesContribution): void {
|
||||
if (this._scopeNameToLanguageRegistration[scopeName]) {
|
||||
const existingRegistration = this._scopeNameToLanguageRegistration[scopeName];
|
||||
if (existingRegistration.grammarFilePath !== filePath) {
|
||||
@@ -47,7 +47,7 @@ export class TMScopeRegistry {
|
||||
);
|
||||
}
|
||||
}
|
||||
this._scopeNameToLanguageRegistration[scopeName] = new TMLanguageRegistration(scopeName, filePath, embeddedLanguages);
|
||||
this._scopeNameToLanguageRegistration[scopeName] = new TMLanguageRegistration(scopeName, filePath, embeddedLanguages, tokenTypes);
|
||||
}
|
||||
|
||||
public getLanguageRegistration(scopeName: string): TMLanguageRegistration {
|
||||
@@ -76,8 +76,9 @@ export class TMLanguageRegistration {
|
||||
readonly scopeName: string;
|
||||
readonly grammarFilePath: string;
|
||||
readonly embeddedLanguages: IEmbeddedLanguagesMap;
|
||||
readonly tokenTypes: ITokenTypeMap;
|
||||
|
||||
constructor(scopeName: string, grammarFilePath: string, embeddedLanguages: IEmbeddedLanguagesMap) {
|
||||
constructor(scopeName: string, grammarFilePath: string, embeddedLanguages: IEmbeddedLanguagesMap, tokenTypes: TokenTypesContribution | undefined) {
|
||||
this.scopeName = scopeName;
|
||||
this.grammarFilePath = grammarFilePath;
|
||||
|
||||
@@ -97,6 +98,27 @@ export class TMLanguageRegistration {
|
||||
this.embeddedLanguages[scope] = language;
|
||||
}
|
||||
}
|
||||
|
||||
this.tokenTypes = Object.create(null);
|
||||
if (tokenTypes) {
|
||||
// If tokenTypes is configured, fill in `this._tokenTypes`
|
||||
const scopes = Object.keys(tokenTypes);
|
||||
for (let i = 0, len = scopes.length; i < len; i++) {
|
||||
const scope = scopes[i];
|
||||
const tokenType = tokenTypes[scope];
|
||||
switch (tokenType) {
|
||||
case 'string':
|
||||
this.tokenTypes[scope] = StandardTokenType.String;
|
||||
break;
|
||||
case 'other':
|
||||
this.tokenTypes[scope] = StandardTokenType.Other;
|
||||
break;
|
||||
case 'comment':
|
||||
this.tokenTypes[scope] = StandardTokenType.Comment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +144,7 @@ export class TextMateService implements ITextMateService {
|
||||
|
||||
private _currentTokenColors: ITokenColorizationRule[];
|
||||
|
||||
public onDidEncounterLanguage: Event<LanguageId>;
|
||||
public readonly onDidEncounterLanguage: Event<LanguageId>;
|
||||
|
||||
constructor(
|
||||
@IModeService modeService: IModeService,
|
||||
@@ -262,13 +284,18 @@ export class TextMateService implements ITextMateService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (syntax.tokenTypes && !types.isObject(syntax.tokenTypes)) {
|
||||
collector.error(nls.localize('invalid.tokenTypes', "Invalid value in `contributes.{0}.tokenTypes`. Must be an object map from scope name to token type. Provided value: {1}", grammarsExtPoint.name, JSON.stringify(syntax.tokenTypes)));
|
||||
return;
|
||||
}
|
||||
|
||||
let normalizedAbsolutePath = normalize(join(extensionFolderPath, syntax.path));
|
||||
|
||||
if (normalizedAbsolutePath.indexOf(extensionFolderPath) !== 0) {
|
||||
collector.warn(nls.localize('invalid.path.1', "Expected `contributes.{0}.path` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.", grammarsExtPoint.name, normalizedAbsolutePath, extensionFolderPath));
|
||||
}
|
||||
|
||||
this._scopeRegistry.register(syntax.scopeName, normalizedAbsolutePath, syntax.embeddedLanguages);
|
||||
this._scopeRegistry.register(syntax.scopeName, normalizedAbsolutePath, syntax.embeddedLanguages, syntax.tokenTypes);
|
||||
|
||||
if (syntax.injectTo) {
|
||||
for (let injectScope of syntax.injectTo) {
|
||||
@@ -336,7 +363,7 @@ export class TextMateService implements ITextMateService {
|
||||
return this._getOrCreateGrammarRegistry().then((_res) => {
|
||||
const [grammarRegistry, initialState] = _res;
|
||||
return new TPromise<ICreateGrammarResult>((c, e, p) => {
|
||||
grammarRegistry.loadGrammarWithEmbeddedLanguages(scopeName, languageId, embeddedLanguages, (err, grammar) => {
|
||||
grammarRegistry.loadGrammarWithConfiguration(scopeName, languageId, { embeddedLanguages, tokenTypes: languageRegistration.tokenTypes }, (err, grammar) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import Event from 'vs/base/common/event';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IGrammar } from 'vscode-textmate';
|
||||
import { LanguageId } from 'vs/editor/common/modes';
|
||||
|
||||
Reference in New Issue
Block a user