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

Unsafe canHandleResource usages #48275

Closed
jrieken opened this issue Apr 20, 2018 · 10 comments
Closed

Unsafe canHandleResource usages #48275

jrieken opened this issue Apr 20, 2018 · 10 comments
Assignees
Labels
debt Code quality issues remote Remote system operations issues
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Apr 20, 2018

We have RemoteFileService#canHandleResource which was introduced as workaround to be able to restore editors from providers that aren't known (yet) but that were around during the last session: https://github.com//Microsoft/vscode/commit/a23633b5d42dc486a668e49a232957696750c254.

This wasn't designed to be a general purpose API and I am surprised by its popularity. In hindsight the FileEditorInput should have serialised that knowledge about other-schemes and not the file service. I want to make that change but many other references leave me puzzled. This is what's to do

  • use canHandleResource in combination with onDidChangeFileSystemProviderRegistrations
  • don't rely on this information statically, e.g. expect that scheme come and do and expect that in the beginning there is just the file-scheme
@jrieken jrieken assigned bpasero and unassigned jrieken Apr 20, 2018
@jrieken jrieken added debt Code quality issues remote Remote system operations issues file-io File I/O labels Apr 20, 2018
jrieken added a commit that referenced this issue Apr 20, 2018
@jrieken
Copy link
Member Author

jrieken commented Apr 20, 2018

e.g. the ResourceContextKey seems to be misbehaving

@jrieken
Copy link
Member Author

jrieken commented Apr 20, 2018

@bpasero I have pushed b7e8a4f which changes the way in which file editor inputs get deserialised. i have tested things but please review/advise

@bpasero bpasero assigned bpasero and isidorn and unassigned bpasero Apr 20, 2018
@bpasero bpasero added this to the May 2018 milestone Apr 20, 2018
@bpasero
Copy link
Member

bpasero commented Apr 20, 2018

@jrieken yeah unhappy, I was assuming this would be a way to statically find out if a resource is supported in the file service or not, but I see how this is not true when remote file system providers come and go.

Also adding @isidorn for some places where we use this e.g. in the resource context key to adjust enablement for commands.

I need to revisit the file editor input serialisation and creation given this, but would like to keep using the createInput method for now because that one goes through a cache (here) so that we never have more than one input for the same file. While I don't think your change would cause much harm, I am a bit nervous with that change before end-game.

@isidorn
Copy link
Contributor

isidorn commented May 18, 2018

We were focused on grid this milestone, next week I am on vacation, this is not for endgame -> June

@isidorn isidorn modified the milestones: May 2018, June 2018 May 18, 2018
@isidorn isidorn modified the milestones: June 2018, July 2018 Jun 21, 2018
@bpasero
Copy link
Member

bpasero commented Jul 2, 2018

I have pushed a change that ensures a FileEditorInput can be created upon reload even if the file system provider is not loaded yet. I checked all usages of canHandleResource and think the only other unsafe usage is within ResourceContextKey#set() as indicated in #48275 (comment)

@isidorn I leave that one up to you to see what needs to be done

@bpasero bpasero removed their assignment Jul 2, 2018
@isidorn isidorn closed this as completed in f365098 Aug 2, 2018
@isidorn
Copy link
Contributor

isidorn commented Aug 2, 2018

I decided to remove resource.isFile context key completely. Reasons:

  1. most of the cases it was not properly used and a hasResource is more fitting
  2. it can be substituted with resource.scheme.isEqualTo('file')
  3. users found it confusing as they thought that this context key tells if the resource is not a directory

I will mention in the release notes that this context key is not removed ( I do not believe people are using it that often)

@isidorn
Copy link
Contributor

isidorn commented Aug 2, 2018

Went all over github and only two repos use "resourceIsFile" I will give them an issue.

isidorn added a commit that referenced this issue Aug 2, 2018
@isidorn isidorn added the release-notes Release notes issues label Aug 3, 2018
@jrieken jrieken assigned bpasero and unassigned isidorn Aug 6, 2018
@jrieken jrieken reopened this Aug 6, 2018
@jrieken
Copy link
Member Author

jrieken commented Aug 6, 2018

I still see (early) access to canHandleResource from the history service. It seems to delete entries before the extension host is ready, and therefore before file system providers have a chance to register.

screen shot 2018-08-06 at 10 46 55

There are also other usages but I they don't look critical... To reproduce, have a workspace with a remote fs entry (e.g MemFS), open a few files from that workspace, set a breakpoint here, and reload.

@jrieken jrieken modified the milestones: July 2018, August 2018 Aug 6, 2018
@bpasero bpasero removed file-io File I/O release-notes Release notes issues labels Aug 6, 2018
@jrieken
Copy link
Member Author

jrieken commented Aug 6, 2018

@isidorn re
#48275 (comment). There is a difference between having an uri (hasResource) and being able to save/load something with a resource, e.g. webview editors have an uri but they don't support things like load, save, revert etc.

screen shot 2018-08-06 at 17 29 53

@isidorn
Copy link
Contributor

isidorn commented Aug 22, 2018

@jrieken thanks, I have pushed a commit which improves this.
Added a new context isFileSystemResource, which now listenes to new fs registrations so the canHandleResource should always be correct.

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues remote Remote system operations issues
Projects
None yet
Development

No branches or pull requests

3 participants