@@ -28,20 +28,22 @@ suite("Formatting", () => {
28
28
test ( "AutoPep8" , done => {
29
29
let fileToFormat = path . join ( pythoFilesPath , "beforeAutoPep8.py" ) ;
30
30
vscode . workspace . openTextDocument ( fileToFormat ) . then ( textDocument => {
31
- vscode . window . showTextDocument ( textDocument ) ;
32
- let formatter = new AutoPep8Formatter ( ch , pythonSettings , pythoFilesPath ) ;
33
- return formatter . formatDocument ( textDocument , null , null ) . then ( edits => {
34
- let activeEditor = vscode . window . activeTextEditor ;
35
- activeEditor . edit ( editBuilder => {
36
- edits . forEach ( edit => editBuilder . replace ( edit . range , edit . newText ) ) ;
37
- } ) . then ( edited => {
38
- let formattedFile = path . join ( pythoFilesPath , "afterAutoPep8.py" ) ;
39
- let formattedContents = fs . readFile ( formattedFile , "utf-8" , ( error , data ) => {
40
- if ( error ) {
41
- return assert . fail ( error , "" , "Failed to read formatted file" ) ;
42
- }
43
- assert . equal ( activeEditor . document . getText ( ) , data , "Formatted text is not the same" ) ;
31
+ vscode . window . showTextDocument ( textDocument ) . then ( textEditor => {
32
+ let formatter = new AutoPep8Formatter ( ch , pythonSettings , pythoFilesPath ) ;
33
+ return formatter . formatDocument ( textDocument , null , null ) . then ( edits => {
34
+ textEditor . edit ( editBuilder => {
35
+ edits . forEach ( edit => editBuilder . replace ( edit . range , edit . newText ) ) ;
36
+ } ) . then ( edited => {
37
+ let formattedFile = path . join ( pythoFilesPath , "afterAutoPep8.py" ) ;
38
+ let formattedContents = fs . readFile ( formattedFile , "utf-8" , ( error , data ) => {
39
+ if ( error ) {
40
+ return assert . fail ( error , "" , "Failed to read formatted file" ) ;
41
+ }
42
+ assert . equal ( textEditor . document . getText ( ) , data , "Formatted text is not the same" ) ;
43
+ } ) ;
44
44
} ) ;
45
+ } , error => {
46
+ assert . fail ( error , "" , "Error in Formatting, " + error ) ;
45
47
} ) ;
46
48
} , error => {
47
49
assert . fail ( error , "" , "Error in Formatting, " + error ) ;
@@ -54,20 +56,22 @@ suite("Formatting", () => {
54
56
test ( "Yapf" , done => {
55
57
let fileToFormat = path . join ( pythoFilesPath , "beforeYapf.py" ) ;
56
58
vscode . workspace . openTextDocument ( fileToFormat ) . then ( textDocument => {
57
- vscode . window . showTextDocument ( textDocument ) ;
58
- let formatter = new YapfFormatter ( ch , pythonSettings , pythoFilesPath ) ;
59
- return formatter . formatDocument ( textDocument , null , null ) . then ( edits => {
60
- let activeEditor = vscode . window . activeTextEditor ;
61
- activeEditor . edit ( editBuilder => {
62
- edits . forEach ( edit => editBuilder . replace ( edit . range , edit . newText ) ) ;
63
- } ) . then ( edited => {
64
- let formattedFile = path . join ( pythoFilesPath , "afterYapf.py" ) ;
65
- let formattedContents = fs . readFile ( formattedFile , "utf-8" , ( error , data ) => {
66
- if ( error ) {
67
- return assert . fail ( error , "" , "Failed to read formatted file" ) ;
68
- }
69
- assert . equal ( activeEditor . document . getText ( ) , data , "Formatted text is not the same" ) ;
59
+ vscode . window . showTextDocument ( textDocument ) . then ( textEditor => {
60
+ let formatter = new YapfFormatter ( ch , pythonSettings , pythoFilesPath ) ;
61
+ return formatter . formatDocument ( textDocument , null , null ) . then ( edits => {
62
+ textEditor . edit ( editBuilder => {
63
+ edits . forEach ( edit => editBuilder . replace ( edit . range , edit . newText ) ) ;
64
+ } ) . then ( edited => {
65
+ let formattedFile = path . join ( pythoFilesPath , "afterYapf.py" ) ;
66
+ let formattedContents = fs . readFile ( formattedFile , "utf-8" , ( error , data ) => {
67
+ if ( error ) {
68
+ return assert . fail ( error , "" , "Failed to read formatted file" ) ;
69
+ }
70
+ assert . equal ( textEditor . document . getText ( ) , data , "Formatted text is not the same" ) ;
71
+ } ) ;
70
72
} ) ;
73
+ } , error => {
74
+ assert . fail ( error , "" , "Error in Formatting, " + error ) ;
71
75
} ) ;
72
76
} , error => {
73
77
assert . fail ( error , "" , "Error in Formatting, " + error ) ;
0 commit comments