-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move filemanager api to new api #2733
Conversation
src/app/files/fileManager.js
Outdated
@@ -23,7 +23,7 @@ const profile = { | |||
icon: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB3aWR0aD0iMTc5MiIgaGVpZ2h0PSIxNzkyIiB2aWV3Qm94PSIwIDAgMTc5MiAxNzkyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xNjk2IDM4NHE0MCAwIDY4IDI4dDI4IDY4djEyMTZxMCA0MC0yOCA2OHQtNjggMjhoLTk2MHEtNDAgMC02OC0yOHQtMjgtNjh2LTI4OGgtNTQ0cS00MCAwLTY4LTI4dC0yOC02OHYtNjcycTAtNDAgMjAtODh0NDgtNzZsNDA4LTQwOHEyOC0yOCA3Ni00OHQ4OC0yMGg0MTZxNDAgMCA2OCAyOHQyOCA2OHYzMjhxNjgtNDAgMTI4LTQwaDQxNnptLTU0NCAyMTNsLTI5OSAyOTloMjk5di0yOTl6bS02NDAtMzg0bC0yOTkgMjk5aDI5OXYtMjk5em0xOTYgNjQ3bDMxNi0zMTZ2LTQxNmgtMzg0djQxNnEwIDQwLTI4IDY4dC02OCAyOGgtNDE2djY0MGg1MTJ2LTI1NnEwLTQwIDIwLTg4dDQ4LTc2em05NTYgODA0di0xMTUyaC0zODR2NDE2cTAgNDAtMjggNjh0LTY4IDI4aC00MTZ2NjQwaDg5NnoiLz48L3N2Zz4=', | |||
permission: true, | |||
version: packageJson.version, | |||
methods: ['getFolder', 'getCurrentFile', 'getFile', 'setFile', 'switchFile'], | |||
methods: ['file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'unlink', 'rename', 'readdir', 'rmdir'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readdir -> readDir
rmdir -> rmDir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the node api on filesystem use the lowercase here :
https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_fs_readdir_path_options_callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using node api filesystem as a standard for our new api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shame
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why they did half low case half uppercase???
src/app/files/fileManager.js
Outdated
* Emits error based on error code | ||
* @param {object} error error { code, message } | ||
*/ | ||
_handleError (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what;s the reason of having this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that errors have a uniform format and it is not just thrown anywhere in our codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds ok to me, what are the concern about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it adds nothing more to the throw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're doing three time the job.
For example if the mkdir
method throw, the message will be:
"File already exists Cannot create directory ${path}" with the first part beeing handle by the code & the second by the error. But still you have a method _handleExists
.
Either you have one method to handle all error with a mapping on the error code :
const errorMsg = {
ENOENT: 'No such file or directory',
...
}
const createError = (err) => new Error(`${errorMsg[err]} ${err.message || ''}`)
...
mkdir (path) {
if (this.exists(path)) {
throw createError({ code: 'EEXIST', message: `Cannot create directory ${path}` })
}
}
Or you have a named methods that take a string as argument :
_handleEnoent(msg) {
throw new Error('No such file or directory ' + msg);
}
Or you can use assert methods by merging check & error :
_assertExist(path, msg) {
if (....) {
throw new Error('No such file or directory ' + msg);
}
}
src/app/files/fileManager.js
Outdated
isFile (path) { | ||
const extension = path.split('/').pop() | ||
|
||
return extension && extension.indexOf('.') > -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can have browser/myfolder.is.cool folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you should ask provider for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
* @returns {boolean} true if the path exists | ||
*/ | ||
exists (path) { | ||
const provider = this.fileProviderOf(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not work like that, it will return localHost or current provider without checking for path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright.
src/app/files/fileManager.js
Outdated
rmdir (path) { | ||
this._handleExists(path, `Cannot remove directory ${path}`) | ||
this._handleIsDir(path, `Cannot remove directory ${path}`) | ||
// To implement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/app/files/fileManager.js
Outdated
if (this.exists(path)) { | ||
this._handleError({ code: 'EEXIST', message: `Cannot create directory ${path}` }) | ||
} | ||
// To implement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should do the trick window.remixFileSystem.mkdirSync
or look at https://github.com/ethereum/remix-ide/blob/master/src/app/files/fileProvider.js#L92 for recursively creating folder.
src/app/files/fileManager.js
Outdated
@@ -23,7 +23,7 @@ const profile = { | |||
icon: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB3aWR0aD0iMTc5MiIgaGVpZ2h0PSIxNzkyIiB2aWV3Qm94PSIwIDAgMTc5MiAxNzkyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xNjk2IDM4NHE0MCAwIDY4IDI4dDI4IDY4djEyMTZxMCA0MC0yOCA2OHQtNjggMjhoLTk2MHEtNDAgMC02OC0yOHQtMjgtNjh2LTI4OGgtNTQ0cS00MCAwLTY4LTI4dC0yOC02OHYtNjcycTAtNDAgMjAtODh0NDgtNzZsNDA4LTQwOHEyOC0yOCA3Ni00OHQ4OC0yMGg0MTZxNDAgMCA2OCAyOHQyOCA2OHYzMjhxNjgtNDAgMTI4LTQwaDQxNnptLTU0NCAyMTNsLTI5OSAyOTloMjk5di0yOTl6bS02NDAtMzg0bC0yOTkgMjk5aDI5OXYtMjk5em0xOTYgNjQ3bDMxNi0zMTZ2LTQxNmgtMzg0djQxNnEwIDQwLTI4IDY4dC02OCAyOGgtNDE2djY0MGg1MTJ2LTI1NnEwLTQwIDIwLTg4dDQ4LTc2em05NTYgODA0di0xMTUyaC0zODR2NDE2cTAgNDAtMjggNjh0LTY4IDI4aC00MTZ2NjQwaDg5NnoiLz48L3N2Zz4=', | |||
permission: true, | |||
version: packageJson.version, | |||
methods: ['getFolder', 'getCurrentFile', 'getFile', 'setFile', 'switchFile'], | |||
methods: ['file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'unlink', 'rename', 'readdir', 'rmdir'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is file
a replacement for getCurrentFile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not current or currentFile? does this come from nodejs as well?
from what i see, there's no issue with parameters ordering right? |
@LianaHus left a comment about |
Yes, i think parameters ordering is okay. |
src/app/files/fileManager.js
Outdated
*/ | ||
unlink (path) { | ||
this._handleExists(path, `Cannot remove file ${path}`) | ||
this._handleIsDir(path, `Cannot remove file ${path}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and window.remixFileSystem.unlinkSync(curPath, console.log)
should work for this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
btw I've put some comment about using |
de71b61
to
5f5bf40
Compare
6fde118
to
37f239a
Compare
src/app/files/file-explorer.js
Outdated
const removeFile = await fileManager.remove(key) | ||
|
||
if (!removeFile) { | ||
tooltip(`failed to remove file ${key}.`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be uppercase
@@ -62,7 +62,7 @@ | |||
"remix-solidity": "0.3.30", | |||
"remix-tabs": "1.0.48", | |||
"remix-tests": "0.1.33", | |||
"remixd": "0.1.8-alpha.10", | |||
"remixd": "0.1.8-alpha.16", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think lock file also needs to be checked in
src/app/panels/tab-proxy.js
Outdated
@@ -34,7 +34,7 @@ export class TabProxy { | |||
return | |||
} | |||
this.addTab(file, '', () => { | |||
this.fileManager.switchFile(file) | |||
this.fileManager.open(file) | |||
this.event.emit('switchFile', file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also change the name of event to openFile? 'switchFile' makes no sense anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that can be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yann300 Liana suggested we also rename switchFile
command for nightwatch to openFile
to avoid confusion. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for nightwatch or for all the codebase? (I mean for the event name too?)
If the changes are well scoped I think that makes sense. If there's a lot of internal rewording changes, I would suggest to split that for another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not so much a change. It can go in this PR.
846e429
to
7855c37
Compare
src/app/files/fileManager.js
Outdated
} | ||
const createError = (err) => { | ||
return new Error(`${errorMsg[err.code]} ${err.message || ''}`) | ||
} | ||
|
||
// File System profile | ||
// - methods: ['getFolder', 'getCurrentFile', 'getFile', 'setFile', 'switchFile'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please remove this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure
3c39f6b
to
2cf7ed5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to create a file with vyper and this is not working for me. could you please try this? I don't have any js error either
@LianaHus @ioedeveloper pretty sure it's because the old api has been removed https://github.com/ethereum/remix-ide/pull/2733/files#diff-f28e4232b4dbf7d53c7b5543bdc9ad4fR26 |
Should be merged after @remixproject/engine release ethereum/remix-plugin#208. |
dc55f61
to
129bf2e
Compare
Originally #2625