@@ -60,7 +60,7 @@ export class FormattingHandler {
6060 const textDocument = await vscode . workspace . openTextDocument ( razorDocumentUri ) ;
6161 const synchronized = await this . documentSynchronizer . trySynchronizeProjectedDocument (
6262 textDocument ,
63- razorDocument . csharpDocument ,
63+ razorDocument . htmlDocument ,
6464 formattingParams . hostDocumentVersion ,
6565 cancellationToken
6666 ) ;
@@ -70,9 +70,21 @@ export class FormattingHandler {
7070
7171 const virtualHtmlUri = razorDocument . htmlDocument . uri ;
7272
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+
7384 const textEdits = await vscode . commands . executeCommand < vscode . TextEdit [ ] > (
74- 'vscode.executeFormatDocumentProvider ' ,
85+ 'vscode.executeFormatRangeProvider ' ,
7586 virtualHtmlUri ,
87+ range ,
7688 formattingParams . options
7789 ) ;
7890
0 commit comments