@@ -41,8 +41,8 @@ import globals from '../../shared/extensionGlobals'
4141import { ResourcePaths } from '../../shared/lsp/types'
4242import { createServerOptions } from '../../shared/lsp/utils/platform'
4343import { waitUntil } from '../../shared/utilities/timeoutUtils'
44- import { tryRun } from '../../shared/utilities/pathFind'
4544import { ToolkitError } from '../../shared/errors'
45+ import { ChildProcess } from '../../shared/utilities/processUtils'
4646
4747const localize = nls . loadMessageBundle ( )
4848
@@ -225,6 +225,20 @@ export class LspClient {
225225 )
226226 }
227227}
228+
229+ /**
230+ * Checks that we can actually run the `node` executable and execute code with it.
231+ */
232+ async function validateNodeExe ( nodePath : string ) {
233+ const args = [ '-e' , 'console.log("ok" + process.version)' ]
234+ const proc = new ChildProcess ( nodePath , args , { logging : 'no' } )
235+ const r = await proc . run ( )
236+ const ok = r . exitCode === 0 && r . stdout . includes ( 'ok' )
237+ if ( ! ok ) {
238+ throw new ToolkitError ( `amazonqLsp: failed to run node (exitcode=${ r . exitCode } ): "${ resourcePaths . node } "` )
239+ }
240+ }
241+
228242/**
229243 * Activates the language server (assumes the LSP server has already been downloaded):
230244 * 1. start LSP server running over IPC protocol.
@@ -234,9 +248,7 @@ export async function activate(extensionContext: ExtensionContext, resourcePaths
234248 LspClient . instance // Tickle the singleton... :/
235249 const toDispose = extensionContext . subscriptions
236250
237- if ( await tryRun ( resourcePaths . node , [ '--version' ] ) ) {
238- throw new ToolkitError ( `failed to run node: "${ resourcePaths . node } "` )
239- }
251+ await validateNodeExe ( resourcePaths . node )
240252
241253 let rangeFormatting : Disposable | undefined
242254 // The debug options for the server
0 commit comments