Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/lsp/src/server/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,18 @@ export const TypescriptServer: LSPServerInfo = {
if (!tsserver) {
// Try via bunx. The version tag makes bunx install from the registry instead of
// reusing a typescript-language-server on PATH, which may be the shim just rejected.
try {
const proc = spawn('bunx', [`typescript-language-server@${TS_LANGUAGE_SERVER_VERSION}`, '--stdio'], {
cwd: root,
env: { ...process.env, BUN_BE_BUN: '1' },
})
attachLSPProcessHandlers(proc, 'typescript')
return { process: proc }
}
catch (err) {
log.error({ err }, 'Failed to spawn typescript-language-server via bunx')
// spawn reports a missing bunx only as an async 'error' event, so check for it first.
const bunx = Bun.which('bunx', { PATH: process.env.PATH ?? '' })
if (!bunx) {
log.warn({ root }, 'typescript-language-server not found. Install with: npm install typescript-language-server typescript')
return undefined
}
const proc = spawn(bunx, [`typescript-language-server@${TS_LANGUAGE_SERVER_VERSION}`, '--stdio'], {
cwd: root,
env: { ...process.env, BUN_BE_BUN: '1' },
})
attachLSPProcessHandlers(proc, 'typescript')
return { process: proc }
}

// On Windows the bin is a .cmd shim, which only runs through a shell.
Expand Down
21 changes: 21 additions & 0 deletions packages/lsp/test/unit/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,27 @@ describe.skipIf(process.platform === 'win32')('TypescriptServer classic fallback
const invoked = await spawnTypescriptWith({ bunx: recorder('bunx') }, rootDir => installLocalServer(rootDir, '#!/bin/sh\nexit 1\n'))
expect(invoked).toBe('bunx typescript-language-server@4.3.3 --stdio')
})

test('returns undefined with the install hint when bunx is missing', async () => {
const emptyDir = await fs.mkdtemp(path.join(os.tmpdir(), 'lsp-fallback-empty-'))
const savedPath = process.env.PATH
const warn = spyOn(log, 'warn')
try {
process.env.PATH = emptyDir
const handle = await TypescriptServer.spawn(emptyDir)
process.env.PATH = savedPath
expect(handle).toBeUndefined()
expect(warn).toHaveBeenCalledWith(
expect.anything(),
'typescript-language-server not found. Install with: npm install typescript-language-server typescript',
)
}
finally {
warn.mockRestore()
process.env.PATH = savedPath
await fs.rm(emptyDir, { recursive: true, force: true })
}
})
})

describe.skipIf(process.platform === 'win32')('BiomeServer fallback', () => {
Expand Down
Loading