@@ -8,6 +8,7 @@ import { Logger } from '../../logger/logger'
8
8
import { ChildProcess } from '../../utilities/processUtils'
9
9
import { waitUntil } from '../../utilities/timeoutUtils'
10
10
import { isDebugInstance } from '../../vscode/env'
11
+ import * as vscode from 'vscode'
11
12
12
13
export function getNodeExecutableName ( ) : string {
13
14
return process . platform === 'win32' ? 'node.exe' : 'node'
@@ -81,26 +82,125 @@ export async function validateNodeExe(nodePath: string[], lsp: string, args: str
81
82
}
82
83
}
83
84
85
+ /**
86
+ * Gets proxy settings from VS Code configuration
87
+ */
88
+ export function getVSCodeProxySettings ( ) : { proxyUrl ?: string ; proxyBypassRules ?: string ; certificatePath ?: string } {
89
+ try {
90
+ const result : { proxyUrl ?: string ; proxyBypassRules ?: string ; certificatePath ?: string } = { }
91
+
92
+ // Get proxy settings from VS Code configuration
93
+ const httpConfig = vscode . workspace . getConfiguration ( 'http' )
94
+ const proxy = httpConfig . get < string > ( 'proxy' )
95
+
96
+ if ( proxy ) {
97
+ result . proxyUrl = proxy
98
+ }
99
+
100
+ // Try to get system certificates
101
+ try {
102
+ // @ts -ignore - This is a valid access pattern in VSCode extensions
103
+ const electron = require ( 'electron' )
104
+ if ( electron ?. net ?. getCACertificates ) {
105
+ const certs = electron . net . getCACertificates ( )
106
+ if ( certs && certs . length > 0 ) {
107
+ // Create a temporary file with the certificates
108
+ const os = require ( 'os' )
109
+ const fs = require ( 'fs' )
110
+ const path = require ( 'path' )
111
+
112
+ const certContent = certs
113
+ . map ( ( cert : any ) => cert . pemEncoded )
114
+ . filter ( Boolean )
115
+ . join ( '\\n' )
116
+
117
+ if ( certContent ) {
118
+ const tempDir = path . join ( os . tmpdir ( ) , 'aws-toolkit-vscode' )
119
+ if ( ! fs . existsSync ( tempDir ) ) {
120
+ fs . mkdirSync ( tempDir , { recursive : true } )
121
+ }
122
+
123
+ const certPath = path . join ( tempDir , 'vscode-ca-certs.pem' )
124
+ fs . writeFileSync ( certPath , certContent )
125
+ result . certificatePath = certPath
126
+ }
127
+ }
128
+ }
129
+ } catch ( err ) {
130
+ // Silently fail if we can't access certificates
131
+ }
132
+
133
+ return result
134
+ } catch ( err ) {
135
+ // Silently fail if we can't access VS Code configuration
136
+ return { }
137
+ }
138
+ }
139
+
84
140
export function createServerOptions ( {
85
141
encryptionKey,
86
142
executable,
87
143
serverModule,
88
144
execArgv,
89
145
warnThresholds,
146
+ env,
90
147
} : {
91
148
encryptionKey : Buffer
92
149
executable : string [ ]
93
150
serverModule : string
94
151
execArgv : string [ ]
95
152
warnThresholds ?: { cpu ?: number ; memory ?: number }
153
+ env ?: Record < string , string >
96
154
} ) {
97
155
return async ( ) => {
98
156
const bin = executable [ 0 ]
99
157
const args = [ ...executable . slice ( 1 ) , serverModule , ...execArgv ]
100
158
if ( isDebugInstance ( ) ) {
101
159
args . unshift ( '--inspect=6080' )
102
160
}
103
- const lspProcess = new ChildProcess ( bin , args , { warnThresholds } )
161
+
162
+ // Merge environment variables
163
+ const processEnv = { ...process . env }
164
+ if ( env ) {
165
+ Object . assign ( processEnv , env )
166
+ }
167
+
168
+ // Get proxy settings from VS Code
169
+ const proxySettings = getVSCodeProxySettings ( )
170
+
171
+ // Add proxy settings to the Node.js process
172
+ if ( proxySettings . proxyUrl ) {
173
+ processEnv . HTTPS_PROXY = proxySettings . proxyUrl
174
+ processEnv . HTTP_PROXY = proxySettings . proxyUrl
175
+ processEnv . https_proxy = proxySettings . proxyUrl
176
+ processEnv . http_proxy = proxySettings . proxyUrl
177
+ }
178
+
179
+ // Add certificate path if available
180
+ if ( proxySettings . certificatePath ) {
181
+ processEnv . NODE_EXTRA_CA_CERTS = proxySettings . certificatePath
182
+ }
183
+
184
+ // Enable Node.js to use system CA certificates as a fallback
185
+ if ( ! processEnv . NODE_EXTRA_CA_CERTS ) {
186
+ processEnv . NODE_TLS_USE_SYSTEM_CA_STORE = '1'
187
+ }
188
+
189
+ // Get SSL verification settings
190
+ const httpConfig = vscode . workspace . getConfiguration ( 'http' )
191
+ const strictSSL = httpConfig . get < boolean > ( 'proxyStrictSSL' , true )
192
+
193
+ // Handle SSL certificate verification
194
+ if ( ! strictSSL ) {
195
+ processEnv . NODE_TLS_REJECT_UNAUTHORIZED = '0'
196
+ }
197
+
198
+ const lspProcess = new ChildProcess ( bin , args , {
199
+ warnThresholds,
200
+ spawnOptions : {
201
+ env : processEnv ,
202
+ } ,
203
+ } )
104
204
105
205
// this is a long running process, awaiting it will never resolve
106
206
void lspProcess . run ( )
0 commit comments