4
4
*/
5
5
6
6
import { ToolkitError } from '../../errors'
7
- import { Logger } from '../../logger/logger'
7
+ import { Logger , getLogger } from '../../logger/logger'
8
8
import { ChildProcess } from '../../utilities/processUtils'
9
9
import { waitUntil } from '../../utilities/timeoutUtils'
10
10
import { isDebugInstance } from '../../vscode/env'
@@ -83,57 +83,65 @@ export async function validateNodeExe(nodePath: string[], lsp: string, args: str
83
83
}
84
84
85
85
/**
86
- * Gets proxy settings from VS Code configuration
86
+ * Gets proxy settings and certificates from VS Code
87
87
*/
88
- export function getVSCodeProxySettings ( ) : { proxyUrl ?: string ; proxyBypassRules ?: string ; certificatePath ?: string } {
88
+ export function getVSCodeSettings ( ) : { proxyUrl ?: string ; certificatePath ?: string } {
89
+ const result : { proxyUrl ?: string ; certificatePath ?: string } = { }
90
+ const logger = getLogger ( 'amazonqLsp' )
91
+
89
92
try {
90
- const result : { proxyUrl ?: string ; proxyBypassRules ?: string ; certificatePath ?: string } = { }
93
+ // Check if user already has NODE_EXTRA_CA_CERTS set
94
+ const userCerts = process . env . NODE_EXTRA_CA_CERTS
95
+ if ( userCerts ) {
96
+ logger . info ( `User already has NODE_EXTRA_CA_CERTS set: ${ userCerts } ` )
97
+ return result
98
+ }
91
99
92
100
// Get proxy settings from VS Code configuration
93
101
const httpConfig = vscode . workspace . getConfiguration ( 'http' )
94
102
const proxy = httpConfig . get < string > ( 'proxy' )
95
-
96
103
if ( proxy ) {
97
104
result . proxyUrl = proxy
105
+ logger . info ( `Using proxy from VS Code settings: ${ proxy } ` )
98
106
}
99
107
100
- // Try to get system certificates
101
108
try {
102
109
// @ts -ignore - This is a valid access pattern in VSCode extensions
103
110
const electron = require ( 'electron' )
104
111
if ( electron ?. net ?. getCACertificates ) {
105
112
const certs = electron . net . getCACertificates ( )
106
113
if ( certs && certs . length > 0 ) {
107
- // Create a temporary file with the certificates
108
- const os = require ( 'os' )
114
+ logger . info ( `Found ${ certs . length } certificates in VS Code's trust store` )
115
+
116
+ // Create a temporary file with certificates
109
117
const fs = require ( 'fs' )
118
+ const os = require ( 'os' )
110
119
const path = require ( 'path' )
111
120
121
+ const tempDir = path . join ( os . tmpdir ( ) , 'aws-toolkit-vscode' )
122
+ if ( ! fs . existsSync ( tempDir ) ) {
123
+ fs . mkdirSync ( tempDir , { recursive : true } )
124
+ }
125
+
126
+ const certPath = path . join ( tempDir , 'vscode-ca-certs.pem' )
112
127
const certContent = certs
128
+ . filter ( ( cert : any ) => cert . pemEncoded )
113
129
. 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
- }
130
+ . join ( '\n' )
131
+
132
+ fs . writeFileSync ( certPath , certContent )
133
+ result . certificatePath = certPath
134
+ logger . info ( `Created certificate file at: ${ certPath } ` )
127
135
}
128
136
}
129
137
} catch ( err ) {
130
- // Silently fail if we can't access certificates
138
+ logger . error ( `Failed to extract certificates: ${ err } ` )
131
139
}
132
140
133
141
return result
134
142
} catch ( err ) {
135
- // Silently fail if we can't access VS Code configuration
136
- return { }
143
+ logger . error ( `Failed to get VS Code settings: ${ err } ` )
144
+ return result
137
145
}
138
146
}
139
147
@@ -165,25 +173,22 @@ export function createServerOptions({
165
173
Object . assign ( processEnv , env )
166
174
}
167
175
168
- // Get proxy settings from VS Code
169
- const proxySettings = getVSCodeProxySettings ( )
176
+ // Get settings from VS Code
177
+ const settings = getVSCodeSettings ( )
178
+ const logger = getLogger ( 'amazonqLsp' )
170
179
171
180
// 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
181
+ if ( settings . proxyUrl ) {
182
+ processEnv . HTTPS_PROXY = settings . proxyUrl
183
+ processEnv . HTTP_PROXY = settings . proxyUrl
184
+ processEnv . https_proxy = settings . proxyUrl
185
+ processEnv . http_proxy = settings . proxyUrl
177
186
}
178
187
179
188
// 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'
189
+ if ( settings . certificatePath ) {
190
+ processEnv . NODE_EXTRA_CA_CERTS = settings . certificatePath
191
+ logger . info ( `Using certificate file: ${ settings . certificatePath } ` )
187
192
}
188
193
189
194
// Get SSL verification settings
@@ -193,6 +198,7 @@ export function createServerOptions({
193
198
// Handle SSL certificate verification
194
199
if ( ! strictSSL ) {
195
200
processEnv . NODE_TLS_REJECT_UNAUTHORIZED = '0'
201
+ logger . info ( 'SSL verification disabled via VS Code settings' )
196
202
}
197
203
198
204
const lspProcess = new ChildProcess ( bin , args , {
0 commit comments