@@ -8,6 +8,7 @@ import { Logger } from '../../logger/logger'
88import { ChildProcess } from '../../utilities/processUtils'
99import { waitUntil } from '../../utilities/timeoutUtils'
1010import { isDebugInstance } from '../../vscode/env'
11+ import * as vscode from 'vscode'
1112
1213export function getNodeExecutableName ( ) : string {
1314 return process . platform === 'win32' ? 'node.exe' : 'node'
@@ -81,26 +82,125 @@ export async function validateNodeExe(nodePath: string[], lsp: string, args: str
8182 }
8283}
8384
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+
84140export function createServerOptions ( {
85141 encryptionKey,
86142 executable,
87143 serverModule,
88144 execArgv,
89145 warnThresholds,
146+ env,
90147} : {
91148 encryptionKey : Buffer
92149 executable : string [ ]
93150 serverModule : string
94151 execArgv : string [ ]
95152 warnThresholds ?: { cpu ?: number ; memory ?: number }
153+ env ?: Record < string , string >
96154} ) {
97155 return async ( ) => {
98156 const bin = executable [ 0 ]
99157 const args = [ ...executable . slice ( 1 ) , serverModule , ...execArgv ]
100158 if ( isDebugInstance ( ) ) {
101159 args . unshift ( '--inspect=6080' )
102160 }
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+ } )
104204
105205 // this is a long running process, awaiting it will never resolve
106206 void lspProcess . run ( )
0 commit comments