@@ -15,31 +15,43 @@ export class DocumentRangeFormattingEditProvider implements vscode.DocumentRange
1515 }
1616
1717 public async provideDocumentRangeFormattingEdits ( document : vscode . TextDocument , range : vscode . Range ,
18+ options : vscode . FormattingOptions , token : vscode . CancellationToken ) : Promise < vscode . TextEdit [ ] > {
19+ return this . provideFormattingEdits ( document , [ range ] , options , token ) ;
20+ }
21+
22+ public async provideDocumentRangesFormattingEdits ( document : vscode . TextDocument , ranges : vscode . Range [ ] ,
23+ options : vscode . FormattingOptions , token : vscode . CancellationToken ) : Promise < vscode . TextEdit [ ] > {
24+ return this . provideFormattingEdits ( document , ranges , options , token ) ;
25+ }
26+
27+ private async provideFormattingEdits ( document : vscode . TextDocument , ranges : vscode . Range [ ] ,
1828 options : vscode . FormattingOptions , token : vscode . CancellationToken ) : Promise < vscode . TextEdit [ ] > {
1929 const settings : CppSettings = new CppSettings ( vscode . workspace . getWorkspaceFolder ( document . uri ) ?. uri ) ;
20- if ( settings . formattingEngine === "disabled" ) {
30+ if ( settings . formattingEngine === "disabled" || ranges . length === 0 ) {
2131 return [ ] ;
2232 }
2333 const filePath : string = document . uri . fsPath ;
2434 const useVcFormat : boolean = settings . useVcFormat ( document ) ;
2535 const configCallBack = async ( editorConfigSettings : any | undefined ) => {
36+ const requestRanges = ranges . map ( range => ( {
37+ start : {
38+ character : range . start . character ,
39+ line : range . start . line
40+ } ,
41+ end : {
42+ character : range . end . character ,
43+ line : range . end . line
44+ }
45+ } ) ) ;
2646 const params : FormatParams = {
2747 editorConfigSettings : { ...editorConfigSettings } ,
2848 useVcFormat : useVcFormat ,
2949 uri : document . uri . toString ( ) ,
3050 insertSpaces : options . insertSpaces ,
3151 tabSize : options . tabSize ,
3252 character : "" ,
33- range : {
34- start : {
35- character : range . start . character ,
36- line : range . start . line
37- } ,
38- end : {
39- character : range . end . character ,
40- line : range . end . line
41- }
42- } ,
53+ range : requestRanges [ 0 ] ,
54+ ranges : requestRanges ,
4355 onChanges : false
4456 } ;
4557 let response : FormatResult ;
@@ -63,12 +75,4 @@ export class DocumentRangeFormattingEditProvider implements vscode.DocumentRange
6375 return configCallBack ( editorConfigSettings ) ;
6476 }
6577 }
66-
67- // TODO: This is needed for correct Extract to function formatting.
68- /*
69- public async provideDocumentRangesFormattingEdits(_document: vscode.TextDocument, _ranges: vscode.Range[],
70- _options: vscode.FormattingOptions, _token: vscode.CancellationToken): Promise<vscode.TextEdit[]> {
71- return [];
72- }
73- */
7478}
0 commit comments