2
votes

Visual Studio Code (0.3.0 - 0.7.0) defaults to opening files in a new window, so if you double-click a file in the project view in Unity, or any log in the console, it will open a new window rather than opening the file in an existing window you already have open.

Visual Studio Code (0.5.0 - 0.7.0) will open a file in an existing window if you pass it the command line arg -r, however Unity will not let you customize command line arguments on OSX, it's a Windows-only feature.

Is there a way to open files from Unity into an existing window in Visual Studio Code (0.3.0 - 0.7.0)?

2

2 Answers

3
votes

There is a way, but it's a pain. Create a shell script that calls Visual Studio Code and passes it the file path that Unity provides:

"/Applications/Visual Studio Code.app/Contents/MacOS/Electron" -r -g $1

exit 0

Then you need to make an .app from that shell script. I used a program called Platypus to make the .app. If you use Platypus make sure to check the 'Accepts Dropped Items` checkbox, it didn't work for me until I used this option.

Once you have the .app created you need to set that app as your External Editor in Unity.

Hopefully in the future Unity will allow custom arguments to be sent for OSX, not just Windows. Also it would be nice if Unity passed the line and column numbers to custom external editors, currently those details are only passed to certain Unity-recognized editors. There is really no reason I can think of that why they could not pass that information as additional arguments. Because that information isn't being passed that means you cannot configure this script to open up the file to line that an error might be on, which is a bummer.

Also, this entire answer would be unnecessary if the Visual Studio Code team would just add an option in the preferences to default to opening files in the existing window instead of defaulting to a new one. There are a couple of feature requests listed on their site for this currently, here's one: http://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/8740771-persistant-option-to-open-files-in-existing-window

1
votes

Hi you can get full debugging support in VSCode for Unity using this plugin

https://github.com/dotBunny/VSCode

VS Code in Unity

This plugin works on both MacOS and Windows and gives you the following capabilities:

•An option to enable VS Code integration (Editor –> Assets –> Enable Integration), this updates your solution files and (more importantly) keeps them in sync. This also sets the preferred external tool editor in the Unity preferences. *Note, the old “Sync MonoDevelop” option is now gone in the Unity editor from V5.2 •It writes out the necessary (and sometimes hard to find) VS Code configuration files, including the ability to hide “non-code” files in the editor (hides things like .sln, .csproj and the ever present unity .meta files) There are a couple of other settings in there to help speed up the integration. •Automatically launches VS Code direct to your project folder, EVERY-TIME. no longer do you have to worry about keeping that window open, or switching around if you work on multiple projects

One thing to be aware of, once you enable the VSCode integration, changing your preferred code editor in the External Tools preferences will have no effect as the plugin takes over opening code files.