Path: blob/main/src/vs/editor/common/services/treeSitter/treeSitterLibraryService.ts
5237 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type { Language, Parser, Query } from '@vscode/tree-sitter-wasm';6import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';7import { IReader } from '../../../../base/common/observable.js';89export const ITreeSitterLibraryService = createDecorator<ITreeSitterLibraryService>('treeSitterLibraryService');1011export interface ITreeSitterLibraryService {12readonly _serviceBrand: undefined;1314/**15* Gets the tree sitter Parser constructor.16*/17getParserClass(): Promise<typeof Parser>;1819/**20* Checks whether a language is supported and available based setting enablement.21* @param languageId The language identifier to check.22* @param reader Optional observable reader.23*/24supportsLanguage(languageId: string, reader: IReader | undefined): boolean;2526/**27* Gets the tree sitter Language object synchronously.28* @param languageId The language identifier to retrieve.29* @param ignoreSupportsCheck Whether to ignore the supportsLanguage check.30* @param reader Optional observable reader.31*/32getLanguage(languageId: string, ignoreSupportsCheck: boolean, reader: IReader | undefined): Language | undefined;3334/**35* Gets the language as a promise, as opposed to via observables. This ignores the automatic36* supportsLanguage check.37*38* Warning: This approach is generally not recommended as it's not reactive, but it's the only39* way to catch and handle import errors when the grammar fails to load.40* @param languageId The language identifier to retrieve.41*/42getLanguagePromise(languageId: string): Promise<Language | undefined>;4344/**45* Gets the injection queries for a language. A return value of `null`46* indicates that there are no highlights queries for this language.47* @param languageId The language identifier to retrieve queries for.48* @param reader Optional observable reader.49*/50getInjectionQueries(languageId: string, reader: IReader | undefined): Query | null | undefined;5152/**53* Gets the highlighting queries for a language. A return value of `null`54* indicates that there are no highlights queries for this language.55* @param languageId The language identifier to retrieve queries for.56* @param reader Optional observable reader.57*/58getHighlightingQueries(languageId: string, reader: IReader | undefined): Query | null | undefined;5960/**61* Creates a one-off custom query for a language.62* @param language The Language to create the query for.63* @param querySource The query source string to compile.64*/65createQuery(language: Language, querySource: string): Promise<Query>;66}676869