-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[vscode] No error message if vscode.open command is invoked with reso… #6568
Conversation
Why should it be implemented in monaco extension generically, not in |
I have updated the PR, the implementation is moved to |
@vrubezhny thank you! Could you update a description please with test steps? It looks very empty right now. Defining it is very important for next time when we are going to change this code. |
@akosyakov I have updated the |
options = { | ||
...columnOrOptions | ||
}; | ||
const stat = await this.fileSystem.getFileStat(new TheiaURI(resource).toString()); |
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.
resource is not necessary file URIs, it can be any URI supported by extension, i.e. gitlens contribute special schemes. It would break all such extensions.
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 found that gitlens
tries to invoke vscode.open
at least in case the uri.scheme === "gitlens"
or in case it wasn't able to open a given URI as a Text Document.
So, it looks like it delegates to vscode.open
to take care of any URIs it cannot open by itself.
As I cannot check existence of / create document for any uri.scheme
I suggest to make the existence check only for the documents with uri.scheme === "file"
while delegating it transparently to vscode.open
for any other uri.scheme
.
a730644
to
c29970a
Compare
options = { | ||
...columnOrOptions | ||
}; | ||
if (await this.shouldCreateBeforeOpen(new TheiaURI(resource))) { |
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 don't think we need to convert the URI here. The only stuff we need is #scheme and #toString(), both of which are availble on the URI type.
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, you're right.
I changed the argument of shouldCreateBeforeOpen
to be URI
instead of TheiaURI
in updated PR
if (stat.isDirectory) { | ||
return stat; | ||
} | ||
return this.getOrCreateDirectory(uri.parent); |
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.
Not sure what you're trying to achieve here.
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.
In case the URI contains a path to a not existing file that should be placed in some not existing folder tree, then we have to create the required folders before creating the file itself. Don't we?
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 don't think the logic is right here: if something exists, but it's not a directory we should fail. But anyway I think the node file system will create any required parents of a new directory already, no need to implement this yourself.
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 was wrong. No need to create the sub-directories in recursion.
if (res === 'CREATE') { | ||
this.getOrCreateDirectory(uri.parent).then(parent => { | ||
if (parent) { | ||
this.fileSystem.createFile(resource.toString()).then(async () => { |
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 if you try to create this in a place where you don't have permission? Do you know what VS code does in that 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.
For me it prints an error to console:
root ERROR Request createFolder failed with error: EACCES: permission denied, mkdir '/home/jeremy1' Error: EACCES: permission denied, mkdir '/home/NotExistingUser'
No error messages in Theia IDE.
And it's able to create a file in a folder that is placed somewhere outside of the workspace (if permissions allow creating a folder/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.
In case te required file cannot be created vscode shows an error message like: Unable to write file '/home/wrongUser/projects/project/aFile.ts'
. So, I've added a similar error processing.
…urce that doesn't exist eclipse-theia#5667 Fixes eclipse-theia#5667 Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
protected async shouldCreateBeforeOpen(uri: URI): Promise<boolean> { | ||
// Do not try to create a document which scheme is not a file | ||
if (uri.scheme !== 'file') { | ||
return false; |
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 we should do #7127 after that we will have the proper file system API which respect all kind of schemes.
const uri = new TheiaURI(resource); | ||
const msg = `Unable to open '${uri.displayName}': Unable to read file '${uri.path}'`; | ||
const createButton = 'Create File'; | ||
this.messages.showMessage({ type: MessageType.Error, text: msg, actions: [`${createButton}`] }) |
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.
please use async/await
not promise chaining, it is easy to read
I'll have a look at this again. |
@tsmaeder Does it make sense to simply close this PR? We cannot easily merge it anyway due to merge conflicts and I don't expect the original contributor to get back to this. If anyone is interested in contributing this fix, they can use the changes in this PR to create a new PR. |
This commit finishes imlementations of eclipse-theia#6568 This commit closes eclipse-theia#5667 Signed-Off-By: FernandoAscencio <fernando.ascencio.cama@ericsson.com>
…urce that doesn't exist #5667
Fixes #5667
Signed-off-by: Victor Rubezhny vrubezhny@redhat.com
What it does
The fix adds an error message to be shown in case a file to open doesn't exist and button
Create
that allows a user to create a new file with the same path and name as originally requested.How to test
A test extension [1] provided by @tolusha is used to test this fix.
The error message appearance can be tested using the extension [1] as is by finding and executing
Open Some File
command provided by the extension.In order to test creation of a file, before loading the extension, one needs to edit
/extension/out/extension.js
in order to specify an URI with an absolute path that is to be inside the test workspace instead ofvscode.Uri.file('/bla-bla')
, for example,vscode.Uri.parse('file:///home/user/projects/theia/test-workspace/bla0/bla1/bla2/bla-file.ts')
, where:file:///home/user/projects/theia/test-workspace/
path to a workspace to open in Theia,bla0/bla1/bla2/bla-file.ts
relative path part for not existing file to be opened[1] https://github.com/tolusha/vscode-test-extensions/blob/master/open-some-file-0.0.1.vsix
Review checklist
Reminder for reviewers