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

code scripts test if in remote terminal #150131

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
code scripts test if in remote terminal
  • Loading branch information
aeschli committed May 22, 2022
commit 6148ecb70025867be3848dfb8631b873ee27b4ae
7 changes: 7 additions & 0 deletions resources/darwin/bin/code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

# when run in remote terminal, use the remote cli instead
if [ -n "$VSCODE_IPC_HOOK_CLI" ] && [ -n "$VSCODE_REMOTE_CLI_PATH" ]; then
"$VSCODE_REMOTE_CLI_PATH"
exit $?
fi

function app_realpath() {
SOURCE=$1
while [ -h "$SOURCE" ]; do
Expand All @@ -19,6 +25,7 @@ if [ -z "$APP_PATH" ]; then
echo "Unable to determine app path from symlink : ${BASH_SOURCE[0]}"
exit 1
fi

CONTENTS="$APP_PATH/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
Expand Down
6 changes: 6 additions & 0 deletions resources/linux/bin/code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ if [ "$(id -u)" = "0" ]; then
fi
fi

# when run in remote terminal, use the remote cli instead
if [ -n "$VSCODE_IPC_HOOK_CLI" ] && [ -n "$VSCODE_REMOTE_CLI_PATH" ]; then
"$VSCODE_REMOTE_CLI_PATH"
exit $?
fi

if [ ! -L "$0" ]; then
# if path is not a symlink, find relatively
VSCODE_PATH="$(dirname "$0")/.."
Expand Down
7 changes: 7 additions & 0 deletions resources/win32/bin/code.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
@echo off

rem when run in remote terminal, use the remote cli instead
if defined VSCODE_IPC_HOOK_CLI if defined VSCODE_REMOTE_CLI_PATH (
%VSCODE_REMOTE_CLI_PATH% %*
exit
)

setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
Expand Down
8 changes: 6 additions & 2 deletions src/vs/server/node/extensionHostConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import { IProcessEnvironment, isWindows } from 'vs/base/common/platform';
import { logRemoteEntry } from 'vs/workbench/services/extensions/common/remoteConsoleUtil';
import { removeDangerousEnvVariables } from 'vs/base/common/processes';
import { IExtensionHostStatusService } from 'vs/server/node/extensionHostStatusService';
import { IProductService } from 'vs/platform/product/common/productService';

export async function buildUserEnvironment(startParamsEnv: { [key: string]: string | null } = {}, withUserShellEnvironment: boolean, language: string, isDebug: boolean, environmentService: IServerEnvironmentService, logService: ILogService): Promise<IProcessEnvironment> {
export async function buildUserEnvironment(startParamsEnv: { [key: string]: string | null } = {}, withUserShellEnvironment: boolean, language: string, isDebug: boolean, environmentService: IServerEnvironmentService, productService: IProductService, logService: ILogService): Promise<IProcessEnvironment> {
const nlsConfig = await getNLSConfiguration(language, environmentService.userDataPath);

let userShellEnv: typeof process.env = {};
Expand Down Expand Up @@ -63,6 +64,8 @@ export async function buildUserEnvironment(startParamsEnv: { [key: string]: stri
}
setCaseInsensitive(env, 'PATH', PATH);

env.VSCODE_REMOTE_CLI_PATH = join(remoteCliBinFolder, productService.applicationName + (isWindows ? '.cmd' : '')); // the `code` command

if (!environmentService.args['without-browser-env-var']) {
env.BROWSER = join(binFolder, 'helpers', isWindows ? 'browser.cmd' : 'browser.sh'); // a command that opens a browser on the local machine
}
Expand Down Expand Up @@ -108,6 +111,7 @@ export class ExtensionHostConnection {
socket: NodeSocket | WebSocketNodeSocket,
initialDataChunk: VSBuffer,
@IServerEnvironmentService private readonly _environmentService: IServerEnvironmentService,
@IProductService private readonly _productService: IProductService,
@ILogService private readonly _logService: ILogService,
@IExtensionHostStatusService private readonly _extensionHostStatusService: IExtensionHostStatusService,
) {
Expand Down Expand Up @@ -194,7 +198,7 @@ export class ExtensionHostConnection {
execArgv = [`--inspect${startParams.break ? '-brk' : ''}=${startParams.port}`];
}

const env = await buildUserEnvironment(startParams.env, true, startParams.language, !!startParams.debugId, this._environmentService, this._logService);
const env = await buildUserEnvironment(startParams.env, true, startParams.language, !!startParams.debugId, this._environmentService, this._productService, this._logService);
removeDangerousEnvVariables(env);

const opts = {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/server/node/remoteTerminalChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
};


const baseEnv = await buildUserEnvironment(args.resolverEnv, !!args.shellLaunchConfig.useShellEnvironment, platform.language, false, this._environmentService, this._logService);
const baseEnv = await buildUserEnvironment(args.resolverEnv, !!args.shellLaunchConfig.useShellEnvironment, platform.language, false, this._environmentService, this._productService, this._logService);
this._logService.trace('baseEnv', baseEnv);

const reviveWorkspaceFolder = (workspaceData: IWorkspaceFolderData): IWorkspaceFolder => {
Expand Down