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

Enforce editor options from lists/trees in extension commands #109947

Closed
wants to merge 1 commit into from

Conversation

bpasero
Copy link
Member

@bpasero bpasero commented Nov 4, 2020

This is a continuation of #109779 specifically for extensions (see #85636 and #101522).

We have 3 built in components that open editors from tree usages:

  • custom trees (e.g. references view)
  • timeline
  • changes view

None of these currently have a way to enforce our list/tree options, specifically wether to:

  • preserve focus
  • open pinned or as preview
  • open to the side

We discussed this in the API call yesterday and concluded that we should build a solution that does not require any adoption because we know an adoption will not happen for all extensions.

As such, if we keep the context of the user gesture for the duration of the command invocation and enforce it in very specific dedicated places where we know that an editor opens (vscode.open, vscode.diff), we can solve this for most cases.

My first solution was to add this entirely into mainThreadEditors but I felt it is wrong that e.g. custom trees, timeline and changes view depend on it. So now I made this API in IListService and want to put it out here to get some initial feedback. A slight variant I had in mind but did not push for is to let the IListService itself remember each open event for a specific duration, but that also felt wrong given that we only need this in very few places and not all trees/lists.

@joaomoreno mainly asking you for feedback if this direction is OK from the POV of list service and @jrieken for the hook in the extension commands (vscode.open, vscode.diff)

//cc @eamodio @alexr00

@bpasero bpasero added this to the November 2020 milestone Nov 4, 2020
@bpasero bpasero self-assigned this Nov 4, 2020
@bpasero bpasero requested review from joaomoreno and jrieken November 4, 2020 07:37
/**
* Remember the last `IOpenEvent` that occured.
*/
setOpenContext(context: IOpenEvent<unknown>): IDisposable;
Copy link
Member

Choose a reason for hiding this comment

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

Could we move something like this directly into the IOpenerService? That already knows OpenOption. With that the service could handle everything internally and the commands wouldn't be required to know this (tho the command do need some tweak so that they don't use the editor service directly).

Copy link
Member Author

Choose a reason for hiding this comment

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

@jrieken isn't that risking the exposure of this "hack" to anyone that uses the opener service? What I like about this approach is that it is exclusively used for the 2 commands and nothing else and we know only extensions can call it.

Copy link
Member

Choose a reason for hiding this comment

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

With that it is definitely widely available but I don't see it as a hack but as something really nice. Thinking of all the bugs I have fixed for "internal" features like outline, peek, go-to-links etc I would have really wanted this automagic behaviour a couple of years back.

Tho, fine for me if you wanna keep it local (at least for now) but I think this approach is actually good and we should use it internally as well

@bpasero
Copy link
Member Author

bpasero commented Nov 4, 2020

Talked with Joao and we feel that an explicit API might still be beneficial, I suggest to talk about it again in the next API sync to get to some conclusion.

Copy link
Member

@joaomoreno joaomoreno left a comment

Choose a reason for hiding this comment

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

The async nature of commands is what will kill us here. A command's open context will leak onto the following command, if the first takes a while to complete, which happens much more often than we'd hope. This will create issues of once a week my editor doesn't open in preview, which will be hard to reproduce and straight up impossible to fix.

I'm much more in favor of a solution which requires extension adoption, since only that can give us a fool proof solution, as far as I can see. I don't fear API adoption: given we have such a lively extension ecosystem, adoption will come fast.

@jrieken
Copy link
Member

jrieken commented Nov 4, 2020

This will create issues of once a week my editor doesn't open in preview, which will be hard to reproduce and straight up impossible to fix.

This is not impossible because we know which extension has triggered the open-command and we can always install the 'extra open args' for a specific extension only. For this exploration, in the name of simplicity, we decided to skip that but we have all the information at hand

@bpasero
Copy link
Member Author

bpasero commented Nov 4, 2020

This is not impossible because we know which extension has triggered the open-command and we can always install the 'extra open args' for a specific extension only.

That will not help for the case which imho is also the most likely one: you see a tree from 1 extension and interact with it multiple times with multiple items in short time frame. Chances are high that if the opening takes long, the context we set is always wrong.

@jrieken
Copy link
Member

jrieken commented Nov 4, 2020

You mean the user clicks fives times before the first open-command is triggered from the extension? A stack would help. The UI could do nothing while the command is still running, e.g not dispatch another event. I don't know but I don't see real road blockers here, sure things get more complex to implement but not impossible. But what I do not share is the optimistic expectation that extension author jump on adopting an API change quickly - if you ask me it's too niche for that.

@joaomoreno
Copy link
Member

joaomoreno commented Nov 4, 2020

A stack won't help, since commands don't finish in the reverse order they started executing...

Blocking UI events while commands don't complete is even more mind boggling to me. Isn't this just asking for trouble? 🤔 We could potentially block actual important UI interactions just because git show takes 5 seconds to complete which, believe me, happens more often that you'd expect.

I really don't buy it. In order to close the editor doesn't open as I want it to issue, you're gonna just open another one editor sometimes doesn't open as I want it to. Total number of issues stays the same...

@jrieken
Copy link
Member

jrieken commented Nov 4, 2020

We could potentially block actual important UI interactions just because git show takes 5 seconds to complete which, believe me, happens more often that you'd expect.

I don't think that we are on the same page. This has nothing to do with blocking the UI but with sequentialising things (e.g how we do it for save): when running the command for some node is slow then nothing is "blocked" but the next invocation for that exact node waits for the previous to finish. One could argue it's a bug that the UI doesn't show that the command is taking a long time.

@bpasero
Copy link
Member Author

bpasero commented Nov 10, 2020

Closing, as we don't seem to be pushing on this solution.

@bpasero bpasero closed this Nov 10, 2020
@bpasero bpasero deleted the ben/list-open-context branch November 10, 2020 09:49
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants