Skip to content

Commit

Permalink
Patch ctor for plaintext service generator
Browse files Browse the repository at this point in the history
  • Loading branch information
zm-cttae committed Oct 15, 2023
1 parent f21bbff commit e3ed98d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class TextmateLanguageService {
const extension = context?.extension || resolver.getExtensionFromLanguageId(languageId);
const manifest = extension?.packageJSON as ExtensionManifest | undefined;

if (!manifest) {
if (languageId !== 'plaintext' && !manifest) {
throw new Error('could not find extension contributing language ID "' + languageId + '"');
}

Expand All @@ -78,14 +78,19 @@ export default class TextmateLanguageService {
const grammarData = resolver.getGrammarDefinitionFromLanguageId(languageId);
this[_private].grammarPromise = registry.loadGrammar(grammarData.scopeName);

const paths = manifest['textmate-languageservices'] || {};
const filepath = paths[languageId] || './textmate-configuration.json';

const uri = vscode.Uri.joinPath(extension.extensionUri, filepath);
const languageData = resolver.getLanguageDefinitionFromId(languageId);
this[_private].configPromise = loadJsonFile<ConfigJson>(uri, '{}')
.then(json => new ConfigData(json, languageData))
.catch(() => new ConfigData({}, languageData));

if (languageId !== 'plaintext') {
const paths = manifest['textmate-languageservices'] || {};
const filepath = paths[languageId] || './textmate-configuration.json';

const uri = vscode.Uri.joinPath(extension.extensionUri, filepath);
this[_private].configPromise = loadJsonFile<ConfigJson>(uri, '{}')
.then(json => new ConfigData(json, languageData))
.catch(() => new ConfigData({}, languageData));
} else {
this[_private].configPromise = Promise.resolve(new ConfigData({}, languageData));
}
}

public async initTokenService(): Promise<TokenizerService> {
Expand Down

0 comments on commit e3ed98d

Please sign in to comment.