From cd2cf504c49156c4437b324dc84630a187c8b583 Mon Sep 17 00:00:00 2001 From: zm-cttae <114668551+zm-cttae@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:50:01 +0100 Subject: [PATCH] Fix plaintext grammar parsing error Refs: http://microsoft/vscode-textmate#214 --- src/services/resolver.ts | 6 ++++-- src/util/contributes.ts | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/services/resolver.ts b/src/services/resolver.ts index 795ad45..2ab9f6d 100644 --- a/src/services/resolver.ts +++ b/src/services/resolver.ts @@ -7,7 +7,7 @@ import * as vscode from 'vscode'; import * as vscodeTextmate from 'vscode-textmate'; import { readFileText, loadMessageBundle } from '../util/loader'; -import { ContributorData } from '../util/contributes'; +import { ContributorData, plaintextGrammarDefinition } from '../util/contributes'; import type { GrammarLanguageDefinition, LanguageDefinition } from '../util/contributes'; const localize = loadMessageBundle(); @@ -27,7 +27,9 @@ export class ResolverService implements vscodeTextmate.RegistryOptions { public async loadGrammar(scopeName: string): Promise { if (scopeName === 'text') { const text = JSON.stringify(plainTextGrammar); - return vscodeTextmate.parseRawGrammar(text); + const appRoot = vscode.Uri.file(vscode.env.appRoot); + const jsonPath = vscode.Uri.joinPath(appRoot, plaintextGrammarDefinition.path).path + return vscodeTextmate.parseRawGrammar(text, jsonPath); } const mapping = this._contributes.sources; diff --git a/src/util/contributes.ts b/src/util/contributes.ts index c5469e8..306680e 100644 --- a/src/util/contributes.ts +++ b/src/util/contributes.ts @@ -69,22 +69,22 @@ export type ExtensionManifestContributionKey = 'textmate-languageservice-contrib export type ExtensionData = Record | undefined>; -const plaintextLanguage: LanguageDefinition = { +export const plaintextLanguageDefinition: LanguageDefinition = { id: 'plaintext', extensions: ['.txt'], aliases: [localize('plainText.alias', 'Plain Text'), 'text'], mimetypes: ['text/plain'] }; -const plaintextGrammar = { +export const plaintextGrammarDefinition = { language: 'plaintext', - path: 'vscode://blank', + path: './out/vs/editor/common/languages/plaintext.tmLanguage.json', scopeName: 'text' }; function getAllContributes() { - const languages: LanguageData = [plaintextLanguage]; - const grammars: GrammarData = [plaintextGrammar]; + const languages: LanguageData = [plaintextLanguageDefinition]; + const grammars: GrammarData = [plaintextGrammarDefinition]; const sources = { grammars: {} as ExtensionData, languages: {} as ExtensionData