-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Extension Activation on web is not fired for each local folder opened #146868
Comments
I am not 100% familiar with what the workspace model is on the web and what occurs when opening a local folder. @bpasero @joaomoreno @sandy081 Does the workbench restart the web worker extension host when that happens?
Again I'm not 100% sure what the workbench does here @bpasero @joaomoreno @sandy081 ?
Again I don't know. @sandy081 ?
What are the exact steps to reproduce this? Maybe there is some race condition that is causing all these issues where you are observing an empty workspace while in fact the workspace has a local folder. 🤷 |
Hi @alexdima , First of all, thank you for the detailed explanation. I was aware VS Code internals should be complex, but never looked at the details.
I guess this point summarize my understanding of VS Code desktop. And that's exactly the behavior I think differs from the web. It seems the workbench is not reloading on the web, and as a result, the
A simple web extension would reproduce the issue
Thank you |
@alexdima as for restarting extension host when the first folder changes, please chime in to #69335 which discusses that and the consequences. I think that issue is currently not seeing any progress. Specifically there are calls to restart the extension host that are probably also going to restart the web worker (you would have to tell):
vscode/src/vs/workbench/services/workspaces/electron-sandbox/workspaceEditingService.ts Line 184 in 99ef899
That is when:
@alefragnani can you isolate this in a small sample to look at? |
Forgot to mention: when you open vscode.dev we immediately bring you into a multi root workspace that is empty. The reason is that MR workspaces are the only ones that allow to add and remove folders without reload and that is required for accessing local files. The MR workspace is a bit special in that it uses an in-memory fs provider, but that should not have any impact here. |
If it brings you an empty workspace, that's may be the reason why web and desktop is working different. @bpasero The sample extension I've created yesterday to isolate the steps is here https://github.com/alefragnani/vscode-test-web-workspace |
To clarify: we only force an empty MR workspace onto you for when you open vscode.dev / insiders.vscode.dev. Once you go to a remote, that changes. In other words, in web, without a server, the empty window experience is that empty MR workspace where you can open local folders in if the browser supports that. And when you do, immediately the first folder will change and thus most likely restart the extension host. On desktop, when you open a folder, the window reloads into that folder. So yeah, there is a difference. |
Well, if the extension host was restarted every time you change the first folder, the behavior would be similar to Desktop. I understand the reasons that motivated such differences, and when I noticed the I suggest to update the Update existing extensions to web extensions guide, to warn other extension authors about such differences. In fact, based on recent discussions we had on that unofficial Slack channel, FAQ and Know Issues sections would be of great value for newcomers. Thank you |
It is documented, no? vscode/src/vscode-dts/vscode.d.ts Lines 11328 to 11331 in b261d64
|
I'm referring to this activation difference between Desktop and Web. Not only on this API, but also on that guide I mentioned. |
Oh ok, to clarify: I was not talking about how activation works, I was only commenting that vscode.dev is a bit special that you are immediately put into an empty MR workspace. But a user could easily do the same on desktop when launching from the command line, so an extension has to be aware. |
About that, maybe I'm mistaken, but I have memories when multi-root workspaces was first released that the add/remove folders were firing the extension host restart. That's why my extension didn't have to deal with the But yeah, testing yesterday on Desktop, I've noticed the extension needs to be updated to properly support the |
Maybe https://github.com/microsoft/vscode/wiki/Adopting-Multi-Root-Workspace-APIs is still helpful. It is dated by now but the API never changed. |
Yeah...as I said, maybe I'm mistaken. In this case, I probably am 😆 |
@alefragnani Sorry for being so slow, this issue fell through the cracks. I'm trying the steps from here and have a few questions:
|
Hi @alexdima , no problem, and sorry for the delay to answer you as well 🤝 About the steps, in both cases (steps 6 & 7 and 20 & 21), I used I just repro the steps and the behavior seems to the same, so you should be able to reproduce it as well. Thank you |
@alefragnani Thank you for your answer. I tried selecting two different local folders using the When I try this, and press Open, on step 7 I see that the extension activates only once: |
@alexdima , sorry for the ambiguity in the steps. When I did say "opening two different local folders from my machine" I wasn't meaning a multi-select approach but instead, one folder at a time, so the second selection replaces the first. You could read the steps as: ... The same scenario for steps 20 & 21 Thank you |
Hey @alexdima, this issue might need further attention. @alefragnani, you can help us out by closing this issue if the problem no longer exists, or adding more information. |
I went through the steps again. Basically this issue is about:
@bpasero has confirmed that this is because on the web the workbench always runs in multi-root workspace mode:
So IMHO everything works as designed, I don't think there is anything actionable here. |
Does this issue occur when all extensions are disabled?: Yes/No
Steps to Reproduce:
Maybe. I'm missing something, but it seems the extension activation in web extensions works a bit different compared to desktop.
I mean, in desktop, the regular
activate
function is fired every time a workspace is opened, respecting of course what you defined inactivationEvents
. which in my case, is*
yet. In web (http://vscode.dev to be more precise), it seems the extension is activated only once when you navigate to http://vscode.dev. And no matter how many local folders you open, theactivate
function is not called anymore.I'm using the side load approach to test my extension in web, and noticed this behavior because I use
workspaceFolders
while in the activation event to manage some data used on my extension. In web, this is returningundefined
, even after I opened some local folder.I didn't find any documentation nor any issue that points to this behavior, so I wonder I’m doing something wrong.
On the other hand, I could see the
onDidChangeWorkspaceFolders
being fired when you open a different folder, but based on API Docs, this event should be fired only when you add/remove some folder from a workspace.Also, I’m not sure another issue is being caused by the side load approach (just like debugging extensions does) but the
activationEvents
is not being respected on web. I changed my extension toworkspaceContains:somefile
and it was activated even on an empty workspace.Thank you
The text was updated successfully, but these errors were encountered: