Search Unity

VSCode on Mac doesn't open correct file

Discussion in 'Editor & General Support' started by laurie71, Aug 30, 2019.

  1. laurie71

    laurie71

    Joined:
    Aug 15, 2018
    Posts:
    18
    I have VSCode selected as my default editor, with the default command line parameters. When opening scripts from the editor, VSCode opens the project but doesn't switch to the file I opened. It seems to be ignoring the -g command-line argument. I've tried removing the project path, as well as adding a -r option, but no luck.

    Is this a known limitation with using VSCode, or is there a fix? This really makes VSCode a lot less convenient to use with Unity.

    Thanks!
     
    Muckel likes this.
  2. amroc

    amroc

    Joined:
    Apr 8, 2014
    Posts:
    6
    Having the same issue too, started when I switched from 2019.1 to 2019.2. There's another thread about this with some suggested fixes but they seem mainly to be for Windows.
     
  3. laurie71

    laurie71

    Joined:
    Aug 15, 2018
    Posts:
    18
    Interesting; I tested on 2019.1 and it worked fine. That version doesn't offer the option to specify the command arguments, so I tried clearing them in 2019.2 but without luck. I also tried pointing the editor at a script that would log the command arguments then call the 'real' code command, but Unity wouldn't let me select the script (or the 'code' executable for that matter) so no go there.

    If anyone knows a fix for this annoying regression please let us know!
     
  4. amroc

    amroc

    Joined:
    Apr 8, 2014
    Posts:
    6
    Yeah it just seems as if Unity isn't actually sending the $(File) param at all, once VSCode is open.

    Found a sort of workaround. File selection works again after downgrading the Visual Studio Code Editor package to 1.0.3. This version though seems to not recognise the $(ProjectPath) param (I couldn't find anywhere if the name was different in this version or just didn't exist), so I just have -g ($File) in the args, and I manually load the solution folder in VSCode on startup. Hardcoding the folder path at the start of the args might work too.

    Not sure if using 1.0.3 will throw up any problems but it seems ok so far. According to the package log the changes in 1.0.7 were: "Fix various OSX specific issues. Generate project on load if they are not generated. Fix path recognition." Maybe that's when the problem was introduced.
     
    Muckel likes this.
  5. shengyihua88

    shengyihua88

    Joined:
    Jul 25, 2017
    Posts:
    5
    This problem has affected me for a long time. Now I have to change to another IDE. I don't know if there are several versions on Mac, including 2.0, 2.1, 2.2, 2.3, 2010.3.x. The authorities don't seem to be taking it seriously.
     
  6. laurie71

    laurie71

    Joined:
    Aug 15, 2018
    Posts:
    18
    Interesting, that's definately worth a try, although I'm using the same vscode everywhere and it's working for all versions on Unity I've tried prior to 2019.2. For what it's worth, the $(ProjectPath) param is expanded by Unity before calling vscode, not by vscode itself; what might be lacking is support for specifying a project path on the command line that way at all, though.
     
  7. juanfornos

    juanfornos

    Joined:
    Feb 17, 2018
    Posts:
    6
    Muckel and amroc like this.
  8. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    431
  9. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    34
    FWIW this seems to work if you quit VS Code before trying to click through in Unity. Obviously a very S***ty work-around, but there are cases (like when I generate a whole bunch of errors in various files I need to chase down) where knowing this can be helpful.
     
  10. shengyihua88

    shengyihua88

    Joined:
    Jul 25, 2017
    Posts:
    5
    Why is there no reported fix for this bug? I've been waiting a long time, and the Visual Studio Code Editor version has been upgraded to 1.1.2, but it still doesn't work.
     
  11. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    34
    Didn't realize 1.1.2 was out, but I just updated and it's working for me now. Maybe just try restarting Unity and VS Code if you didn't already.
     
  12. laurie71

    laurie71

    Joined:
    Aug 15, 2018
    Posts:
    18
    Confirmed, seems to work great for me now.
     
  13. shengyihua88

    shengyihua88

    Joined:
    Jul 25, 2017
    Posts:
    5
    All the software I use is the latest version, and it still doesn't work. The main problem is that only a single script can be opened, and it can't be automatically opened as a project.
    QQ20190914-153854@2x.png
     
  14. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    34
    Hmmm, that seems like something else since the project doesn't appear to be opening.

    I just seem to have lost code folding (tried fiddling with the settings and restarting VS Code but it's just gone forever). Seems like maybe that coincided with this update, anyone else noticing that or perhaps it's unrelated?
     
  15. Rachzella

    Rachzella

    Joined:
    Oct 9, 2015
    Posts:
    72
    I started unity and launched a script. But no, i don't seem to have this issue. What i did have is the scenes opening in vs code. simpely removing vs code as the default editor was a fix. i don't have any other editors installed so it launches in vs code. if that doesn't fix it. There are multiple extensions for unity in vs code. Just type in unity in the exstension bar. they should help you. if not. restart your mac. and open the project folder in vs code. then it should launch the right one.