safe-ts lsp: a language server, with a VS Code extension #17
Loading…
Reference in a new issue
No description provided.
Delete branch "lsp-server"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
A SAFE-TS language server,
safe-ts lsp, plus a minimal VS Code extension that starts it. Until now the editor only got SAFE-TS through the oxlint plugin, which can't run on.vuefiles and sees one file at a time, read from disk.Server (
crates/safe_ts_cli/src/lsp.rs, stdio).ts/.tsx/.mts/.vuefiles. They come on open, on save, and after a change (150 ms debounce, at most 1 s while typing). They use the same checks assafe-ts check(Run::diagnostics_for), so failures are followed into other modules.Project::set_overlaymakes every read of an open file use the buffer, including when another file imports it.Project::check_file_with_dependenciesreturns the files a check read. When one of them changes (an edit, open, close, save, or a watched-file event for a file that isn't open), the open files that read it are checked again. The server registers file watchers when the client supports dynamic registration. A change topackage.json/tsconfig*.json/safe-ts.json, or a file being created or deleted, rebuilds theProject, because config and resolver results are cached.fixes.rs(theLocatedDiagnostic::fixes) are returned asquickfixcode actions.Project::call_failures. It shows thrown non-PropagateErrorfailures with their path,PropagateErrorkinds (rejects when async), aResultreturn type, and library calls that a feature pack or automatic mode knows about.recommended.json:warnthere is a warning here. Diagnostics link to their rule page. A checker panic is caught and logged; it doesn't kill the server.Why lsp-server + lsp-types: these are rust-analyzer's crates, maintained (lsp-server 0.10.0, July 2026). The loop is synchronous over crossbeam channels. The checker is synchronous and fast, so tower-lsp's async/tokio stack would add a runtime for nothing, and debouncing is just
recv_deadline. (tower-lsp itself hasn't had a release since 2023; its maintained fork is tower-lsp-server.)VS Code extension (
packages/vscode-safe-ts, plain JS,vscode-languageclient10.1.2, not published)@evobug/safe-ts-native-<platform>carriesbin/safe-ts(bin/safe-ts.exeon Windows) next tosafe-ts.node, so npm installs exactly the matching one, version-locked to the addon, and@evobug/safe-ts-transform/ the oxlint plugin bring it along.@evobug/safe-ts-nativeitself stays a loader. In the repository,npm run build(scripts/copy-addon.mjs) still copies the CLI topackages/safe-ts-native/bin/(gitignored), next to the localsafe-ts.node.server-path.js, novscodeimport, so it can be tested outside VS Code) in:safeTs.path; then, in each workspace folder and its parents,node_modules/@evobug/safe-ts-native/bin/(repository build),node_modules/@evobug/safe-ts-native-<platform>/bin/(npm), and the same undernode_modules/.pnpm/node_modules/(pnpm); thensafe-tsonPATH. The platform id is worked out like the loader's (linux-x64-gnu,win32-x64-msvc, ...).build-native.mjsbuildssafe_ts_cliwith the addon,stage-native.mjsstages both (--checkrequires both),build-packages.mjslistsbinin the platform packages'files.copy-addon.mjscopies the CLI only when it was built, because the bench, pages and release workflows build onlysafe_ts_napibefore calling it; the release job's platform packages get their CLI frombuild-native.mjs.verify-packages.mjschecks the CLI is in the host tarball and executable after install, runssafe-ts checkand an LSP initialize/shutdown with it, and checks the extension's lookup resolves to it. With the CLI, the Linux x64 platform package packs to 3.9 MB (the CLI is 5.8 MB unpacked, the addon 4.6 MB)..vuefiles are matched by pattern, so it works without the Vue extension.SAFE-TS: Restart language servercommand, and changingsafeTs.pathrestarts the server too.Docs: a new
docs/guide/editor.md(in the sidebar after Adopting), plus updates to quick-start, adoption (setup),vue/setup.md(table and text), thevue/index.md"Where it runs" table, theindex.md"Where it runs" section and playground caption,docs/README.md, and the README (layout, editor, quick fixes, Vue, tests).Which editors were tried
@vscode/test-electron(scratch harness in /tmp, not committed) and--disable-extensions, so the Vue extension was not installed. I ran it two ways: as a development extension (--extensionDevelopmentPath), and installed from a VSIX built exactly as the docs describe. Both passed the same script:no-nullproblems shown, and "Replace null with undefined" applied as a code actionApp.vue(languageIdplaintext) getsunhandled-failureon its template linemain.tsgets the cross-file failureload() can fail: throws … load → JSON.parse() at helper.ts:3:10helper.tsclearsmain.tsRebased onto main at
1fe2d1dRebased onto
mainat1fe2d1d(after #2, #3, #4, #5, #6, #8, #9, #10, #11, #12, #13, #16, #23). What had to change:lib.rs(the export list, with #10'sTransformOptions) and the README (#16's bench paragraph and this PR's editor paragraph, both kept).CallSite::calleeis now aCalleeenum; the hover label usescall.name(the callee as written), as the diagnostics do. #2's resolver filter and #5's call-following apply to the LSP unchanged:analyzeis still the only place files are read, so overlays cover the new paths too.PropagateErrorkind rejects by the callee'sasynckeyword. It now uses the failure chain's throws/rejects and each kind's ownrejects(newCallFailure::Rejects { error: Option<_>, path },Propagates { rejects }). New stdio testhover_tells_rejections_from_throws; it fails on the previous code ("propagatesGone" for a rejection).bench.ymlrunscargo build -p safe_ts_napi && node scripts/copy-addon.mjs, and this PR'scopy-addon.mjsrequired the CLI. Fixed incopy-addon.mjs(last commit). Locally,npm run bench:checkon this branch passes all ratios; the twonewentries (no-accumulating-copy, stable-shape bench blocks) come from main and have no baseline there either, which the check doesn't fail on.Tests
After the rebase:
cargo nextest run --workspace: 111 passed, 0 failed.crates/safe_ts_cli/tests/lsp.rs(4 tests, including the new hover one) run 10 times in a row: 4/4 each time.npm run test:std: 130 passed, 0 failed.npm run test:vite: passed.npm run typecheck: passed.npm run test:docs: passed (docs typecheck, wasm, VitePress build, no dead links).node scripts/verify-packages.mjs: all checks passed, including the new CLI checks (ok: @evobug/safe-ts-native-linux-x64-gnu/bin/safe-ts runs check and lsp, and the VS Code extension finds it).node_modules/.pnpm/node_modules/@evobug/safe-ts-native-linux-x64-gnu/bin/safe-ts, and it ran.cargo xwin build --release --locked -p safe_ts_napi -p safe_ts_cli --target x86_64-pc-windows-msvcbuilt; staged withstage-native.mjs win32-x64-msvc <dll> <exe>, the Windowssafe-ts.exe(run through WSL interop) answered an LSP initialize and shutdown.npm run bench:check: passed locally (29 ratios).node scripts/copy-addon.mjswith and withouttarget/release/safe-ts: copies the CLI, or skips it with a note.Before the rebase (unchanged tests, on
0e01fb3): the stdio tests drove initialize/diagnostics, a code action applied with an incrementaldidChange, full-text change anddidClose, a.vuefile, and the cross-file case (failure path, hover, unsaved fix in the imported buffer, close going back to disk,didChangeWatchedFiles), plus unit tests for UTF-16 positions, URIs and preset severities. The VS Code runs described above were done before the rebase; I didn't repeat them in VS Code after it.Left out / uncertain
safe-ts check.safe-ts check's warnings (pack version range,noUncheckedIndexedAccessoff) aren't shown.$/cancelRequestis ignored.npx safe-tsshim: the CLI is found by path (the extension, ornode_modules/@evobug/safe-ts-native-<platform>/bin/safe-tsby hand). Yarn PnP isn't handled; there, setsafeTs.path.🤖 Generated with Claude Code
ef8861ff9fto57b61533cb