Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/languages/language.ts
3294 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 { Event } from '../../../base/common/event.js';
7
import { IDisposable } from '../../../base/common/lifecycle.js';
8
import { URI } from '../../../base/common/uri.js';
9
import { ILanguageIdCodec } from '../languages.js';
10
import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
11
12
export const ILanguageService = createDecorator<ILanguageService>('languageService');
13
14
export interface ILanguageExtensionPoint {
15
id: string;
16
extensions?: string[];
17
filenames?: string[];
18
filenamePatterns?: string[];
19
firstLine?: string;
20
aliases?: string[];
21
mimetypes?: string[];
22
configuration?: URI;
23
/**
24
* @internal
25
*/
26
icon?: ILanguageIcon;
27
}
28
29
export interface ILanguageSelection {
30
readonly languageId: string;
31
readonly onDidChange: Event<string>;
32
}
33
34
export interface ILanguageNameIdPair {
35
readonly languageName: string;
36
readonly languageId: string;
37
}
38
39
export interface ILanguageIcon {
40
readonly light: URI;
41
readonly dark: URI;
42
}
43
44
export interface ILanguageService {
45
readonly _serviceBrand: undefined;
46
47
/**
48
* A codec which can encode and decode a string `languageId` as a number.
49
*/
50
readonly languageIdCodec: ILanguageIdCodec;
51
52
/**
53
* An event emitted when basic language features are requested for the first time.
54
* This event is emitted when embedded languages are encountered (e.g. JS code block inside Markdown)
55
* or when a language is associated to a text model.
56
*
57
* **Note**: Basic language features refers to language configuration related features.
58
* **Note**: This event is a superset of `onDidRequestRichLanguageFeatures`
59
*/
60
onDidRequestBasicLanguageFeatures: Event<string>;
61
62
/**
63
* An event emitted when rich language features are requested for the first time.
64
* This event is emitted when a language is associated to a text model.
65
*
66
* **Note**: Rich language features refers to tokenizers, language features based on providers, etc.
67
* **Note**: This event is a subset of `onDidRequestRichLanguageFeatures`
68
*/
69
onDidRequestRichLanguageFeatures: Event<string>;
70
71
/**
72
* An event emitted when languages have changed.
73
*/
74
onDidChange: Event<void>;
75
76
/**
77
* Register a language.
78
*/
79
registerLanguage(def: ILanguageExtensionPoint): IDisposable;
80
81
/**
82
* Check if `languageId` is registered.
83
*/
84
isRegisteredLanguageId(languageId: string): boolean;
85
86
/**
87
* Get a list of all registered languages.
88
*/
89
getRegisteredLanguageIds(): string[];
90
91
/**
92
* Get a list of all registered languages with a name.
93
* If a language is explicitly registered without a name, it will not be part of the result.
94
* The result is sorted using by name case insensitive.
95
*/
96
getSortedRegisteredLanguageNames(): ILanguageNameIdPair[];
97
98
/**
99
* Get the preferred language name for a language.
100
*/
101
getLanguageName(languageId: string): string | null;
102
103
/**
104
* Get the mimetype for a language.
105
*/
106
getMimeType(languageId: string): string | null;
107
108
/**
109
* Get the default icon for the language.
110
*/
111
getIcon(languageId: string): ILanguageIcon | null;
112
113
/**
114
* Get all file extensions for a language.
115
*/
116
getExtensions(languageId: string): ReadonlyArray<string>;
117
118
/**
119
* Get all file names for a language.
120
*/
121
getFilenames(languageId: string): ReadonlyArray<string>;
122
123
/**
124
* Get all language configuration files for a language.
125
*/
126
getConfigurationFiles(languageId: string): ReadonlyArray<URI>;
127
128
/**
129
* Look up a language by its name case insensitive.
130
*/
131
getLanguageIdByLanguageName(languageName: string): string | null;
132
133
/**
134
* Look up a language by its mime type.
135
*/
136
getLanguageIdByMimeType(mimeType: string | null | undefined): string | null;
137
138
/**
139
* Guess the language id for a resource.
140
*/
141
guessLanguageIdByFilepathOrFirstLine(resource: URI, firstLine?: string): string | null;
142
143
/**
144
* Will fall back to 'plaintext' if `languageId` is unknown.
145
*/
146
createById(languageId: string | null | undefined): ILanguageSelection;
147
148
/**
149
* Will fall back to 'plaintext' if `mimeType` is unknown.
150
*/
151
createByMimeType(mimeType: string | null | undefined): ILanguageSelection;
152
153
/**
154
* Will fall back to 'plaintext' if the `languageId` cannot be determined.
155
*/
156
createByFilepathOrFirstLine(resource: URI | null, firstLine?: string): ILanguageSelection;
157
158
/**
159
* Request basic language features for a language.
160
*/
161
requestBasicLanguageFeatures(languageId: string): void;
162
163
/**
164
* Request rich language features for a language.
165
*/
166
requestRichLanguageFeatures(languageId: string): void;
167
168
}
169
170