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

Untitled files aren't well supported in custom editors #114711

Closed
lramos15 opened this issue Jan 21, 2021 · 3 comments
Closed

Untitled files aren't well supported in custom editors #114711

lramos15 opened this issue Jan 21, 2021 · 3 comments
Assignees
Labels
custom-editors Custom editor API (webview based editors) *duplicate Issue identified as a duplicate of another issue(s) under-discussion Issue is under discussion for relevance, priority, approach
Milestone

Comments

@lramos15
Copy link
Member

The custom editor flow is normally as follows:

  1. User calls open with / the editor is the default editor
  2. The custom editor is passed a URI, normally a file URI but sometimes can be the untitled file
  3. The custom editor then utilizes various fs APIs to perform actions on that file URI.

This flow is of course broken when the URI passed in isn't a file URI as the custom editor can no longer utilize the fs APIs. We currently don't have a good story on how to handle untitled files in custom editors. Taking the hex editor for example, if the user calls reopen editor with -> hex editor on an untitled file the custom editor will crash due to the fs APIs failing. The current workaround is:

  1. Check the URI passed in to your custom editor to see if it is an untitled file
  2. Find the matching URI in vscode.workspace.textDocuments.
  3. Call .getText() on the matching text document.
  4. Convert that text into a Uint8Array as that is the form of data vscode.workspace.fs.readFile(uri) would normally return.
  5. When the user attempts to save, always trigger a saveAs.
@lramos15 lramos15 added the custom-editors Custom editor API (webview based editors) label Jan 21, 2021
@jrieken
Copy link
Member

jrieken commented Jan 22, 2021

@bpasero what's the deal with untitled files? Those are always text document, right? Who is owning them and disposing them?

@bpasero
Copy link
Member

bpasero commented Jan 22, 2021

Can we have a meeting rather than Q&A in this issue please with everyone involved, I am not up to speed with the issues around untitled and custom editors and would like to get a intro + discussion in person.

@mjbvz
Copy link
Collaborator

mjbvz commented Feb 23, 2021

Marking as a duplicate of #115631

@mjbvz mjbvz added the *duplicate Issue identified as a duplicate of another issue(s) label Feb 23, 2021
@mjbvz mjbvz modified the milestones: February 2021, Backlog Feb 23, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
custom-editors Custom editor API (webview based editors) *duplicate Issue identified as a duplicate of another issue(s) under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

4 participants