@@ -60,7 +60,7 @@ export class FormattingHandler {
60
60
const textDocument = await vscode . workspace . openTextDocument ( razorDocumentUri ) ;
61
61
const synchronized = await this . documentSynchronizer . trySynchronizeProjectedDocument (
62
62
textDocument ,
63
- razorDocument . csharpDocument ,
63
+ razorDocument . htmlDocument ,
64
64
formattingParams . hostDocumentVersion ,
65
65
cancellationToken
66
66
) ;
@@ -70,9 +70,21 @@ export class FormattingHandler {
70
70
71
71
const virtualHtmlUri = razorDocument . htmlDocument . uri ;
72
72
73
+ // This is a workaround for https://github.com/microsoft/vscode/issues/191395.
74
+ // We need to call the HTML range formatter instead of document formattter since
75
+ // the latter does not respect HTML settings.
76
+ const htmlDocContent = razorDocument . htmlDocument . getContent ( ) ;
77
+ const zeroBasedNumLinesHtmlDoc = this . countLines ( htmlDocContent ) ;
78
+ const lastLineLengthHtmlDoc = this . getLastLineLength ( htmlDocContent ) ;
79
+ const range = new vscode . Range (
80
+ new vscode . Position ( 0 , 0 ) ,
81
+ new vscode . Position ( zeroBasedNumLinesHtmlDoc , lastLineLengthHtmlDoc )
82
+ ) ;
83
+
73
84
const textEdits = await vscode . commands . executeCommand < vscode . TextEdit [ ] > (
74
- 'vscode.executeFormatDocumentProvider ' ,
85
+ 'vscode.executeFormatRangeProvider ' ,
75
86
virtualHtmlUri ,
87
+ range ,
76
88
formattingParams . options
77
89
) ;
78
90
0 commit comments