Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening multiple instances of VS Code from Unity #152

Open
MattHamsay opened this issue May 22, 2017 · 3 comments
Open

Opening multiple instances of VS Code from Unity #152

MattHamsay opened this issue May 22, 2017 · 3 comments

Comments

@MattHamsay
Copy link

MattHamsay commented May 22, 2017

I'm running on Windows 10 and using Unity 2017.1.0.b5. I'm using 2.70-Release version of your extension that I installed from Asset Store.

Let's say I opened two instances of Unity. I click on scripts from each of the projects. I would like your extension to open two instances of VS Code where each instance is synced with a Unity project.

Currently, with my settings, it only opens one single instance of VS Code. When a script from a second project is opened, it will close the first one and switch to the next project.

I would like to have options to open multiple instances of VS Code when opened from Unity.

I looked up the list of opened & closed issues but I didn't seem to find a similar issue to my problem. I tried different settings for VSCode (I think the settings are ignored when launched from the command line) and changed a bit of Code.bin but it didn't work, although I have to admit I don't know much about the *.bin language. I tried to create a shortcut to open Code.exe with "-n" parameter but the problem for that was that I was not able to change the path to VSCode from the Preferences.VSCode panel because VS Code is installed in the default location and the path was auto detected.

Could you suggest a solution if there is a way to do this? Thanks for your helps in advance.

My settings for VS Code are as follows:

"window.openFilesInNewWindow": "on",
"window.openFoldersInNewWindow": "on",
"window.reopenFolders": "one",

I did not change anything from C:\Program Files (x86)\Microsoft VS Code\bin\Code.bin, and here is the content:

~/bin/Code.bin

@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
call "%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*
endlocal

#!/usr/bin/env bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

~/bin/Code

NAME="Code"
VSCODE_PATH="$(dirname "$(dirname "$(realpath "$0")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"
if grep -q Microsoft /proc/version; then
	# If running under WSL don't pass cli.js to Electron as environment vars
	# cannot be transferred from WSL to Windows
	# See: https://github.com/Microsoft/BashOnWindows/issues/1363
	#      https://github.com/Microsoft/BashOnWindows/issues/1494
	"$ELECTRON" "$@"
	exit $?
fi
if [ "$(expr substr $(uname -s) 1 9)" == "CYGWIN_NT" ]; then
	CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
	CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?
@elfmimi
Copy link

elfmimi commented May 22, 2017

I suppose you may edit VSCode.cs and try removing "-r" option from the command line.
Of course it's nicer if we can make this configurable according to user's pref.

A bit off-topic but, I have an experimental patch which allows you make VSCode's debugger to always connect to it's originating Unity process.
Though this takes both sides, Unity(VSCode.cs) and VSCode(Debugger for Unity), to be modified,
it it possible.

@MattHamsay
Copy link
Author

@elfmimi Thanks for your suggestion. Removing "-r" parameters in VSCode.cs solved it. However I'm leaving this issue open for now because I believe it would be beneficial for many people if this can be added as an option to the VSCode preferences panel.

@DonSkeleton
Copy link

DonSkeleton commented Aug 20, 2017

I also wanted Unity, in my case only Unity, to open a new VSC window for each Unity Project I have open. I've got it working with a batch script which has the follwing inside of it:

"D:\Program Files\Microsoft VS Code\Code.exe" %*

exit 0 

Then in Unity under Edit -> Preferences -> External Tools, I've selected the Batch file for "External Script Editor". After selecting the batch file, Unity will show a new input field called "External Script Editor Args" in the Preference popup which should have "$(File)" written inside of it, including the "".

This is not specific to the dotBunny extension but I thought people will stumble upon this site when looking for the same thing. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants