Repository navigation
fix(lsp): skip an unrunnable typescript-language-server and fall back to bunx #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import type { ChildProcessWithoutNullStreams } from 'node:child_process' | |||||||||||||||||||||||||||||||||||||
| import type { RootFunction } from './types' | ||||||||||||||||||||||||||||||||||||||
| import fs from 'node:fs/promises' | ||||||||||||||||||||||||||||||||||||||
| import path from 'node:path' | ||||||||||||||||||||||||||||||||||||||
| import process from 'node:process' | ||||||||||||||||||||||||||||||||||||||
| import { createLogger } from '@pleaseai/logger' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Re-export from @pleaseai/binaries | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -47,6 +48,53 @@ export function attachLSPProcessHandlers( | |||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const VERSION_PROBE_TIMEOUT_MS = 10_000 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * Find the first `name` on PATH whose `name --version` exits 0 when run in `root`. | ||||||||||||||||||||||||||||||||||||||
| * A version-manager shim (e.g. mise) can resolve on PATH while exiting non-zero | ||||||||||||||||||||||||||||||||||||||
| * because no version is configured for that directory, and a working install may | ||||||||||||||||||||||||||||||||||||||
| * sit in a later PATH entry. | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| export async function findRunnableBin(name: string, root: string): Promise<string | undefined> { | ||||||||||||||||||||||||||||||||||||||
| // Read PATH now rather than the copy Bun captured at startup | ||||||||||||||||||||||||||||||||||||||
| const dirs = (process.env.PATH ?? '').split(path.delimiter).filter(Boolean) | ||||||||||||||||||||||||||||||||||||||
| const seen = new Set<string>() | ||||||||||||||||||||||||||||||||||||||
| for (const dir of dirs) { | ||||||||||||||||||||||||||||||||||||||
| const bin = Bun.which(name, { PATH: dir }) | ||||||||||||||||||||||||||||||||||||||
| if (!bin || seen.has(bin)) { | ||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| seen.add(bin) | ||||||||||||||||||||||||||||||||||||||
| if (await runsVersion(bin, root)) { | ||||||||||||||||||||||||||||||||||||||
| return bin | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return undefined | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** Whether `bin --version` exits 0 when run in `root`. */ | ||||||||||||||||||||||||||||||||||||||
|
amondnet marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||
| export async function runsVersion(bin: string, root: string): Promise<boolean> { | ||||||||||||||||||||||||||||||||||||||
|
amondnet marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| const proc = Bun.spawn([bin, '--version'], { | ||||||||||||||||||||||||||||||||||||||
| cwd: root, | ||||||||||||||||||||||||||||||||||||||
| stdout: 'ignore', | ||||||||||||||||||||||||||||||||||||||
| stderr: 'ignore', | ||||||||||||||||||||||||||||||||||||||
| timeout: VERSION_PROBE_TIMEOUT_MS, | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
|
amondnet marked this conversation as resolved.
Comment on lines
+79
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [HIGH] Windows compatibility and error handling issues in runsVersion Problem: On Windows, Rationale: Correctness, cross-platform compatibility, and robustness. Suggestion: Pass
Suggested change
References
|
||||||||||||||||||||||||||||||||||||||
| const exitCode = await proc.exited | ||||||||||||||||||||||||||||||||||||||
| if (exitCode !== 0) { | ||||||||||||||||||||||||||||||||||||||
| log.warn({ bin, exitCode, signal: proc.signalCode }, 'Binary failed --version, skipping it') | ||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| catch (err) { | ||||||||||||||||||||||||||||||||||||||
| log.warn({ bin, err }, 'Failed to spawn binary for version check, skipping it') | ||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
amondnet marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // ============================================================================= | ||||||||||||||||||||||||||||||||||||||
| // Root Detection Utilities | ||||||||||||||||||||||||||||||||||||||
| // ============================================================================= | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.