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: VSCode

-

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 (10)

  1. 872dcd147dae287a8998c23138709dd4?d=mm

    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

  2. 01f1bdbc087fc3468f05608759475fbe?d=mm

    benjamminlaner

    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.

  3. 42190708a3674bc4aba3399be7fbbd0c?d=mm

    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)

  4. 42190708a3674bc4aba3399be7fbbd0c?d=mm

    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.

  5. 16ac0964d997a183b8239a32f103de6d?d=mm

    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.

  6. 42190708a3674bc4aba3399be7fbbd0c?d=mm

    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.

  7. 42190708a3674bc4aba3399be7fbbd0c?d=mm

    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.

  8. 1d7cbdb12051bb238366c9ec7d182bee?d=mm

    Anthony0506

    Sep 28, 2019 20:17

    how are you setting it to use the .cmd file?

  9. 644a451a0f827335e5db3e9f716645b7?d=mm

    mccann

    Sep 28, 2019 18:53

    Issue happened to me (2019.2.5). I tried a lot of different work arounds to no avail. Thanks for the workaround of using .cmd file option!

  10. 42190708a3674bc4aba3399be7fbbd0c?d=mm

    Macklin

    Sep 19, 2019 09:31

    Adding some notes that aren't listed above, but might be worth mentioning:
    - Does not occur when setting the editor to code.cmd (in earlier versions you were required to open VSCode via the .cmd file, however in the current version, code.exe works fine and accepts command line parameters just as well).
    - Occurs regardless of the presence of parameters in Preferences.
    - Only occurs if VS Code is closed before attempting to open from Unity.
    - After reproducing the issue, a number of separate Code.exe processes are in fact visible in Task Manager, but only in the Details tab - not in the Processes tab. They have to be manually ended before another instance can be opened.

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.