@@ -11,6 +11,8 @@ import {
1111 CancellationToken ,
1212 DocumentFormattingEditProvider ,
1313 DocumentRangeFormattingEditProvider ,
14+ OnTypeFormattingEditProvider ,
15+ Position ,
1416 Range ,
1517 TextEditor ,
1618 TextLine
@@ -131,7 +133,10 @@ class DocumentLocker {
131133 }
132134}
133135
134- class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider , DocumentRangeFormattingEditProvider {
136+ class PSDocumentFormattingEditProvider implements
137+ DocumentFormattingEditProvider ,
138+ DocumentRangeFormattingEditProvider ,
139+ OnTypeFormattingEditProvider {
135140 private static documentLocker = new DocumentLocker ( ) ;
136141 private static statusBarTracker = new Object ( ) ;
137142 private languageClient : LanguageClient ;
@@ -188,6 +193,24 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
188193 return textEdits ;
189194 }
190195
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+
191214 setLanguageClient ( languageClient : LanguageClient ) : void {
192215 this . languageClient = languageClient ;
193216
@@ -392,8 +415,10 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
392415}
393416
394417export class DocumentFormatterFeature implements IFeature {
418+ private firstTriggerCharacter : string = "}" ;
395419 private formattingEditProvider : vscode . Disposable ;
396420 private rangeFormattingEditProvider : vscode . Disposable ;
421+ private onTypeFormattingEditProvider : vscode . Disposable ;
397422 private languageClient : LanguageClient ;
398423 private documentFormattingEditProvider : PSDocumentFormattingEditProvider ;
399424
@@ -405,6 +430,10 @@ export class DocumentFormatterFeature implements IFeature {
405430 this . rangeFormattingEditProvider = vscode . languages . registerDocumentRangeFormattingEditProvider (
406431 "powershell" ,
407432 this . documentFormattingEditProvider ) ;
433+ this . onTypeFormattingEditProvider = vscode . languages . registerOnTypeFormattingEditProvider (
434+ "powershell" ,
435+ this . documentFormattingEditProvider ,
436+ this . firstTriggerCharacter ) ;
408437 }
409438
410439 public setLanguageClient ( languageclient : LanguageClient ) : void {
@@ -415,5 +444,6 @@ export class DocumentFormatterFeature implements IFeature {
415444 public dispose ( ) : any {
416445 this . formattingEditProvider . dispose ( ) ;
417446 this . rangeFormattingEditProvider . dispose ( ) ;
447+ this . onTypeFormattingEditProvider . dispose ( ) ;
418448 }
419449}
0 commit comments