mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 14:01:38 +01:00
Adopt latest vscode-textmate (fixes #84401)
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -18,7 +18,7 @@ interface ITMGrammarFactoryHost {
|
||||
|
||||
export interface ICreateGrammarResult {
|
||||
languageId: LanguageId;
|
||||
grammar: IGrammar;
|
||||
grammar: IGrammar | null;
|
||||
initialState: StackElement;
|
||||
containsEmbeddedLanguages: boolean;
|
||||
}
|
||||
|
||||
@@ -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/
|
||||
|
||||
Reference in New Issue
Block a user