Skip to content
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

Merged
merged 25 commits into from
May 27, 2020
Merged

Move filemanager api to new api #2733

merged 25 commits into from
May 27, 2020

Conversation

ioedeveloper
Copy link
Member

@ioedeveloper ioedeveloper commented Apr 15, 2020

Originally #2625

@@ -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'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readdir -> readDir
rmdir -> rmDir

Copy link
Collaborator

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

Copy link
Member Author

@ioedeveloper ioedeveloper Apr 15, 2020

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shame

Copy link
Collaborator

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???

* Emits error based on error code
* @param {object} error error { code, message }
*/
_handleError (error) {
Copy link
Collaborator

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?

Copy link
Member Author

@ioedeveloper ioedeveloper Apr 15, 2020

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.

Copy link
Collaborator

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?

Copy link
Collaborator

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

Copy link
Collaborator

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);
  }
}

isFile (path) {
const extension = path.split('/').pop()

return extension && extension.indexOf('.') > -1
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Member Author

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)
Copy link
Collaborator

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright.

rmdir (path) {
this._handleExists(path, `Cannot remove directory ${path}`)
this._handleIsDir(path, `Cannot remove directory ${path}`)
// To implement
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (this.exists(path)) {
this._handleError({ code: 'EEXIST', message: `Cannot create directory ${path}` })
}
// To implement
Copy link
Collaborator

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.

@@ -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'],
Copy link
Collaborator

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is.

Copy link
Collaborator

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?

@yann300
Copy link
Collaborator

yann300 commented Apr 15, 2020

from what i see, there's no issue with parameters ordering right?

@ioedeveloper
Copy link
Member Author

ioedeveloper commented Apr 15, 2020

@LianaHus left a comment about _handle_error function, What do you think about it? @yann300 @GrandSchtroumpf

@ioedeveloper
Copy link
Member Author

from what i see, there's no issue with parameters ordering right?

Yes, i think parameters ordering is okay.

*/
unlink (path) {
this._handleExists(path, `Cannot remove file ${path}`)
this._handleIsDir(path, `Cannot remove file ${path}`)
Copy link
Collaborator

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

@yann300
Copy link
Collaborator

yann300 commented Apr 15, 2020

btw I've put some comment about using window.remixFileSystem.* . Not saying that we should put window.remixFileSystem.* call in the fileManager. These call should stay in the fileProvider.js .
But that will probably require some changes in fileProvider.js

const removeFile = await fileManager.remove(key)

if (!removeFile) {
tooltip(`failed to remove file ${key}.`)
Copy link
Collaborator

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

src/app/files/fileManager.js Show resolved Hide resolved
@@ -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",
Copy link
Collaborator

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

@@ -34,7 +34,7 @@ export class TabProxy {
return
}
this.addTab(file, '', () => {
this.fileManager.switchFile(file)
this.fileManager.open(file)
this.event.emit('switchFile', file)
Copy link
Collaborator

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

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Collaborator

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.

Copy link
Member Author

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.

}
const createError = (err) => {
return new Error(`${errorMsg[err.code]} ${err.message || ''}`)
}

// File System profile
// - methods: ['getFolder', 'getCurrentFile', 'getFile', 'setFile', 'switchFile']
Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure

@ioedeveloper ioedeveloper removed the WIP label May 19, 2020
Copy link
Collaborator

@LianaHus LianaHus left a 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

@yann300
Copy link
Collaborator

yann300 commented May 20, 2020

@ioedeveloper
Copy link
Member Author

ioedeveloper commented May 21, 2020

Should be merged after @remixproject/engine release ethereum/remix-plugin#208.

@yann300 yann300 merged commit ecdd1fb into master May 27, 2020
@yann300 yann300 deleted the filemanager-api branch May 27, 2020 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants