import * as vscode from 'vscode' ; import * as html from 'vscode-html-languageservice' ; import * as lst from 'vscode-languageserver-types' ; import { EdgeFormatter , IEdgeFormatterOptions } from "../services/EdgeFormatter" ; const service = html . getLanguageService ( ) ; export class EdgeFormattingEditProvider implements vscode . DocumentFormattingEditProvider , vscode . DocumentRangeFormattingEditProvider { formatterOptions : IEdgeFormatterOptions ; provideDocumentFormattingEdits ( document , options ) { let range = new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( ( document . lineCount - 1 ) , Number . MAX_VALUE ) ) ; return this . provideFormattingEdits ( document , document . validateRange ( range ) , options ) ; } provideDocumentRangeFormattingEdits ( document , range , options ) { return this . provideFormattingEdits ( document , range , options ) ; } private provideFormattingEdits ( document , range , options ) { this . formatterOptions = { tabSize : options . tabSize , insertSpaces : options . insertSpaces } ; let htmlFormatConfig = vscode . workspace . getConfiguration ( 'html.format' ) ; Object . assign ( options , htmlFormatConfig ) ; let doc = lst . TextDocument . create ( document . uri . fsPath , 'html' , 1 , document . getText ( ) ) ; let htmlTextEdit = service . format ( doc , range , options ) ; let formatter = new EdgeFormatter ( this . formatterOptions ) ; let edgeText = formatter . format ( htmlTextEdit [ 0 ] . newText ) ; return [ vscode . TextEdit . replace ( range , edgeText ) ] ; } }