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

How can I call command in my extension? #8422

Closed
Tracked by #9044
taoqf opened this issue Apr 28, 2023 · 17 comments
Closed
Tracked by #9044

How can I call command in my extension? #8422

taoqf opened this issue Apr 28, 2023 · 17 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers
Milestone

Comments

@taoqf
Copy link

taoqf commented Apr 28, 2023

commands.executeCommand('remote-containers.reopenInContainer', xxx);
commands.executeCommand('remote-containers.attachToRunningContainer', xxx);

Is it possible I can do this and what are the arguments types?

@eleanorjboyd eleanorjboyd added the containers Issue in vscode-remote containers label May 1, 2023
@chrmarti
Copy link
Contributor

chrmarti commented May 2, 2023

'remote-containers.reopenInContainer' does not have any arguments. 'remote-containers.attachToRunningContainer' takes a container id or name as an optional argument.

@chrmarti chrmarti closed this as completed May 2, 2023
@chrmarti chrmarti added the *dev-question VS Code Remote development questions label May 2, 2023
@taoqf
Copy link
Author

taoqf commented May 4, 2023

Many thanks @chrmarti , what about

commands.executeCommand('remote-containers.startAndOpenFolder', xxx);
commands.executeCommand('remote-containers.openFolder', xxx);

@chrmarti
Copy link
Contributor

chrmarti commented May 4, 2023

These commands are not stable API. What are you trying to do?

@chrmarti chrmarti reopened this May 4, 2023
@taoqf
Copy link
Author

taoqf commented May 5, 2023

I want call devcontainers/cli to build dev container, then call commands.executeCommand('remote-containers.openFolder', xxx); to open the container.

@taoqf
Copy link
Author

taoqf commented May 5, 2023

It more like do the same thing reopen in container, but I want call it in my extension. and do some thing before/after the container opened, especially after that. If I call the reopen in container, vscode will reload, and I could not do any thing after that. so I want do these things by steps:

  1. do something.
  2. call cli to build container
  3. open container folder (or just attach to container, but then I should open my working folder after that by hand)
  4. do something else.

@chrmarti
Copy link
Contributor

chrmarti commented May 5, 2023

You could add the following to your package.json to make sure your extension can run after the window reload:

	"extensionKind": [
		"ui"
	],

You might have to add "*" to the activation events in the package.json to get it activated early on. (More specific activation events to avoid unnecessary activation are better performance-wise.)

@taoqf
Copy link
Author

taoqf commented May 5, 2023

Now I use pkg build cli into an executable app and in my extension i call it.
but even though I could not open remove folder. May I call commands.executeCommand('remote-containers.openFolder', xxx); ? what are the params?

@taoqf
Copy link
Author

taoqf commented May 8, 2023

I am failed with pkged cli on windows, macos too, only worked on linux. It seems node-pty is the issue I've got.
Is it possible to do this:

  1. commands.executeCommand('remote-containers.rebuildContainer', myWorkspaceFolder);
  2. commands.executeCommand('remote-containers.startAndOpenFolder', containerID);

@chrmarti
Copy link
Contributor

chrmarti commented May 9, 2023

See devcontainers/cli#498 (comment) on node-pty. You would have to run pkg for each platform.

commands.executeCommand('remote-containers.openFolder', xxx); might be the easiest to make it work (needs a change on our side first).

@andpiccione
Copy link
Member

commands.executeCommand('remote-containers.openFolder', xxx); might be the easiest to make it work (needs a change on our side first).

@chrmarti I have a similar problem and I would like to programmatically open a local folder in a devcontainer. If I use commands.executeCommand('remote-containers.openFolder', <folder-uri>); a new window is opened in the local filesystem, but not in the devcontainer (so, it seems to do the same as vscode.openFolder ?).

Would you know when you are planning to support opening a folder in a devcontainer using the remote contains API? I noticed similar issues related to the same in problem in the past:

Thanks in advance!

@chrmarti
Copy link
Contributor

@andpiccione If <folder-uri> is a local folder this should already work. I will fix the case where <folder-uri> is a folder on an SSH server when using Remote-SSH.

@chrmarti chrmarti added bug Issue identified by VS Code Team member as probable bug and removed *dev-question VS Code Remote development questions labels Jul 13, 2023
@chrmarti chrmarti added this to the July 2023 milestone Jul 13, 2023
@andpiccione
Copy link
Member

andpiccione commented Jul 13, 2023

@andpiccione If <folder-uri> is a local folder this should already work. I will fix the case where <folder-uri> is a folder on an SSH server when using Remote-SSH.

@chrmarti Maybe I'm doing something wrong, but it doesn't work as expected for me when <folder-uri> is a local folder.

To clarify, by running commands.executeCommand('remote-containers.openFolder', <folder-uri>); I would expect a new devcontainer (Docker container) to be created from the folder URI given.

However, the result of executing the command above is a new Visual Studio Code window with the folder referenced by <folder-uri> opened in the local filesystem (in my specific case, in WSL).

@andpiccione
Copy link
Member

@chrmarti Any updates on the above? Thanks!

@roblourens roblourens added verified Verification succeeded and removed verified Verification succeeded labels Jul 26, 2023
@roblourens
Copy link
Member

@chrmarti is out, I will reopen this just in case since it's not clear to me what's expected

@roblourens roblourens reopened this Jul 26, 2023
@roblourens roblourens removed this from the July 2023 milestone Jul 26, 2023
@roblourens roblourens added this to the August 2023 milestone Jul 26, 2023
@roblourens roblourens added the verification-found Issue verification failed label Jul 26, 2023
@chrmarti chrmarti modified the milestones: August 2023, On Deck Jul 27, 2023
@chrmarti chrmarti removed the verification-found Issue verification failed label Sep 28, 2023
@protection6 protection6 mentioned this issue Sep 29, 2023
@Simon-Count
Copy link

Simon-Count commented May 16, 2024

I have a similar issue, I'm trying to connect to an existing remote tunnel from my extension. I already know that GitHub was used to create the tunnel and I know the tunnel id, because my extension initialised it.

Does executeCommand('remote-tunnels.connectCurrentWindowToTunnel') take any input args so that I can skip asking the user again for things I already know?

@Simon-Count
Copy link

I have a similar issue, I'm trying to connect to an existing remote tunnel from my extension. I already know that GitHub was used to create the tunnel and I know the tunnel id, because my extension initialised it.

Does executeCommand('remote-tunnels.connectCurrentWindowToTunnel') take any input args so that I can skip asking the user again for things I already know?

@roblourens / @chrmarti any pointers would be greatly appreciated

@chrmarti
Copy link
Contributor

@Simon-Count Could you open a issue for the tunnel case?

@andpiccione If <folder-uri> is a local folder this should already work. I will fix the case where <folder-uri> is a folder on an SSH server when using Remote-SSH.

@chrmarti Maybe I'm doing something wrong, but it doesn't work as expected for me when <folder-uri> is a local folder.

To clarify, by running commands.executeCommand('remote-containers.openFolder', <folder-uri>); I would expect a new devcontainer (Docker container) to be created from the folder URI given.

However, the result of executing the command above is a new Visual Studio Code window with the folder referenced by <folder-uri> opened in the local filesystem (in my specific case, in WSL).

This works for me with a local folder:

await vscode.commands.executeCommand('remote-containers.openFolder', vscode.Uri.file('C:\\Users\\chrmarti\\devel\\test'));

And a WSL folder:

await vscode.commands.executeCommand('remote-containers.openFolder', vscode.Uri.file('\\\\wsl.localhost\\Ubuntu\\home\\chrmarti\\devel\\test'));

Closing again as fixed, let me know if this doesn't work.

@chrmarti chrmarti modified the milestones: On Deck, July 2023 May 27, 2024
@microsoft microsoft locked and limited conversation to collaborators Jul 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers
Projects
None yet
Development

No branches or pull requests

6 participants