@@ -7,10 +7,10 @@ import sax = require('sax');
77
88export class ClangDocumentFormattingEditProvider implements vscode . DocumentFormattingEditProvider , vscode . DocumentRangeFormattingEditProvider {
99 private defaultConfigure = {
10- executable : 'clang-format' ,
11- style : 'file' ,
12- fallbackStyle : 'none' ,
13- assumeFilename : ''
10+ executable : 'clang-format' ,
11+ style : 'file' ,
12+ fallbackStyle : 'none' ,
13+ assumeFilename : ''
1414 } ;
1515
1616 public provideDocumentFormattingEdits ( document : vscode . TextDocument , options : vscode . FormattingOptions , token : vscode . CancellationToken ) : Thenable < vscode . TextEdit [ ] > {
@@ -23,25 +23,25 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
2323
2424 private getEdits ( document : vscode . TextDocument , xml : string , codeContent : string ) : Thenable < vscode . TextEdit [ ] > {
2525 return new Promise ( ( resolve , reject ) => {
26- var options = {
27- trim : false ,
28- normalize : false ,
29- loose : true
26+ let options = {
27+ trim : false ,
28+ normalize : false ,
29+ loose : true
3030 } ;
31- var parser = sax . parser ( true , options ) ;
31+ let parser = sax . parser ( true , options ) ;
3232
33- var edits : vscode . TextEdit [ ] = [ ] ;
34- var currentEdit : { length : number , offset : number , text : string } ;
33+ let edits : vscode . TextEdit [ ] = [ ] ;
34+ let currentEdit : { length : number , offset : number , text : string } ;
3535
36- var codeBuffer = new Buffer ( codeContent ) ;
36+ let codeBuffer = new Buffer ( codeContent ) ;
3737 // encoding position cache
38- var codeByteOffsetCache = {
39- byte : 0 ,
40- offset : 0
38+ let codeByteOffsetCache = {
39+ byte : 0 ,
40+ offset : 0
4141 } ;
42- var byteToOffset = function ( editInfo : { length : number , offset : number } ) {
43- var offset = editInfo . offset ;
44- var length = editInfo . length ;
42+ let byteToOffset = function ( editInfo : { length : number , offset : number } ) {
43+ let offset = editInfo . offset ;
44+ let length = editInfo . length ;
4545
4646 if ( offset >= codeByteOffsetCache . byte ) {
4747 editInfo . offset = codeByteOffsetCache . offset + codeBuffer . slice ( codeByteOffsetCache . byte , offset ) . toString ( 'utf8' ) . length ;
@@ -73,9 +73,9 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
7373
7474 case 'replacement' :
7575 currentEdit = {
76- length : parseInt ( tag . attributes [ 'length' ] . toString ( ) ) ,
77- offset : parseInt ( tag . attributes [ 'offset' ] . toString ( ) ) ,
78- text : ''
76+ length : parseInt ( tag . attributes [ 'length' ] . toString ( ) ) ,
77+ offset : parseInt ( tag . attributes [ 'offset' ] . toString ( ) ) ,
78+ text : ''
7979 } ;
8080 byteToOffset ( currentEdit ) ;
8181 break ;
@@ -95,10 +95,10 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
9595 parser . onclosetag = ( tagName ) => {
9696 if ( ! currentEdit ) { return ; }
9797
98- var start = document . positionAt ( currentEdit . offset ) ;
99- var end = document . positionAt ( currentEdit . offset + currentEdit . length ) ;
98+ let start = document . positionAt ( currentEdit . offset ) ;
99+ let end = document . positionAt ( currentEdit . offset + currentEdit . length ) ;
100100
101- var editRange = new vscode . Range ( start , end ) ;
101+ let editRange = new vscode . Range ( start , end ) ;
102102
103103 edits . push ( new vscode . TextEdit ( editRange , currentEdit . text ) ) ;
104104 currentEdit = null ;
@@ -169,12 +169,12 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
169169
170170 private doFormatDocument ( document : vscode . TextDocument , range : vscode . Range , options : vscode . FormattingOptions , token : vscode . CancellationToken ) : Thenable < vscode . TextEdit [ ] > {
171171 return new Promise ( ( resolve , reject ) => {
172- var filename = document . fileName ;
172+ let filename = document . fileName ;
173173
174- var formatCommandBinPath = getBinPath ( this . getExecutablePath ( ) ) ;
175- var codeContent = document . getText ( ) ;
174+ let formatCommandBinPath = getBinPath ( this . getExecutablePath ( ) ) ;
175+ let codeContent = document . getText ( ) ;
176176
177- var childCompleted = ( err , stdout , stderr ) => {
177+ let childCompleted = ( err , stdout , stderr ) => {
178178 try {
179179 if ( err && ( < any > err ) . code === 'ENOENT' ) {
180180 vscode . window . showInformationMessage ( 'The \'' + formatCommandBinPath + '\' command is not available. Please check your clang-format.executable user setting and ensure it is installed.' ) ;
@@ -184,7 +184,7 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
184184 return reject ( 'Cannot format due to syntax errors.' ) ;
185185 }
186186
187- var dummyProcessor = ( value : string ) => {
187+ let dummyProcessor = ( value : string ) => {
188188 debugger ;
189189 return value ;
190190 } ;
@@ -195,16 +195,16 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
195195 }
196196 } ;
197197
198- var formatArgs = [
198+ let formatArgs = [
199199 '-output-replacements-xml' ,
200200 `-style=${ this . getStyle ( document ) } ` ,
201201 `-fallback-style=${ this . getFallbackStyle ( document ) } ` ,
202- `-assume-filename=${ this . getAssumedFilename ( document ) } ` ,
202+ `-assume-filename=${ this . getAssumedFilename ( document ) } `
203203 ] ;
204204
205205 if ( range ) {
206- var offset = document . offsetAt ( range . start ) ;
207- var length = document . offsetAt ( range . end ) - offset ;
206+ let offset = document . offsetAt ( range . start ) ;
207+ let length = document . offsetAt ( range . end ) - offset ;
208208
209209 // fix charater length to byte length
210210 length = Buffer . byteLength ( codeContent . substr ( offset , length ) , 'utf8' ) ;
@@ -214,12 +214,12 @@ export class ClangDocumentFormattingEditProvider implements vscode.DocumentForma
214214 formatArgs . push ( `-offset=${ offset } ` , `-length=${ length } ` ) ;
215215 }
216216
217- var workingPath = vscode . workspace . rootPath ;
217+ let workingPath = vscode . workspace . rootPath ;
218218 if ( ! document . isUntitled ) {
219219 workingPath = path . dirname ( document . fileName ) ;
220220 }
221221
222- var child = cp . execFile ( formatCommandBinPath , formatArgs , { cwd : workingPath } , childCompleted ) ;
222+ let child = cp . execFile ( formatCommandBinPath , formatArgs , { cwd : workingPath } , childCompleted ) ;
223223 child . stdin . end ( codeContent ) ;
224224
225225 if ( token ) {
@@ -240,10 +240,10 @@ let diagnosticCollection: vscode.DiagnosticCollection;
240240
241241export function activate ( ctx : vscode . ExtensionContext ) : void {
242242
243- var formatter = new ClangDocumentFormattingEditProvider ( ) ;
244- var availableLanguages = { } ;
243+ let formatter = new ClangDocumentFormattingEditProvider ( ) ;
244+ let availableLanguages = { } ;
245245
246- MODES . forEach ( mode => {
246+ MODES . forEach ( ( mode ) => {
247247 ctx . subscriptions . push ( vscode . languages . registerDocumentRangeFormattingEditProvider ( mode , formatter ) ) ;
248248 ctx . subscriptions . push ( vscode . languages . registerDocumentFormattingEditProvider ( mode , formatter ) ) ;
249249 availableLanguages [ mode . language ] = true ;
0 commit comments