rafaelmaiolla / remote-vscode

A package that implements the Textmate's 'rmate' feature for Visual Studio Code.
MIT License
259 stars 33 forks source link

Bring VSCode window to foreground after opening remote file #48

Closed pe224 closed 6 years ago

pe224 commented 6 years ago

As a quick fix, this is (kinda hacky) done by launching VSCode via "code" by child_process. This was inspired by the solution of a similar plugin for SublimeText (see https://github.com/randy3k/RemoteSubl/blob/f131b3b8b7317ac06998f96e1b8095c9841b2e1a/remote_subl.py#L140-L141).

rafaelmaiolla commented 6 years ago

Unfortunately, this didn't work in my tests

Command seems to execute, but VSCode is not put on focus. I can't say what is missing.

Manually executing the command seems to work as expected.

pe224 commented 6 years ago

I have only tested in on Windows with an VSCode Insider build. So I had to actually use exec('code-insiders') instead of exec('code')

When you open a terminal (cmd in Windows or your favourite shell in Linux) and simply execute "code" (or "code-insiders"), does it open VScode? If yes, then I think the command should work.

Ideally, one needs to figure out (cross-platform) the path to the executable of VSCode (or at least if it's insider or not to use code or code-insiders) and execute that. Does e.g. the vscode module have any special methods for that? The full path would be best as then we would not need to rely on vscode/bin directory being in the PATH.

pe224 commented 6 years ago

In insiders, I noticed recentely this fix opens a new (empty) window. It can be corrected by including the --reuse-window (-r) flag so that an existing window is brought up. So exec("code") becomes exec("code -r")