Repository navigation
fix(lsp): fall back to downloaded dart sdk when system dart cannot run - #129
Conversation
A version-manager shim (e.g. mise) can resolve on PATH but exit non-zero when no SDK is installed for the project. Probe `dart --version` and use the system dart only if it exits 0; otherwise log a warning and fall back to the auto-downloaded SDK. Refs #127
There was a problem hiding this comment.
Code Review
This pull request introduces a findSystemDart helper function to verify that the system Dart binary is functional by running its version command before using it, preventing issues with unconfigured version-manager shims. It also adds corresponding unit tests. The review feedback correctly identifies a robustness issue where Bun.spawn could throw a synchronous error due to permission issues, which would crash the LSP server startup instead of falling back to the auto-downloaded SDK. Wrapping the spawning logic in a try-catch block is recommended to handle this safely.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
[Medium impact] The PR appears safe to merge; no new blocking issue was found. SummaryThe PR checks whether system Dart can run before starting its language server. Failed probes fall back to the downloaded SDK.
|
Harden the system dart probe: catch spawn errors, run it in the project root, and bound it with a 10s timeout. Skip the shell-based tests on Windows. Refs #127
|
/gemini review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
No issues found across 2 files
Architecture diagram
sequenceDiagram
participant LSP as LSP Manager
participant DS as DartServer (dart.ts)
participant FS as findSystemDart()
participant PATH as System PATH
participant BUN as Bun Runtime
participant DL as Auto-Download SDK
Note over LSP,DL: Dart LSP Server Startup Flow
LSP->>DS: spawn(root)
DS->>FS: findSystemDart(root)
FS->>PATH: Bun.which('dart')
alt System dart found on PATH
PATH-->>FS: systemDart path
FS->>BUN: Bun.spawn([dart, '--version'], { cwd: root })
alt Probe succeeds (exit 0)
BUN-->>FS: exit 0
FS-->>DS: return systemDart path
else Probe fails (non-zero exit or spawn error)
BUN-->>FS: exit != 0 / signal / error
FS->>FS: Log warning with exit code + stderr
FS-->>DS: return undefined
end
else No system dart on PATH
PATH-->>FS: undefined
FS-->>DS: return undefined
end
alt Valid system Dart available
DS->>BUN: spawn(systemDart, ['language-server', ...])
BUN-->>LSP: LSP process started
else Falling back to auto-downloaded SDK
DS->>DL: Fetch/download cached Dart SDK
DL-->>DS: SDK path
DS->>BUN: spawn(downloadedSDK, ['language-server', ...])
BUN-->>LSP: LSP process started
end
Bun.which defaults to the PATH captured at process startup. Passing process.env.PATH lets findSystemDart follow the current environment, so its unit tests can run in-process and count toward coverage instead of probing through a child bun process. Refs #127
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|



Summary
DartServer.spawn(packages/lsp/src/server/dart.ts) usedBun.which('dart')and spawned whatever resolved. A mise shim with no Dart version configured resolves on PATH but exits 1 (mise ERROR No version is set for shim: dart), so the server died instead of using the auto-downloaded SDK. Spawn now probes the systemdartfirst and falls back to the download path when it cannot run.findSystemDart()runsdart --version(asyncBun.spawn, same pattern as oxlint's--helpprobe) and returns the system path only on exit 0.findSystemDartis not re-exported publicly (server/index.tsimports onlyDartServer). This is thesrc/server/dart.ts:120item that test(lsp): skip dart integration tests when dart cannot run #128 listed as remaining work.Verification
packages/lsp/test/unit/server.test.tsuse a fake failing and a fake workingdarton PATH. They run in a child bun process becauseBun.whichreads PATH at process startup.bun run typecheckpasses, eslint is clean, andbun test ./test/unitinpackages/lspgives 162 pass / 0 fail.LSPManagerontest/fixtures/dart-projectskipped the shim, started from the cached SDK in\~/.cache/dora/dart-lsp, reportedconnected, andworkspaceSymbol('Calculator')returned 1 result.bun run testwas not run locally because the Vue integration tests still fail locally (VueServer and DartServer integration tests fail locally in packages/lsp #127). CI covers it.Related issue
Refs #127 (it also covers the Vue integration failures, which remain open)
Checklist
bun run testis left to CI)bun run lint)Summary by cubic
Fixes the Dart LSP server crashing when the system
dartresolves on PATH but cannot actually run, such as a mise shim without an SDK version configured. The server now probes the systemdartwithdart --versionand falls back to the auto-downloaded SDK when it cannot run.findSystemDart()looks updarton the current PATH and returns the resolved path only whendart --versionexits 0 in the project root within a 10s timeout.dartscripts on PATH, skipped on Windows.Written for commit a13a4f6. Summary will update on new commits.