From e1535a79eac08a1169ae429dde44eb39fcc46c34 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 24 Feb 2022 12:19:09 +0100 Subject: [PATCH 1/2] fix async method --- apps/remix-ide/src/app/files/fileManager.ts | 2 +- .../remix-ide/src/app/files/remixDProvider.js | 23 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index 5ac6f8dd30..9c11b5863d 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -752,7 +752,7 @@ class FileManager extends Plugin { if (provider) { try{ const content = await provider.get(currentFile) - this.editor.setText(content) + if(content) this.editor.setText(content) }catch(error){ console.log(error) } diff --git a/apps/remix-ide/src/app/files/remixDProvider.js b/apps/remix-ide/src/app/files/remixDProvider.js index a36b6d8ec9..0e8f1223cf 100644 --- a/apps/remix-ide/src/app/files/remixDProvider.js +++ b/apps/remix-ide/src/app/files/remixDProvider.js @@ -98,20 +98,19 @@ module.exports = class RemixDProvider extends FileProvider { }) } - get (path, cb) { + async get (path, cb) { if (!this._isReady) return cb && cb('provider not ready') var unprefixedpath = this.removePrefix(path) - this._appManager.call('remixd', 'get', { path: unprefixedpath }) - .then((file) => { - this.filesContent[path] = file.content - if (file.readonly) { this._readOnlyFiles[path] = 1 } - cb(null, file.content) - }).catch((error) => { - if (error) console.log(error) - // display the last known content. - // TODO should perhaps better warn the user that the file is not synced. - return cb(null, this.filesContent[path]) - }) + try{ + const file = await this._appManager.call('remixd', 'get', { path: unprefixedpath }) + this.filesContent[path] = file.content + if (file.readonly) { this._readOnlyFiles[path] = 1 } + if(cb) return cb(null, file.content) + return file.content + } catch(error) { + if (error) console.log(error) + if(cb) return cb(null, this.filesContent[path]) + } } async set (path, content, cb) { From 7591a9e9382d1e82d447a6c96dd7fb7be29cc386 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Thu, 24 Feb 2022 12:45:15 +0100 Subject: [PATCH 2/2] Update remixDProvider.js --- apps/remix-ide/src/app/files/remixDProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/files/remixDProvider.js b/apps/remix-ide/src/app/files/remixDProvider.js index 0e8f1223cf..c52055e04f 100644 --- a/apps/remix-ide/src/app/files/remixDProvider.js +++ b/apps/remix-ide/src/app/files/remixDProvider.js @@ -105,7 +105,7 @@ module.exports = class RemixDProvider extends FileProvider { const file = await this._appManager.call('remixd', 'get', { path: unprefixedpath }) this.filesContent[path] = file.content if (file.readonly) { this._readOnlyFiles[path] = 1 } - if(cb) return cb(null, file.content) + if(cb) cb(null, file.content) return file.content } catch(error) { if (error) console.log(error)