Skip to content

Commit

Permalink
Fix plaintext grammar parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
zm-cttae committed Nov 7, 2023
1 parent c01d6e5 commit cd2cf50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/services/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -27,7 +27,9 @@ export class ResolverService implements vscodeTextmate.RegistryOptions {
public async loadGrammar(scopeName: string): Promise<vscodeTextmate.IRawGrammar | null> {
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;
Expand Down
10 changes: 5 additions & 5 deletions src/util/contributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ export type ExtensionManifestContributionKey = 'textmate-languageservice-contrib

export type ExtensionData = Record<string, vscode.Extension<unknown> | 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
Expand Down

0 comments on commit cd2cf50

Please sign in to comment.