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

Don't use findTreeItem in AzExtTreeFileSystem #1257

Merged
merged 5 commits into from
Dec 20, 2022

Conversation

alexweininger
Copy link
Member

We haven't gotten findTreeItem to work for v2 yet since tree item IDs haven't been ironed out. However, I'm proposing that we move away from using findTreeItem in AzExtTreeFileSystem. AzExtTreeFileSystem is one of the main places where findTreeItem is used.

vscode.FileSystemProvider relies on handling Uris within VS Code. Within the file system provider methods we need access to the tree item in order to read/write the file content. Currently, we're adding the tree item ID to the Uri query params, and then using findTreeItem to retrieve the tree item within the handler.

Although that works great, I found it sorta wasteful to use findTreeItem to retrieve a reference to an object that we already have when forming the Uri. Instead, I just store the tree item in a Map with a random key and pass the key in the Uri, eliminating the need for findTreeItem. This method is probably a bit faster too.

Drawbacks of this method include:

  • File system provider will not be able to handle URIs that have originated from this method and have tree items in the Map. This is fine since we currently don't support this anyway.

bwateratmsft
bwateratmsft previously approved these changes Dec 5, 2022
Base automatically changed from bmw/quickPick_v8.30 to main December 7, 2022 20:03
@alexweininger alexweininger force-pushed the alex/v2-AzExtTreeFileSystem branch from 5022ddb to 49904b4 Compare December 8, 2022 19:15
@alexweininger alexweininger force-pushed the alex/v2-AzExtTreeFileSystem branch from f6587b5 to 9d2f4db Compare December 20, 2022 21:04
@alexweininger alexweininger marked this pull request as ready for review December 20, 2022 21:12
@alexweininger alexweininger requested a review from a team as a code owner December 20, 2022 21:12
export abstract class AzExtTreeFileSystem<TItem extends AzExtTreeItem> implements FileSystemProvider {
export abstract class AzExtTreeFileSystem<TItem extends types.AzExtTreeFileSystemItem> implements FileSystemProvider {

private readonly itemCache: Map<string, TItem> = new Map<string, TItem>();
Copy link
Member

Choose a reason for hiding this comment

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

Should we clear and repopulate this every time a refresh happens? Seems like it could cause stale tree item ids if we're not careful.

Copy link
Member Author

@alexweininger alexweininger Dec 20, 2022

Choose a reason for hiding this comment

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

I haven't run into that in my testing, but I am worried about the possibility of something like that happening. The tree item ids correspond to Azure resource ids so unless something is deleted I think it's fine. I will test that now. I don't know if delete was handled properly in v1.

If you delete a resource while editing the tags it will show this error. I think that's fine behavior.
image

Copy link
Member Author

Choose a reason for hiding this comment

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

Also whenever I tried clearing this map, it resulted in errors since we can't really know if the items in the map are still in use easily.

Copy link
Member Author

Choose a reason for hiding this comment

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

A potential fix for all of this would be to really remove the reliance on items at all, and base if fully on URIs.

@nturinski
Copy link
Member

Oh, this is only for the FileSystem? So findTreeItem will still be used in normal TreeDataProviders?

@alexweininger
Copy link
Member Author

Oh, this is only for the FileSystem? So findTreeItem will still be used in normal TreeDataProviders?

Yes this PR is only removing the usage of findTreeItem (and anything AzExtTree* related for that matter) from the file system. Side note: maybe we should rename this class...

However, findTreeItem is still used in other places in the v1.5 client extensions. But we are not exposing a find API in v2. At least not yet. There's a chance we absolutely must add it when upgrading v1.5 extensions to v2. However we want to avoid this as much as we can because the whole find tree item thing is a bit problematic.

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

Successfully merging this pull request may close these issues.

3 participants