Skip to content

Commit ffe2527

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

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

packages/amazonq/test/unit/amazonq/lsp/lspClient.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55
import * as sinon from 'sinon'
66
import assert from 'assert'
7-
import { globals } from 'aws-core-vscode/shared'
8-
import { LspClient } from 'aws-core-vscode/amazonq'
7+
import { globals, getNodeExecutableName } from 'aws-core-vscode/shared'
8+
import { LspClient, lspClient as lspClientModule } from 'aws-core-vscode/amazonq'
99

1010
describe('Amazon Q LSP client', function () {
1111
let lspClient: LspClient
@@ -50,6 +50,22 @@ describe('Amazon Q LSP client', function () {
5050
assert.ok(!encryptedSample.includes('hello'))
5151
})
5252

53+
it('validates node executable + lsp bundle', async () => {
54+
await assert.rejects(async () => {
55+
await lspClientModule.activate(globals.context, {
56+
// Mimic the `LspResolution<ResourcePaths>` type.
57+
node: 'node.bogus.exe',
58+
lsp: 'fake/lsp.js',
59+
})
60+
}, /.*failed to run basic .*node.*exitcode.*node\.bogus\.exe.*/)
61+
await assert.rejects(async () => {
62+
await lspClientModule.activate(globals.context, {
63+
node: getNodeExecutableName(),
64+
lsp: 'fake/lsp.js',
65+
})
66+
}, /.*failed to run .*exitcode.*node.*lsp\.js/)
67+
})
68+
5369
afterEach(() => {
5470
sinon.restore()
5571
})

packages/core/src/amazonq/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
} from './onboardingPage/walkthrough'
1818
export { LspController } from './lsp/lspController'
1919
export { LspClient } from './lsp/lspClient'
20+
export * as lspClient from './lsp/lspClient'
2021
export { api } from './extApi'
2122
export { AmazonQChatViewProvider } from './webview/webView'
2223
export { init as cwChatAppInit } from '../codewhispererChat/app'

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,36 @@ async function validateNodeExe(nodePath: string, lsp: string, args: string[]) {
235235
const r = await proc.run()
236236
const ok = r.exitCode === 0 && r.stdout.includes('ok')
237237
if (!ok) {
238-
throw new ToolkitError(`amazonqLsp: failed to run "node -e" (exitcode=${r.exitCode}): "${nodePath}"`)
238+
const msg = `amazonqLsp: failed to run basic "node -e" test (exitcode=${r.exitCode}): ${proc}`
239+
logger.error(msg)
240+
throw new ToolkitError(msg)
239241
}
240242

241243
// Check that we can start `node …/lsp.js --stdio …`.
242244
const lspProc = new ChildProcess(nodePath, [lsp, ...args], { logging: 'no' })
243245
try {
244246
// Start asynchronously (it never stops; we need to stop it below).
245-
lspProc.run().catch((e) => logger.error('failed to start [%O %O %O]: %s', nodePath, lsp, args, e))
246-
247-
const ok2 = await waitUntil(
248-
async () => {
249-
return lspProc.pid !== undefined
250-
},
251-
{
252-
timeout: 5000,
253-
interval: 100,
254-
truthy: true,
255-
}
256-
)
257-
if (!ok2) {
258-
throw new ToolkitError(`amazonqLsp: failed to start (exitcode=${lspProc.exitCode}): [${nodePath} ${lsp} …]`)
247+
lspProc.run().catch((e) => logger.error('failed to run: %s', lspProc))
248+
249+
const ok2 =
250+
!lspProc.stopped &&
251+
(await waitUntil(
252+
async () => {
253+
return lspProc.pid() !== undefined
254+
},
255+
{
256+
timeout: 5000,
257+
interval: 100,
258+
truthy: true,
259+
}
260+
))
261+
const selfExit = await waitUntil(async () => lspProc.stopped, {
262+
timeout: 500,
263+
interval: 100,
264+
truthy: true,
265+
})
266+
if (!ok2 || selfExit) {
267+
throw new ToolkitError(`amazonqLsp: failed to run (exitcode=${lspProc.exitCode()}): ${lspProc}`)
259268
}
260269
} finally {
261270
lspProc.stop(true)

0 commit comments

Comments
 (0)