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

Fix 'window.showTextDocument' to open resources with 'untitled' schema #6803

Merged
merged 1 commit into from
Feb 24, 2020

Conversation

ShimonBenYair
Copy link
Contributor

@ShimonBenYair ShimonBenYair commented Dec 31, 2019

Fixes #6565

Signed-off-by: Shimon Ben Yair [email protected]

What it does

Currently "window.showTextDocument" Does Not open Resources With "untitled" Scheme.
i.e. Using the following code :
const fileUri = Uri.parse(untitled:${uri}).with({ scheme }); await window.showTextDocument(fileUri);
does not open a file in Theia an raises an error.
With changes in this pull request, when calling the above API a file is created and the user can modify and save the file with no problems.
This pull request Fixes #6565 bug.

How to test

  1. Add this SQLTools extension (current version 0.21.5) under your plugins folder in Theia.
    sqltools-0.21.5.zip

  2. Create in workspace/theia a new file called "tom.db".
    3.Add to User preferences the following values:
    {
    "sqltools.useNodeRuntime": true,
    "sqltools.dependencyManager": {
    "autoAccept": true
    },
    "sqltools.connections": [
    {
    "name": "sqlite",
    "dialect": "SQLite",
    "database": "workspace/theia/tom.db"
    }
    ]
    }
    image

  3. Click on SQLTools extension.

  4. In "sqlite" linem, click on connect:
    image

When clicking on the "connect" button , code similar to the following is executed :
const uri = vscode.Uri.file(os.homedir + '/newnew.txt'); const fileUri = vscode.Uri.parse(untitled:${uri}).with({ scheme: 'untitled' }); vscode.window.showTextDocument(fileUri);

  1. Verify a file called "sqlite Session.sql" was created and opened.
  2. Modify this file (write something and save) and verify there are no exceptions and errors.

showTextDocument_bug_fix

I have found some more issues in this code but as their fix is not required for this feature, it is out of the scope of this pull request.

Review checklist

Reminder for reviewers

@ShimonBenYair
Copy link
Contributor Author

@akosyakov
please review

@ShimonBenYair ShimonBenYair changed the title Fix 'window.showTextDocument' to open resources with 'untitled' schem… Fix 'window.showTextDocument' to open resources with 'untitled' schema Dec 31, 2019
@akosyakov akosyakov added the vscode issues related to VSCode compatibility label Jan 1, 2020
@akosyakov
Copy link
Member

akosyakov commented Jan 1, 2020

With changes in this pull request, when calling the above API a file is created and the user can modify and save the file with no problems.

I thought that untitled resources should not have physical representation till a user explicitly saved them? If a user just close the editor without saving then there should not be a trace of the file? cc @amiramw @TomHermanSAP @offer8

It would be nice if someone setups simple VS Code extension to manipulate resource with untitled schema. And then run it against VS Code and Theia to make sure that resources are treated the same. Running the sql extension is overkill.

@@ -221,6 +221,7 @@ export class DocumentsExtImpl implements DocumentsExt {
// return opened document
return document;
} catch (error) {
console.log(error);
Copy link
Member

Choose a reason for hiding this comment

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

left overs? Should not it be handled by clients since we throw it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, fixed

@akosyakov
Copy link
Member

@ShimonBenYair btw i thought @amiramw @TomHermanSAP @offer8 were working on it, please give a notice that you want to work on something which is obviously in discussions to avoid duplicate effort

@amiramw
Copy link
Member

amiramw commented Jan 1, 2020

@ShimonBenYair is in our team so we are all synced. Sorry for the confusion.

@akosyakov
Copy link
Member

akosyakov commented Jan 1, 2020

@amiramw ok, thanks for letting to know. Could you take care about the review please and testing that it is aligned with VS Code interpretation of untitled schema? Don't get why i cannot assign you as a reviewer. I was pretty sure that you are an Eclipse Theia committer.

@amiramw
Copy link
Member

amiramw commented Jan 1, 2020

Sure

@ShimonBenYair
Copy link
Contributor Author

With changes in this pull request, when calling the above API a file is created and the user can modify and save the file with no problems.

I thought that untitled resources should not have physical representation till a user explicitly saved them? If a user just close the editor without saving then there should not be a trace of the file? cc @amiramw @TomHermanSAP @offer8

It would be nice if someone setups simple VS Code extension to manipulate resource with untitled schema. And then run it against VS Code and Theia to make sure that resources are treated the same. Running the sql extension is overkill.

After consulting with @amiramw i have fixed it so now when calling the 'vscode.window.showTextDocument' API with 'untitled' schema,the untitled resource will not have physical representation till the user will save it

@akosyakov
Copy link
Member

VS Code uses the save file dialog to let a user to pick the proper file name, why we cannot do the same with https://github.com/eclipse-theia/theia/blob/master/packages/filesystem/src/browser/file-dialog/file-dialog-service.ts#L63?

@akosyakov
Copy link
Member

@chrisguindon @eclipsewebmaster Some committers don't seem to belong to Eclipse Theia org, for example @amiramw. Is it the issue with sync script or some actions are expected from the committer?

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

It still does not behave like in VS Code and create a file with weird name instead of using a file dialog. Is it on purpose or there are some technical limitations to implement it properly?

@chrisguindon
Copy link
Member

@chrisguindon @eclipsewebmaster Some committers don't seem to belong to Eclipse Theia org, for example @amiramw. Is it the issue with sync script or some actions are expected from the committer?

From what I can tell, @amiramw is a committer on the project: https://accounts.eclipse.org/users/amiramw#tab-projects

@amiramw
Copy link
Member

amiramw commented Jan 16, 2020

@chrisguindon my issue was resolved after i fixed my github id in eclipse profile

@akosyakov
Copy link
Member

It still does not behave like in VS Code and create a file with weird name instead of using a file dialog. Is it on purpose or there are some technical limitations to implement it properly?

@amiramw @ShimonBenYair Could you elaborate on it? We have FileDialogService, it should not be a problem to insert it in UntitledResourceResolver and prompt a user on saveContent method?

@akosyakov
Copy link
Member

Merge branch 'master' into untitledShimon

please use fetch + rebase (not merge) to keep the history straight, please see https://github.com/eclipse-theia/theia/blob/master/doc/pull-requests.md#checklist-commit-history

@amiramw
Copy link
Member

amiramw commented Jan 21, 2020

@amiramw @ShimonBenYair Could you elaborate on it? We have FileDialogService, it should not be a problem to insert it in UntitledResourceResolver and prompt a user on saveContent method?

In the original issue vscode API was called with uri already so when the untitled document is saved there is no file save dialog.
@akosyakov are you aware of a vscode API where untitled is opens without uri so that the file dialog should open on save?

@akosyakov
Copy link
Member

@ShimonBenYair @amiramw there is this path: https://github.com/ShimonBenYair/theia/blob/7e2e4afd88d18c7365cee7c03588c0a00600779a/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts#L141-L143

What happens if VS Code extension calls this command workbench.action.files.newUntitledFile ? Anyway If you are saying that there is not save dialog, then filing an issue workbench.action.files.newUntitledFile could be enough for now if it requires the save dialog.

Please though address remaining comments before landing.

@amiramw
Copy link
Member

amiramw commented Jan 22, 2020

@akosyakov it seems that after the below code in the VS Code extension, fileUri contains inline a uri with schema "file".

const uri = vscode.Uri.file(os.homedir + '/newnew.txt');
const fileUri = vscode.Uri.parse(`untitled:${uri}`).with({ scheme: 'untitled' });

If we want to be generic to other schemas (inside untitled schema) then we should not hold FileResourceResolver but should hold ResourceProvider and call its getter to get any underlined resource upon change.

Does it seem ok with you or untitled resource and file resolved are coupled by definition?

@ShimonBenYair
Copy link
Contributor Author

yes, if changes to part outside of the plugin system are reverted, we can redesign it is later. Is it really important issue? Why a user will try to open already opened file?

So maybe I shall remove from the PR the part that tries to handle the tab duplication and open a new issue for it with minor priority ?

@akosyakov
Copy link
Member

So maybe I shall remove from the PR the part that tries to handle the tab duplication and open a new issue for it with minor priority ?

yes, it was my suggestion, we don't affect anything, it still works for you to some extent and we can redesign it in another PR

@ShimonBenYair
Copy link
Contributor Author

So maybe I shall remove from the PR the part that tries to handle the tab duplication and open a new issue for it with minor priority ?

yes, it was my suggestion, we don't affect anything, it still works for you to some extent and we can redesign it in another PR

Ok i will update the PR

@ShimonBenYair
Copy link
Contributor Author

@akosyakov
PR was updated
please review

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

code-wise it looks good, except one comment

someone has to test that it does what expected, cc @amiramw

@akosyakov
Copy link
Member

@ShimonBenYair Please file an issue for duplicate editors? I think we need a general issue to support untitled editors properly in core. And think about the holistic design instead of trying to fix it as a separate case in the plugin system.

@amiramw
Copy link
Member

amiramw commented Feb 18, 2020

I will test it later this week.

@akosyakov
Copy link
Member

@ShimonBenYair Just noticed that not all Resource APIs were covered: https://github.com/eclipse-theia/theia/blob/master/packages/core/src/common/resource.ts#L40 resourceVersion, onDidChangeContents and guessEncoding are missing.

@ShimonBenYair
Copy link
Contributor Author

ShimonBenYair commented Feb 19, 2020

@ShimonBenYair Just noticed that not all Resource APIs were covered: https://github.com/eclipse-theia/theia/blob/master/packages/core/src/common/resource.ts#L40 resourceVersion, onDidChangeContents and guessEncoding are missing.

@akosyakov
I saw that those methods are optional and that not all the classes that implements 'Resource' implements them. e.g.
https://github.com/eclipse-theia/theia/blob/master/packages/debug/src/browser/debugresource.ts#L23

https://github.com/eclipse-theia/theia/blob/master/packages/java/src/browser/java-resource.ts#L24

Are you sure i need to implement them on UntitledResource ?
Also for example, the guessEncoding method of the file-resource.ts calls the 'filesystem.gueseEncoding' method (Guess encoding of a given file based on its content) but our untitled resource does not have yet a representation in the file system.

What is the 'onDidChangeContents' responsible for ? ( i didn't find any documentation for it and i was not able to stop there when setting a breakpoint) .
What do i need to implement in 'onDidChangeContents' ?

@akosyakov
Copy link
Member

@ShimonBenYair UntitledResource should implement everything which is implemented by FileResource to support it completely, otherwise it will misbehave. When it does not have representation on the file disk it should return nothing. onDidChangeContents is responsible to notify then resource is changed, i.e. file is changed outside of Theia.

@ShimonBenYair
Copy link
Contributor Author

ShimonBenYair commented Feb 21, 2020

@ShimonBenYair UntitledResource should implement everything which is implemented by FileResource to support it completely, otherwise it will misbehave. When it does not have representation on the file disk it should return nothing. onDidChangeContents is responsible to notify then resource is changed, i.e. file is changed outside of Theia.

done
Please merge this PR

@ShimonBenYair
Copy link
Contributor Author

@akosyakov

please review again
I have fixed everything
please merge

@akosyakov
Copy link
Member

akosyakov commented Feb 24, 2020

please merge

@ShimonBenYair just to be clear, i'm not trying to prevent your progress or something like that. Each time when I look I find something like it will leak memory, it will ignore changes on the disk and so on. When I see that it does not break, then I merge.

Code looks good now, I'm going to test it and if it is fine I merge it. We have a rule that we don't merge things which were tested only by the author: https://github.com/eclipse-theia/theia/blob/master/doc/pull-requests.md#landing-pr That's why asked someone else to test it.

@akosyakov
Copy link
Member

Tested, it behaves well, did not find memory leaks and it reacts to changes on the disk as well.

The only error was:

root ERROR [hosted-plugin: 10377] Promise rejection not handled in one second: Error: Command with id 'SQLTools.getConnectionStatus' is not registered. , reason: Error: Command with id 'SQLTools.getConnectionStatus' is not registered.
With stack trace: Error: Command with id 'SQLTools.getConnectionStatus' is not registered.
    at CommandRegistryMainImpl.<anonymous> (https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/60.bundle.js:2027:35)
    at step (https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/60.bundle.js:1938:23)
    at Object.next (https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/60.bundle.js:1919:53)
    at https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/60.bundle.js:1913:71
    at new Promise (<anonymous>)
    at push.../../packages/plugin-ext/lib/main/browser/command-registry-main.js.__awaiter (https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/60.bundle.js:1909:12)
    at CommandRegistryMainImpl.push.../../packages/plugin-ext/lib/main/browser/command-registry-main.js.CommandRegistryMainImpl.$executeCommand (https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/60.bundle.js:2020:16)
    at RPCProtocolImpl.push.../../packages/plugin-ext/lib/common/rpc-protocol.js.RPCProtocolImpl.doInvokeHandler (https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/39.bundle.js:849:23)
    at RPCProtocolImpl.push.../../packages/plugin-ext/lib/common/rpc-protocol.js.RPCProtocolImpl.invokeHandler (https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/39.bundle.js:834:41)
    at RPCProtocolImpl.push.../../packages/plugin-ext/lib/common/rpc-protocol.js.RPCProtocolImpl.receiveRequest (https://3000-e0a15803-6cd7-4df2-8e51-fd074f296fde.ws-eu01.gitpod-staging.com/39.bundle.js:798:31)

It is unrelated to the PR, it would be worth to file a PR to fix it as well.

@akosyakov akosyakov merged commit 0efc669 into eclipse-theia:master Feb 24, 2020
@akosyakov
Copy link
Member

@ShimonBenYair opening follow-up issues would be good, about missing commands and duplicate editors for untitled and file schemes for the same path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"window.showTextDocument" Does Not open Resources With "untitled" Scheme
4 participants