Adopt latest vscode-textmate (fixes #84401)

This commit is contained in:
Alex Dima
2019-11-21 08:44:26 +01:00
parent 2340d87072
commit 7521ebdeb4
12 changed files with 31 additions and 276 deletions

View File

@@ -174,7 +174,7 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
private readonly _notificationService: INotificationService;
private readonly _model: ITextModel;
private readonly _domNode: HTMLElement;
private readonly _grammar: Promise<IGrammar>;
private readonly _grammar: Promise<IGrammar | null>;
constructor(
editor: IActiveCodeEditor,
@@ -212,7 +212,12 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
dom.clearNode(this._domNode);
this._domNode.appendChild(document.createTextNode(nls.localize('inspectTMScopesWidget.loading', "Loading...")));
this._grammar.then(
(grammar) => this._compute(grammar, position),
(grammar) => {
if (!grammar) {
throw new Error(`Could not find grammar for language!`);
}
this._compute(grammar, position);
},
(err) => {
this._notificationService.warn(err);
setTimeout(() => {

View File

@@ -216,6 +216,9 @@ class Snapper {
public captureSyntaxTokens(fileName: string, content: string): Promise<IToken[]> {
const modeId = this.modeService.getModeIdByFilepathOrFirstLine(URI.file(fileName));
return this.textMateService.createGrammar(modeId!).then((grammar) => {
if (!grammar) {
return [];
}
let lines = content.split(/\r\n|\r|\n/);
let result = this._tokenize(grammar, lines);

View File

@@ -218,6 +218,9 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
return null;
}
const r = await grammarFactory.createGrammar(languageId);
if (!r.grammar) {
return null;
}
const tokenization = new TMTokenization(r.grammar, r.initialState, r.containsEmbeddedLanguages);
tokenization.onDidEncounterLanguage((languageId) => {
if (!this._encounteredLanguages[languageId]) {
@@ -314,7 +317,7 @@ export abstract class AbstractTextMateService extends Disposable implements ITex
return true;
}
public async createGrammar(modeId: string): Promise<IGrammar> {
public async createGrammar(modeId: string): Promise<IGrammar | null> {
const grammarFactory = await this._getOrCreateGrammarFactory();
const { grammar } = await grammarFactory.createGrammar(this._modeService.getLanguageIdentifier(modeId)!.id);
return grammar;

View File

@@ -18,7 +18,7 @@ interface ITMGrammarFactoryHost {
export interface ICreateGrammarResult {
languageId: LanguageId;
grammar: IGrammar;
grammar: IGrammar | null;
initialState: StackElement;
containsEmbeddedLanguages: boolean;
}

View File

@@ -14,7 +14,7 @@ export interface ITextMateService {
onDidEncounterLanguage: Event<LanguageId>;
createGrammar(modeId: string): Promise<IGrammar>;
createGrammar(modeId: string): Promise<IGrammar | null>;
}
// -------------- Types "liberated" from vscode-textmate due to usage in /common/