Skip to content

Commit 1079efc

Browse files
committed
Merge branch 'main' of github.mathworks.com:development/matlab-language-server
2 parents e2ee5cb + e271271 commit 1079efc

File tree

5 files changed

+65
-3
lines changed

5 files changed

+65
-3
lines changed

src/lifecycle/MatlabCommunicationManager.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ declare class MatlabCommunicationManager {
2121
* @param launchCommand The command with which MATLAB is launched
2222
* @param launchArguments The arguments with which MATLAB is launched
2323
* @param logDirectory The directory in which MATLAB should log data
24+
* @param environmentVariables The additional set of environment variables which needs to be passed to the MATLAB process
2425
*
2526
* @returns Information about the new MATLAB process and the connection to it.
2627
* Returns null if the MATLAB process cannot be started.
2728
*/
28-
launchNewMatlab(launchCommand: string, launchArguments: string[], logDirectory: string): MatlabProcessInfo | null;
29+
launchNewMatlab(launchCommand: string, launchArguments: string[], logDirectory: string, environmentVariables?: NodeJS.ProcessEnv): MatlabProcessInfo | null;
2930
/**
3031
* Attempts to connect to an existing instance of MATLAB at the given URL.
3132
*

src/lifecycle/MatlabCommunicationManager.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lifecycle/MatlabSession.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as os from 'os'
1414
import * as path from 'path'
1515
import { EventEmitter } from 'events'
1616
import { checkIfMatlabDeprecated } from "../utils/DeprecationUtils";
17+
import { getProxyEnvironmentVariables } from "../utils/ProxyUtils";
1718

1819
interface MatlabStartupInfo {
1920
pid: number
@@ -84,7 +85,10 @@ export async function launchNewMatlab (): Promise<MatlabSession> {
8485
// Launch MATLAB process
8586
Logger.log('Launching MATLAB...')
8687
const { command, args } = await getMatlabLaunchCommand(outFile)
87-
const matlabProcessInfo = MatlabCommunicationManager.launchNewMatlab(command, args, Logger.logDir)
88+
const envVars: NodeJS.ProcessEnv = {
89+
...getProxyEnvironmentVariables()
90+
}
91+
const matlabProcessInfo = MatlabCommunicationManager.launchNewMatlab(command, args, Logger.logDir, envVars)
8892

8993
if (matlabProcessInfo == null) {
9094
// Error occurred while spawning MATLAB process

src/server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ import FoldingSupportProvider from './providers/folding/FoldingSupportProvider'
2020
import ClientConnection from './ClientConnection'
2121
import PathResolver from './providers/navigation/PathResolver'
2222
import Indexer from './indexing/Indexer'
23+
import { cacheAndClearProxyEnvironmentVariables } from './utils/ProxyUtils'
2324

2425
export async function startServer () {
26+
cacheAndClearProxyEnvironmentVariables()
27+
2528
// Create a connection for the server
2629
const connection = ClientConnection.getConnection()
2730

src/utils/ProxyUtils.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2024 The MathWorks, Inc.
2+
3+
interface ProxyEnvironmentVariables {
4+
HTTP_PROXY?: string
5+
HTTPS_PROXY?: string
6+
NO_PROXY?: string
7+
}
8+
9+
const proxyEnvironmentVariables: ProxyEnvironmentVariables = {}
10+
11+
/**
12+
* Workaround for connection issue with proxy environments: cache values for HTTP_PROXY,
13+
* HTTPS_PROXY, and NO_PROXY environment variables, then delete variables from environment.
14+
*/
15+
export function cacheAndClearProxyEnvironmentVariables (): void {
16+
const http_proxy = process.env.HTTP_PROXY ?? process.env.http_proxy
17+
const https_proxy = process.env.HTTPS_PROXY ?? process.env.https_proxy
18+
const no_proxy = process.env.NO_PROXY ?? process.env.no_proxy
19+
delete process.env.HTTP_PROXY
20+
delete process.env.http_proxy
21+
delete process.env.HTTPS_PROXY
22+
delete process.env.https_proxy
23+
delete process.env.NO_PROXY
24+
delete process.env.no_proxy
25+
26+
if (http_proxy != null) {
27+
proxyEnvironmentVariables.HTTP_PROXY = http_proxy
28+
}
29+
if (https_proxy != null) {
30+
proxyEnvironmentVariables.HTTPS_PROXY = https_proxy
31+
}
32+
if (no_proxy != null) {
33+
proxyEnvironmentVariables.NO_PROXY = no_proxy
34+
}
35+
}
36+
37+
/**
38+
* Determines if running within a proxy environment.
39+
*
40+
* @returns True if within a proxy environment, false otherwise
41+
*/
42+
export function isProxyEnvironment (): boolean {
43+
return Object.keys(proxyEnvironmentVariables).length > 0
44+
}
45+
46+
/**
47+
* Gets any proxy environment variables and their values that had been set prior to
48+
* `cacheAndClearProxyEnvironmentVariables` being called.
49+
*
50+
* @returns An object containing any proxy-related environment variables and their values
51+
*/
52+
export function getProxyEnvironmentVariables (): ProxyEnvironmentVariables {
53+
return proxyEnvironmentVariables
54+
}

0 commit comments

Comments
 (0)