@@ -12,7 +12,7 @@ import {
12
12
DocumentUri ,
13
13
} from "../languageclient"
14
14
import { TextBuffer , TextEditor } from "atom"
15
- import * as fs from "fs"
15
+ import { promises as fsp , Stats } from "fs"
16
16
import * as rimraf from "rimraf"
17
17
18
18
/** Public: Adapts workspace/applyEdit commands to editors. */
@@ -92,11 +92,11 @@ export default class ApplyEditAdapter {
92
92
private static async handleResourceOperation ( edit : CreateFile | RenameFile | DeleteFile ) : Promise < void > {
93
93
if ( DeleteFile . is ( edit ) ) {
94
94
const path = Convert . uriToPath ( edit . uri )
95
- const stats : boolean | fs . Stats = await fs . promises . lstat ( path ) . catch ( ( ) => false )
95
+ const stats : boolean | Stats = await fsp . lstat ( path ) . catch ( ( ) => false )
96
96
const ignoreIfNotExists = edit . options ?. ignoreIfNotExists
97
97
98
98
if ( ! stats ) {
99
- if ( ignoreIfNotExists ) {
99
+ if ( ignoreIfNotExists !== false ) {
100
100
return
101
101
}
102
102
throw Error ( `Target doesn't exist.` )
@@ -113,15 +113,15 @@ export default class ApplyEditAdapter {
113
113
} )
114
114
} )
115
115
}
116
- return fs . promises . rmdir ( path , { recursive : edit . options ?. recursive } )
116
+ return fsp . rmdir ( path , { recursive : edit . options ?. recursive } )
117
117
}
118
118
119
- return fs . promises . unlink ( path )
119
+ return fsp . unlink ( path )
120
120
}
121
121
if ( RenameFile . is ( edit ) ) {
122
122
const oldPath = Convert . uriToPath ( edit . oldUri )
123
123
const newPath = Convert . uriToPath ( edit . newUri )
124
- const exists = await fs . promises
124
+ const exists = await fsp
125
125
. access ( newPath )
126
126
. then ( ( ) => true )
127
127
. catch ( ( ) => false )
@@ -136,11 +136,11 @@ export default class ApplyEditAdapter {
136
136
throw Error ( `Target exists.` )
137
137
}
138
138
139
- return fs . promises . rename ( oldPath , newPath )
139
+ return fsp . rename ( oldPath , newPath )
140
140
}
141
141
if ( CreateFile . is ( edit ) ) {
142
142
const path = Convert . uriToPath ( edit . uri )
143
- const exists = await fs . promises
143
+ const exists = await fsp
144
144
. access ( path )
145
145
. then ( ( ) => true )
146
146
. catch ( ( ) => false )
@@ -151,7 +151,7 @@ export default class ApplyEditAdapter {
151
151
return
152
152
}
153
153
154
- return fs . promises . writeFile ( path , "" )
154
+ return fsp . writeFile ( path , "" )
155
155
}
156
156
}
157
157
0 commit comments