Search Issue Tracker

Fixed in 1.1.3

Votes

47

Found in [Package]

1.1.0

Issue ID

1183165

Regression

No

[VSCode] A Script fails to open when External Script Editor is set to code.exe

Package: VS Code

-

How to reproduce:
1. Open the "VSCode_issue" project using the EnvIronman VM
2. Make sure the External Script Editor is set to code.exe
3. Open any script in the Project window

Expected results: A script is opened without any issues
Actual results: A script is not opened, code.exe is visible in the Task Manager

Reproducible with: 2019.2.0a12, 2019.2.7f2, 2019.3.0b4, 2020.1.0a5 (package ver. 1.1.0, 1.1.2)

Additional notes:
1. 2019.2.0a12 is the version where VSCode package has been introduced
2. After reproducing the issue, scripts won't open even when opening them directly via right-click -> Open With... -> Visual Studio Code
3. No Visual Studio Code instance may be visible in the Task Manager, but the cursor's spinning wheel animation will indicate that something is loading
4. The issue is reproducible with Visual Studio Code version 1.38.1 with Unity Debugger Extension enabled
5. The issue does reproduce when External Script Editor is set via Browse...-> <Path to code.exe>

Comments (13)

  1. coolguyjoey

    Jun 03, 2020 19:57

    None of the method mentioned above worked for me unfourtunately. Had to uninstall and reinstall VScode, which is annoying. It happened twice so far already.

  2. EugeneJefferson

    Nov 30, 2019 03:16

    This one fixed my problem.

    Setting C:\Users\<USER>\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd instead of code.exe works fine for me.

    Thanks A-DIBACCO

  3. a-dibacco

    Nov 17, 2019 22:22

    Setting C:\Users\<USER>\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd instead of code.exe works fine for me.

  4. jacasch

    Nov 12, 2019 13:00

    For me it didnt work after updating to 1.1.3.
    I fiexed it by also deleting all registry entries starting with vscode under \HKEY_CURRENT_USER\Software\Unity Technologies\Unity Editor 5.x

  5. Incode

    Oct 30, 2019 18:38

    It seems like this is fixed in the latest package 1.1.3, a conditional statement was added to use ProcessWindowStyle.Normal if opening with .exe.

  6. Macklin

    Oct 06, 2019 00:22

    ...Though this assumes that you still have the .exe set - otherwise a command prompt (the running cmd file) will also be shown.

    (I really wish comments were shown oldest to newest, instead of the opposite)

  7. Macklin

    Oct 06, 2019 00:13

    @Bunderant Until they update the package, you can also manually fix it by editing VSCodeScriptEditor.cs (as I describe below - it's literally changing one value). It's in com.unity.ide.vscode in the packages section at the bottom of the Project view.

  8. Bunderant

    Oct 03, 2019 22:44

    @macklin, thanks so much for digging into this. Killing the accumulated VS Code processes allowed me to finally open the solution correctly. I'd also changed the editor target to the .cmd file rather than the .exe as you suggested.

    I had originally restarted my computer before creating a new project to reproduce the bug, and it just worked. So, I then recreated another empty project only to see the bug immediately turn up yet again. I was about to lose my mind, looks like those zombie processes were the culprit. Again, thanks for restoring my sanity.

  9. Macklin

    Oct 02, 2019 17:03

    Taking a look at VSCodeScriptEditor.cs (in the com.unity.ide.vscode package), at line 182 it seems that the Process is being created using the ProcessStartInfo.WindowStyle property set to Hidden. So when double clicking on a script, a VSCode process is indeed opened, but the Window is not shown. Changing the ProcessStartInfo.WindowStyle to ProcessWindowStyle.Normal fixes this.

    It seems kinda obvious, but as far as I can tell, this was done to hide the intermediary console window that would otherwise be shown if launching using the .cmd file - and afaik the .exe in older versions of VSCode (which is a good idea if you don't want a console window hanging around every time you open a script). I've suggested that this flag should be conditionally set based on whether the cmd or the exe is selected in the Unity Editor preferences, and perhaps based on the version of VSCode installed.

    Setting the external script editor to the exe worked with prior versions of VSCode - even when using ProcessWindowStyle.Hidden - as I'm fairly sure VSCode was creating the graphical window as a different process (or some other magic) - therefore ignoring the ProcessStartInfo.WindowStyle set when launching the process. In recent versions this doesn't seem to be the case, as the WindowStyle now applies to all processes, hence why the window wasn't being shown.

  10. Macklin

    Oct 02, 2019 14:58

    @Anthony0506 By changing the "External Script Editor" in the editor preferences, manually browsing to ".../Microsoft VS Code/bin/code.cmd". The set editor still appears as "Visual Studio Code" though.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.