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