Skip to content

Commit

Permalink
Fixes #8173: Adopt vscode-textmate with fast plist parser, make fast …
Browse files Browse the repository at this point in the history
…plist parser disableable via editor.useExperimentalParser
  • Loading branch information
alexdima committed Jun 30, 2016
1 parent 97d27d0 commit 170db15
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"sax": "1.1.2",
"semver": "4.3.6",
"vscode-debugprotocol": "1.10.0",
"vscode-textmate": "1.1.0",
"vscode-textmate": "1.2.0",
"winreg": "1.2.0",
"xterm": "git+https://github.com/sourcelair/xterm.js.git#39c4356",
"yauzl": "2.3.1"
Expand Down
18 changes: 16 additions & 2 deletions src/vs/editor/node/textMate/TMSyntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {LineTokens, Token} from 'vs/editor/common/modes/supports';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IGrammar, Registry} from 'vscode-textmate';
import {ModeTransition} from 'vs/editor/common/core/modeTransition';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';

export interface ITMSyntaxExtensionPoint {
language: string;
Expand Down Expand Up @@ -54,27 +55,40 @@ let grammarsExtPoint = ExtensionsRegistry.registerExtensionPoint<ITMSyntaxExtens
}
});

interface MyEditorConfig {
useExperimentalParser: boolean;
}

export class MainProcessTextMateSyntax {
private _grammarRegistry: Registry;
private _modeService: IModeService;
private _scopeNameToFilePath: { [scopeName:string]: string; };
private _injections: { [scopeName:string]: string[]; };

constructor(
@IModeService modeService: IModeService
@IModeService modeService: IModeService,
@IConfigurationService configurationService: IConfigurationService
) {
this._modeService = modeService;
this._scopeNameToFilePath = {};
this._injections = {};

let editorConfig = configurationService.getConfiguration<MyEditorConfig>('editor');
let useExperimentalParser = true;
if (typeof editorConfig.useExperimentalParser !== 'undefined') {
if (Boolean(editorConfig.useExperimentalParser) === false) {
useExperimentalParser = false;
}
}

this._grammarRegistry = new Registry({
getFilePath: (scopeName:string) => {
return this._scopeNameToFilePath[scopeName];
},
getInjections: (scopeName:string) => {
return this._injections[scopeName];
}
});
}, useExperimentalParser);

grammarsExtPoint.setHandler((extensions) => {
for (let i = 0; i < extensions.length; i++) {
Expand Down
10 changes: 6 additions & 4 deletions src/vs/editor/node/textMate/vscode-textmate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ declare module "vscode-textmate" {
*/
export interface IGrammarLocator {
getFilePath(scopeName:string): string;
getInjections(scopeName:string): string[];
getInjections?(scopeName:string): string[];
}

/**
* The registry that will hold all grammars.
*/
export class Registry {

public static readGrammarInfo(path:string, callback:(err:any, grammarInfo:IGrammarInfo)=>void): void;
public static readGrammarInfoSync(path:string): IGrammarInfo;
public static readGrammarInfo(path:string, callback:(err:any, grammarInfo:IGrammarInfo)=>void, useExperimentalParser?:boolean): void;
public static readGrammarInfoSync(path:string, useExperimentalParser?:boolean): IGrammarInfo;

constructor(locator?:IGrammarLocator);
constructor(locator?:IGrammarLocator, useExperimentalParser?:boolean);

/**
* Load the grammar for `scopeName` and all referenced included grammars asynchronously.
Expand Down Expand Up @@ -77,11 +77,13 @@ export interface StackElement {
ruleId: number;
enterPos: number;
endRule: string;
whileRule: string;
scopeName: string;
contentName: string;

clone(): StackElement;
}



}

0 comments on commit 170db15

Please sign in to comment.