@@ -222,16 +222,17 @@ class PSDocumentFormattingEditProvider implements
222222 ch : string ,
223223 options : FormattingOptions ,
224224 token : CancellationToken ) : TextEdit [ ] | Thenable < TextEdit [ ] > {
225- if ( ch === "}" )
226- {
227- // find corresponding '{' character create a range between '{' and '}'
228- }
229- else if ( ch === "\n" )
230- {
231- // find the range that covers the entire line
232- }
233-
234- return this . provideDocumentRangeFormattingEdits ( document , null , options , token ) ;
225+ return this . getScriptRegion ( document , position , ch ) . then ( scriptRegion => {
226+ if ( scriptRegion === null ) {
227+ return this . emptyPromise ;
228+ }
229+
230+ return this . provideDocumentRangeFormattingEdits (
231+ document ,
232+ toRange ( scriptRegion ) ,
233+ options ,
234+ token ) ;
235+ } ) ;
235236 }
236237
237238 setLanguageClient ( languageClient : LanguageClient ) : void {
@@ -244,6 +245,23 @@ class PSDocumentFormattingEditProvider implements
244245 PSDocumentFormattingEditProvider . disposeAllStatusBars ( ) ;
245246 }
246247
248+ private getScriptRegion ( document : TextDocument , position : Position , ch : string ) : Thenable < ScriptRegion > {
249+ return this . languageClient . sendRequest (
250+ ScriptRegionRequest . type ,
251+ {
252+ fileUri : document . uri . toString ( ) ,
253+ character : ch ,
254+ line : position . line + 1 ,
255+ column : position . character + 1
256+ } ) . then ( ( result : ScriptRegionRequestResult ) => {
257+ if ( result === null ) {
258+ return null ;
259+ }
260+
261+ return result . scriptRegion ;
262+ } ) ;
263+ }
264+
247265 private snapRangeToEdges ( range : Range , document : TextDocument ) : Range {
248266 return range . with ( {
249267 start : range . start . with ( { character : 0 } ) ,
0 commit comments