@@ -81,26 +81,97 @@ export async function validateNodeExe(nodePath: string[], lsp: string, args: str
8181 }
8282}
8383
84+ /**
85+ * Gets Electron settings from VS Code
86+ */
87+ export function getElectronSettings ( ) : { caCerts ?: string ; proxyRules ?: string ; proxyBypassRules ?: string } {
88+ try {
89+ // Access Electron's modules through VSCode's API
90+ // @ts -ignore - This is a valid access pattern in VSCode extensions
91+ const electron = require ( 'electron' )
92+ const result : { caCerts ?: string ; proxyRules ?: string ; proxyBypassRules ?: string } = { }
93+
94+ // Get certificates
95+ if ( electron ?. net ?. getCACertificates ) {
96+ const certs = electron . net . getCACertificates ( )
97+ if ( certs && certs . length > 0 ) {
98+ // Convert the certificates to PEM format
99+ result . caCerts = certs
100+ . map ( ( cert : any ) => cert . pemEncoded )
101+ . filter ( Boolean )
102+ . join ( '\n' )
103+ }
104+ }
105+
106+ // Get proxy settings from Electron
107+ if ( electron ?. session ?. defaultSession ?. getProxyRules ) {
108+ result . proxyRules = electron . session . defaultSession . getProxyRules ( )
109+ }
110+
111+ if ( electron ?. session ?. defaultSession ?. getProxyBypassRules ) {
112+ result . proxyBypassRules = electron . session . defaultSession . getProxyBypassRules ( )
113+ }
114+
115+ return result
116+ } catch ( err ) {
117+ // Silently fail if we can't access Electron
118+ return { }
119+ }
120+ }
121+
84122export function createServerOptions ( {
85123 encryptionKey,
86124 executable,
87125 serverModule,
88126 execArgv,
89127 warnThresholds,
128+ env,
90129} : {
91130 encryptionKey : Buffer
92131 executable : string [ ]
93132 serverModule : string
94133 execArgv : string [ ]
95134 warnThresholds ?: { cpu ?: number ; memory ?: number }
135+ env ?: Record < string , string >
96136} ) {
97137 return async ( ) => {
98138 const bin = executable [ 0 ]
99139 const args = [ ...executable . slice ( 1 ) , serverModule , ...execArgv ]
100140 if ( isDebugInstance ( ) ) {
101141 args . unshift ( '--inspect=6080' )
102142 }
103- const lspProcess = new ChildProcess ( bin , args , { warnThresholds } )
143+
144+ // Merge environment variables
145+ const processEnv = { ...process . env }
146+ if ( env ) {
147+ Object . assign ( processEnv , env )
148+ }
149+
150+ // Get Electron settings (certificates and proxy)
151+ const electronSettings = getElectronSettings ( )
152+
153+ // Add system CA certificates to the Node process if not already set
154+ if ( ! processEnv . NODE_EXTRA_CA_CERTS && electronSettings . caCerts ) {
155+ processEnv . NODE_EXTRA_CA_CERTS = electronSettings . caCerts
156+ }
157+
158+ // Add Electron proxy settings to the Node process
159+ if ( electronSettings . proxyRules && ! processEnv . HTTP_PROXY ) {
160+ processEnv . HTTP_PROXY = electronSettings . proxyRules
161+ processEnv . HTTPS_PROXY = electronSettings . proxyRules
162+ }
163+
164+ // Add proxy bypass rules if available
165+ if ( electronSettings . proxyBypassRules ) {
166+ processEnv . NO_PROXY = electronSettings . proxyBypassRules
167+ }
168+
169+ const lspProcess = new ChildProcess ( bin , args , {
170+ warnThresholds,
171+ spawnOptions : {
172+ env : processEnv ,
173+ } ,
174+ } )
104175
105176 // this is a long running process, awaiting it will never resolve
106177 void lspProcess . run ( )
0 commit comments