@@ -11,6 +11,8 @@ import {
11
11
CancellationToken ,
12
12
DocumentFormattingEditProvider ,
13
13
DocumentRangeFormattingEditProvider ,
14
+ OnTypeFormattingEditProvider ,
15
+ Position ,
14
16
Range ,
15
17
TextEditor ,
16
18
TextLine
@@ -131,7 +133,10 @@ class DocumentLocker {
131
133
}
132
134
}
133
135
134
- class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider , DocumentRangeFormattingEditProvider {
136
+ class PSDocumentFormattingEditProvider implements
137
+ DocumentFormattingEditProvider ,
138
+ DocumentRangeFormattingEditProvider ,
139
+ OnTypeFormattingEditProvider {
135
140
private static documentLocker = new DocumentLocker ( ) ;
136
141
private static statusBarTracker = new Object ( ) ;
137
142
private languageClient : LanguageClient ;
@@ -188,6 +193,24 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
188
193
return textEdits ;
189
194
}
190
195
196
+ provideOnTypeFormattingEdits (
197
+ document : TextDocument ,
198
+ position : Position ,
199
+ ch : string ,
200
+ options : FormattingOptions ,
201
+ token : CancellationToken ) : TextEdit [ ] | Thenable < TextEdit [ ] > {
202
+ if ( ch === "}" )
203
+ {
204
+ // find corresponding '{' character create a range between '{' and '}'
205
+ }
206
+ else if ( ch === "\n" )
207
+ {
208
+ // find the range that covers the entire line
209
+ }
210
+
211
+ return this . provideDocumentRangeFormattingEdits ( document , null , options , token ) ;
212
+ }
213
+
191
214
setLanguageClient ( languageClient : LanguageClient ) : void {
192
215
this . languageClient = languageClient ;
193
216
@@ -392,8 +415,10 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
392
415
}
393
416
394
417
export class DocumentFormatterFeature implements IFeature {
418
+ private firstTriggerCharacter : string = "}" ;
395
419
private formattingEditProvider : vscode . Disposable ;
396
420
private rangeFormattingEditProvider : vscode . Disposable ;
421
+ private onTypeFormattingEditProvider : vscode . Disposable ;
397
422
private languageClient : LanguageClient ;
398
423
private documentFormattingEditProvider : PSDocumentFormattingEditProvider ;
399
424
@@ -405,6 +430,10 @@ export class DocumentFormatterFeature implements IFeature {
405
430
this . rangeFormattingEditProvider = vscode . languages . registerDocumentRangeFormattingEditProvider (
406
431
"powershell" ,
407
432
this . documentFormattingEditProvider ) ;
433
+ this . onTypeFormattingEditProvider = vscode . languages . registerOnTypeFormattingEditProvider (
434
+ "powershell" ,
435
+ this . documentFormattingEditProvider ,
436
+ this . firstTriggerCharacter ) ;
408
437
}
409
438
410
439
public setLanguageClient ( languageclient : LanguageClient ) : void {
@@ -415,5 +444,6 @@ export class DocumentFormatterFeature implements IFeature {
415
444
public dispose ( ) : any {
416
445
this . formattingEditProvider . dispose ( ) ;
417
446
this . rangeFormattingEditProvider . dispose ( ) ;
447
+ this . onTypeFormattingEditProvider . dispose ( ) ;
418
448
}
419
449
}
0 commit comments