6
6
import { Emitter , Event } from 'vs/base/common/event' ;
7
7
import { Disposable , IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
8
8
import * as strings from 'vs/base/common/strings' ;
9
- import { LineTokens } from 'vs/editor/common/tokens/lineTokens' ;
10
9
import { ITextModel } from 'vs/editor/common/model' ;
11
10
import { DEFAULT_WORD_REGEXP , ensureValidWordDefinition } from 'vs/editor/common/core/wordHelper' ;
12
11
import { EnterAction , FoldingRules , IAutoClosingPair , IndentationRule , LanguageConfiguration , AutoClosingPairs , CharacterPair , ExplicitLanguageConfiguration } from 'vs/editor/common/languages/languageConfiguration' ;
@@ -21,6 +20,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
21
20
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
22
21
import { ILanguageService } from 'vs/editor/common/languages/language' ;
23
22
import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
23
+ import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry' ;
24
24
25
25
/**
26
26
* Interface used to support insertion of mode specific comments.
@@ -31,19 +31,6 @@ export interface ICommentsConfiguration {
31
31
blockCommentEndToken ?: string ;
32
32
}
33
33
34
- export interface IVirtualModel {
35
- getLineTokens ( lineNumber : number ) : LineTokens ;
36
- getLanguageId ( ) : string ;
37
- getLanguageIdAtPosition ( lineNumber : number , column : number ) : string ;
38
- getLineContent ( lineNumber : number ) : string ;
39
- }
40
-
41
- export interface IIndentConverter {
42
- shiftIndent ( indentation : string ) : string ;
43
- unshiftIndent ( indentation : string ) : string ;
44
- normalizeIndentation ?( indentation : string ) : string ;
45
- }
46
-
47
34
export interface ILanguageConfigurationService {
48
35
readonly _serviceBrand : undefined ;
49
36
@@ -71,6 +58,8 @@ export const ILanguageConfigurationService = createDecorator<ILanguageConfigurat
71
58
export class LanguageConfigurationService extends Disposable implements ILanguageConfigurationService {
72
59
_serviceBrand : undefined ;
73
60
61
+ private readonly _registry = this . _register ( new LanguageConfigurationRegistry ( ) ) ;
62
+
74
63
private readonly onDidChangeEmitter = this . _register ( new Emitter < LanguageConfigurationServiceChangeEvent > ( ) ) ;
75
64
public readonly onDidChange = this . onDidChangeEmitter . event ;
76
65
@@ -107,20 +96,20 @@ export class LanguageConfigurationService extends Disposable implements ILanguag
107
96
}
108
97
} ) ) ;
109
98
110
- this . _register ( LanguageConfigurationRegistry . onDidChange ( ( e ) => {
99
+ this . _register ( this . _registry . onDidChange ( ( e ) => {
111
100
this . configurations . delete ( e . languageId ) ;
112
101
this . onDidChangeEmitter . fire ( new LanguageConfigurationServiceChangeEvent ( e . languageId ) ) ;
113
102
} ) ) ;
114
103
}
115
104
116
105
public register ( languageId : string , configuration : LanguageConfiguration , priority ?: number ) : IDisposable {
117
- return LanguageConfigurationRegistry . register ( languageId , configuration , priority ) ;
106
+ return this . _registry . register ( languageId , configuration , priority ) ;
118
107
}
119
108
120
109
public getLanguageConfiguration ( languageId : string ) : ResolvedLanguageConfiguration {
121
110
let result = this . configurations . get ( languageId ) ;
122
111
if ( ! result ) {
123
- result = computeConfig ( languageId , this . configurationService , this . languageService ) ;
112
+ result = computeConfig ( languageId , this . _registry , this . configurationService , this . languageService ) ;
124
113
this . configurations . set ( languageId , result ) ;
125
114
}
126
115
return result ;
@@ -129,10 +118,11 @@ export class LanguageConfigurationService extends Disposable implements ILanguag
129
118
130
119
function computeConfig (
131
120
languageId : string ,
121
+ registry : LanguageConfigurationRegistry ,
132
122
configurationService : IConfigurationService ,
133
123
languageService : ILanguageService ,
134
124
) : ResolvedLanguageConfiguration {
135
- let languageConfig = LanguageConfigurationRegistry . getLanguageConfiguration ( languageId ) ;
125
+ let languageConfig = registry . getLanguageConfiguration ( languageId ) ;
136
126
137
127
if ( ! languageConfig ) {
138
128
if ( ! languageService . isRegisteredLanguageId ( languageId ) ) {
@@ -179,41 +169,6 @@ function validateBracketPairs(data: unknown): CharacterPair[] | undefined {
179
169
} ) . filter ( ( p ) : p is CharacterPair => ! ! p ) ;
180
170
}
181
171
182
- export class LanguageConfigurationChangeEvent {
183
- constructor ( public readonly languageId : string ) { }
184
- }
185
-
186
- export class LanguageConfigurationRegistryImpl {
187
- private readonly _entries = new Map < string , ComposedLanguageConfiguration > ( ) ;
188
-
189
- private readonly _onDidChange = new Emitter < LanguageConfigurationChangeEvent > ( ) ;
190
- public readonly onDidChange : Event < LanguageConfigurationChangeEvent > = this . _onDidChange . event ;
191
-
192
- /**
193
- * @param priority Use a higher number for higher priority
194
- */
195
- public register ( languageId : string , configuration : LanguageConfiguration , priority : number = 0 ) : IDisposable {
196
- let entries = this . _entries . get ( languageId ) ;
197
- if ( ! entries ) {
198
- entries = new ComposedLanguageConfiguration ( languageId ) ;
199
- this . _entries . set ( languageId , entries ) ;
200
- }
201
-
202
- const disposable = entries . register ( configuration , priority ) ;
203
- this . _onDidChange . fire ( new LanguageConfigurationChangeEvent ( languageId ) ) ;
204
-
205
- return toDisposable ( ( ) => {
206
- disposable . dispose ( ) ;
207
- this . _onDidChange . fire ( new LanguageConfigurationChangeEvent ( languageId ) ) ;
208
- } ) ;
209
- }
210
-
211
- public getLanguageConfiguration ( languageId : string ) : ResolvedLanguageConfiguration | null {
212
- const entries = this . _entries . get ( languageId ) ;
213
- return entries ?. getResolvedConfiguration ( ) || null ;
214
- }
215
- }
216
-
217
172
export function getIndentationAtPosition ( model : ITextModel , lineNumber : number , column : number ) : string {
218
173
const lineText = model . getLineContent ( lineNumber ) ;
219
174
let indentation = strings . getLeadingWhitespace ( lineText ) ;
@@ -230,11 +185,6 @@ export function getScopedLineTokens(model: ITextModel, lineNumber: number, colum
230
185
return createScopedLineTokens ( lineTokens , column ) ;
231
186
}
232
187
233
- /**
234
- * @deprecated Use ILanguageConfigurationService instead.
235
- */
236
- export const LanguageConfigurationRegistry = new LanguageConfigurationRegistryImpl ( ) ;
237
-
238
188
class ComposedLanguageConfiguration {
239
189
private readonly _entries : LanguageConfigurationContribution [ ] ;
240
190
private _order : number ;
@@ -340,6 +290,65 @@ class LanguageConfigurationContribution {
340
290
}
341
291
}
342
292
293
+ export class LanguageConfigurationChangeEvent {
294
+ constructor ( public readonly languageId : string ) { }
295
+ }
296
+
297
+ export class LanguageConfigurationRegistry extends Disposable {
298
+ private readonly _entries = new Map < string , ComposedLanguageConfiguration > ( ) ;
299
+
300
+ private readonly _onDidChange = this . _register ( new Emitter < LanguageConfigurationChangeEvent > ( ) ) ;
301
+ public readonly onDidChange : Event < LanguageConfigurationChangeEvent > = this . _onDidChange . event ;
302
+
303
+ constructor ( ) {
304
+ super ( ) ;
305
+ this . _register ( this . register ( PLAINTEXT_LANGUAGE_ID , {
306
+ brackets : [
307
+ [ '(' , ')' ] ,
308
+ [ '[' , ']' ] ,
309
+ [ '{' , '}' ] ,
310
+ ] ,
311
+ surroundingPairs : [
312
+ { open : '{' , close : '}' } ,
313
+ { open : '[' , close : ']' } ,
314
+ { open : '(' , close : ')' } ,
315
+ { open : '<' , close : '>' } ,
316
+ { open : '\"' , close : '\"' } ,
317
+ { open : '\'' , close : '\'' } ,
318
+ { open : '`' , close : '`' } ,
319
+ ] ,
320
+ colorizedBracketPairs : [ ] ,
321
+ folding : {
322
+ offSide : true
323
+ }
324
+ } , 0 ) ) ;
325
+ }
326
+
327
+ /**
328
+ * @param priority Use a higher number for higher priority
329
+ */
330
+ public register ( languageId : string , configuration : LanguageConfiguration , priority : number = 0 ) : IDisposable {
331
+ let entries = this . _entries . get ( languageId ) ;
332
+ if ( ! entries ) {
333
+ entries = new ComposedLanguageConfiguration ( languageId ) ;
334
+ this . _entries . set ( languageId , entries ) ;
335
+ }
336
+
337
+ const disposable = entries . register ( configuration , priority ) ;
338
+ this . _onDidChange . fire ( new LanguageConfigurationChangeEvent ( languageId ) ) ;
339
+
340
+ return toDisposable ( ( ) => {
341
+ disposable . dispose ( ) ;
342
+ this . _onDidChange . fire ( new LanguageConfigurationChangeEvent ( languageId ) ) ;
343
+ } ) ;
344
+ }
345
+
346
+ public getLanguageConfiguration ( languageId : string ) : ResolvedLanguageConfiguration | null {
347
+ const entries = this . _entries . get ( languageId ) ;
348
+ return entries ?. getResolvedConfiguration ( ) || null ;
349
+ }
350
+ }
351
+
343
352
/**
344
353
* Immutable.
345
354
*/
0 commit comments