Skip to content

Commit fb9a34a

Browse files
committed
fixup! fix(lsp): install failure does not give enough info
1 parent 4d6f886 commit fb9a34a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/core/src/amazonq/lsp/lspClient.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import globals from '../../shared/extensionGlobals'
4141
import { ResourcePaths } from '../../shared/lsp/types'
4242
import { createServerOptions } from '../../shared/lsp/utils/platform'
4343
import { waitUntil } from '../../shared/utilities/timeoutUtils'
44-
import { tryRun } from '../../shared/utilities/pathFind'
4544
import { ToolkitError } from '../../shared/errors'
45+
import { ChildProcess } from '../../shared/utilities/processUtils'
4646

4747
const 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

Comments
 (0)