diff --git a/src/vs/workbench/services/textMate/browser/abstractTextMateService.ts b/src/vs/workbench/services/textMate/browser/abstractTextMateService.ts index fd04e1fd157..57aa1cd2c21 100644 --- a/src/vs/workbench/services/textMate/browser/abstractTextMateService.ts +++ b/src/vs/workbench/services/textMate/browser/abstractTextMateService.ts @@ -26,7 +26,7 @@ import type { IGrammar, StackElement, IOnigLib, IRawTheme } from 'vscode-textmat import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IValidGrammarDefinition, IValidEmbeddedLanguagesMap, IValidTokenTypeMap } from 'vs/workbench/services/textMate/common/TMScopeRegistry'; -import { TMGrammarFactory } from 'vs/workbench/services/textMate/common/TMGrammarFactory'; +import { missingTMGrammarErrorMessage, TMGrammarFactory } from 'vs/workbench/services/textMate/common/TMGrammarFactory'; import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader'; import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress'; import { TMTokenization } from 'vs/workbench/services/textMate/common/TMTokenization'; @@ -266,6 +266,10 @@ export abstract class AbstractTextMateService extends Disposable implements ITex }); return new TMTokenizationSupportWithLineLimit(languageId, encodedLanguageId, tokenization, this._configurationService); } catch (err) { + if (err.message && err.message === missingTMGrammarErrorMessage) { + // Don't log this error message + return null; + } onUnexpectedError(err); return null; } diff --git a/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts b/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts index 5d5ae7a8c8e..2bb9be17ad0 100644 --- a/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts +++ b/src/vs/workbench/services/textMate/common/TMGrammarFactory.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as nls from 'vs/nls'; import { URI } from 'vs/base/common/uri'; import type { IGrammar, Registry, StackElement, IRawTheme, IOnigLib } from 'vscode-textmate'; import { Disposable } from 'vs/base/common/lifecycle'; @@ -22,6 +21,8 @@ export interface ICreateGrammarResult { containsEmbeddedLanguages: boolean; } +export const missingTMGrammarErrorMessage = 'No TM Grammar registered for this language.'; + export class TMGrammarFactory extends Disposable { private readonly _host: ITMGrammarFactoryHost; @@ -113,13 +114,13 @@ export class TMGrammarFactory extends Disposable { const scopeName = this._languageToScope.get(languageId); if (typeof scopeName !== 'string') { // No TM grammar defined - return Promise.reject(new Error(nls.localize('no-tm-grammar', "No TM Grammar registered for this language."))); + throw new Error(missingTMGrammarErrorMessage); } const grammarDefinition = this._scopeRegistry.getGrammarDefinition(scopeName); if (!grammarDefinition) { // No TM grammar defined - return Promise.reject(new Error(nls.localize('no-tm-grammar', "No TM Grammar registered for this language."))); + throw new Error(missingTMGrammarErrorMessage); } let embeddedLanguages = grammarDefinition.embeddedLanguages; @@ -134,7 +135,17 @@ export class TMGrammarFactory extends Disposable { const containsEmbeddedLanguages = (Object.keys(embeddedLanguages).length > 0); - const grammar = await this._grammarRegistry.loadGrammarWithConfiguration(scopeName, encodedLanguageId, { embeddedLanguages, tokenTypes: grammarDefinition.tokenTypes }); + let grammar: IGrammar | null; + + try { + grammar = await this._grammarRegistry.loadGrammarWithConfiguration(scopeName, encodedLanguageId, { embeddedLanguages, tokenTypes: grammarDefinition.tokenTypes }); + } catch (err) { + if (err.message && err.message.startsWith('No grammar provided for')) { + // No TM grammar defined + throw new Error(missingTMGrammarErrorMessage); + } + throw err; + } return { languageId: languageId,