@@ -12,7 +12,7 @@ import {
1212 DocumentUri ,
1313} from "../languageclient"
1414import { TextBuffer , TextEditor } from "atom"
15- import * as fs from "fs"
15+ import { promises as fsp , Stats } from "fs"
1616import * as rimraf from "rimraf"
1717
1818/** Public: Adapts workspace/applyEdit commands to editors. */
@@ -92,11 +92,11 @@ export default class ApplyEditAdapter {
9292 private static async handleResourceOperation ( edit : CreateFile | RenameFile | DeleteFile ) : Promise < void > {
9393 if ( DeleteFile . is ( edit ) ) {
9494 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 )
9696 const ignoreIfNotExists = edit . options ?. ignoreIfNotExists
9797
9898 if ( ! stats ) {
99- if ( ignoreIfNotExists ) {
99+ if ( ignoreIfNotExists !== false ) {
100100 return
101101 }
102102 throw Error ( `Target doesn't exist.` )
@@ -113,15 +113,15 @@ export default class ApplyEditAdapter {
113113 } )
114114 } )
115115 }
116- return fs . promises . rmdir ( path , { recursive : edit . options ?. recursive } )
116+ return fsp . rmdir ( path , { recursive : edit . options ?. recursive } )
117117 }
118118
119- return fs . promises . unlink ( path )
119+ return fsp . unlink ( path )
120120 }
121121 if ( RenameFile . is ( edit ) ) {
122122 const oldPath = Convert . uriToPath ( edit . oldUri )
123123 const newPath = Convert . uriToPath ( edit . newUri )
124- const exists = await fs . promises
124+ const exists = await fsp
125125 . access ( newPath )
126126 . then ( ( ) => true )
127127 . catch ( ( ) => false )
@@ -136,11 +136,11 @@ export default class ApplyEditAdapter {
136136 throw Error ( `Target exists.` )
137137 }
138138
139- return fs . promises . rename ( oldPath , newPath )
139+ return fsp . rename ( oldPath , newPath )
140140 }
141141 if ( CreateFile . is ( edit ) ) {
142142 const path = Convert . uriToPath ( edit . uri )
143- const exists = await fs . promises
143+ const exists = await fsp
144144 . access ( path )
145145 . then ( ( ) => true )
146146 . catch ( ( ) => false )
@@ -151,7 +151,7 @@ export default class ApplyEditAdapter {
151151 return
152152 }
153153
154- return fs . promises . writeFile ( path , "" )
154+ return fsp . writeFile ( path , "" )
155155 }
156156 }
157157
0 commit comments