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

[vscode] No error message if vscode.open command is invoked with reso… #6568

Closed
wants to merge 1 commit into from

Conversation

vrubezhny
Copy link
Contributor

@vrubezhny vrubezhny commented Nov 18, 2019

…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 of vscode.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

@akosyakov akosyakov added monaco issues related to monaco vscode issues related to VSCode compatibility labels Nov 18, 2019
@akosyakov
Copy link
Member

akosyakov commented Nov 18, 2019

Why should it be implemented in monaco extension generically, not in vscode.open? Monaco model should not be directly aware of the filesystem. It should be able to support other resource sources.

@vrubezhny
Copy link
Contributor Author

Why should it be implemented in monaco extension generically, not in vscode.open?

I have updated the PR, the implementation is moved to vscode.open.

@akosyakov
Copy link
Member

akosyakov commented Feb 25, 2020

@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.

@vrubezhny
Copy link
Contributor Author

@akosyakov I have updated the How to test description. Please verify if it is clear enough.

options = {
...columnOrOptions
};
const stat = await this.fileSystem.getFileStat(new TheiaURI(resource).toString());
Copy link
Member

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.

Copy link
Contributor Author

@vrubezhny vrubezhny Feb 28, 2020

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.

@vrubezhny vrubezhny force-pushed the et5667 branch 2 times, most recently from a730644 to c29970a Compare March 3, 2020 16:26
options = {
...columnOrOptions
};
if (await this.shouldCreateBeforeOpen(new TheiaURI(resource))) {
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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 () => {
Copy link
Contributor

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?

Copy link
Contributor Author

@vrubezhny vrubezhny Mar 4, 2020

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)

Copy link
Contributor Author

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;
Copy link
Member

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}`] })
Copy link
Member

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

@JonasHelming JonasHelming added the decision_needed issues that require decisions on ways forward (ex: if they should be updated or closed) label Mar 8, 2022
@tsmaeder
Copy link
Contributor

tsmaeder commented May 3, 2022

I'll have a look at this again.

@tsmaeder tsmaeder removed the decision_needed issues that require decisions on ways forward (ex: if they should be updated or closed) label May 3, 2022
@msujew
Copy link
Member

msujew commented Nov 14, 2022

@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.

@msujew msujew closed this Dec 13, 2022
FernandoAscencio added a commit to FernandoAscencio/theia that referenced this pull request Mar 7, 2023
This commit finishes imlementations of eclipse-theia#6568
This commit closes eclipse-theia#5667

Signed-Off-By: FernandoAscencio <fernando.ascencio.cama@ericsson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
monaco issues related to monaco vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[vscode] No error message if vscode.open command is invoked with resource that doesn't exist
5 participants