Editor
Get live, cross-file SAFE-TS diagnostics, hover failure traces, and one-click quick fixes right in your editor via the built-in language server (safe-ts lsp).
In short
- Full language server:
safe-ts lspchecks.ts,.tsx,.mts, and.vuefiles as you type, suggests quick fixes, and displays every possible failure path when hovering a call. - Live cross-file analysis: reads unsaved editor buffers across imports just like
safe-ts check. - VS Code extension: lives in
packages/vscode-safe-ts(not yet on the Marketplace—launch from source or install a locally built VSIX).
What it does
The same checks as
safe-ts check, run when a file is opened or saved, and 150 ms after you stop typing. A call into another file that can throw is reported here too, with its failure path.Unsaved text counts. Open files are read from the editor, also when another file imports them. Fix a function in one tab, and the call to it in another tab stops being reported.
Dependents are checked again. When a file changes, every open file whose check read it is checked again. This includes files that change on disk without being open (after a
git checkoutor a formatter run), if the editor reports the change. VS Code does.Quick fixes are the ones
safe-ts checklists as= fix:lines, offered as code actions. To apply one rule's fixes across many files from the command line, usesafe-ts fix <rule> <files or dirs>(Applying one rule's quick fixes).Hover on a call lists the ways it can fail, and the path each failure takes:
load() can fail: - throws, not as a `PropagateError`: load → JSON.parse() at helper.ts:3:10It covers calls to your own functions (what they throw, what the promise they return rejects with,
PropagateErrorkinds, aResultreturn type) and library calls a feature pack or automatic mode knows about. The first time a file imports a package, the package is analyzed once for its installed version (pixi.js: about 140 ms) and cached on disk; after that it is a file read.Imports it can't follow are underlined as warnings on the specifier:
could not resolve "@utils/b". What such an import brings in isn't checked with the file, so an alias missing from tsconfig.jsonpathsshows here first (How imports are followed).Severities come from the oxlint preset (rules it sets to
warnare warnings, the rest errors), unless package.json changes a rule's level for that file (rule levels). A rule set to"off"there isn't shown. Each problem links to its rule page.
VS Code
The extension isn't published yet. Here is how to run it from the repository:
sh
npm install
npm run build # builds safe-ts and copies it to packages/safe-ts-native/bin/
code --extensionDevelopmentPath="$PWD/packages/vscode-safe-ts" path/to/your/projectTo install it as a package: vsce can't package it from inside the npm workspace, so copy the folder out first.
sh
cp -r packages/vscode-safe-ts /tmp/vscode-safe-ts && cd /tmp/vscode-safe-ts
npm install --no-workspaces
npx @vscode/vsce package --skip-license
code --install-extension vscode-safe-ts-0.6.0.vsixThe server is the safe-ts CLI. Each platform package of the native addon (@evobug_com/safe-ts-native-linux-x64-gnu, -darwin-arm64, -win32-x64-msvc, ...) carries it as bin/safe-ts (bin/safe-ts.exe on Windows), next to the addon. So a project that installs @evobug_com/safe-ts-transform or the oxlint plugin already has the server that matches them. @evobug_com/safe-ts-native also puts a safe-ts command on the PATH of package.json scripts, npx and bunx (with pnpm, add @evobug_com/safe-ts-native as a dev dependency for that): npx safe-ts lsp starts the server for an editor that takes a command, and npx SAFE-TS --version says which one you have. The extension runs the binary directly, without Node in between.
The extension looks for the server in this order:
- The
safeTs.pathsetting. A relative path starts at the workspace folder. - In the workspace folder's
node_modules/@evobug_com/(and in each parent folder's):safe-ts-native/bin/safe-ts, a build from the repository:npm run buildcopies it there, both in this repository and in projects that use its packages as workspace packages.safe-ts-native-<platform>/bin/safe-ts, the one npm installs. pnpm keeps it undernode_modules/.pnpm/node_modules/, which is checked too.
safe-tsonPATH.
After a rebuild, run SAFE-TS: Restart language server.
If you also run the oxc extension with the SAFE-TS oxlint plugin, every problem shows up twice, once from each. In .vue files oxlint hands the plugin one script block at a time, so template problems from the plugin sit at the top of <script setup>, naming their line, and a component with two script blocks is checked as saved (Vue setup). The language server points at the template itself. Keep oxlint for CI either way.
Other editors
Any editor with an LSP client can run safe-ts lsp (or npx safe-ts lsp, bunx safe-ts lsp from the project). It talks over stdio and handles TypeScript and Vue files. None has been tried yet, so there is no setup to copy here.
What was tried
| Editor | Tried |
|---|---|
| VS Code 1.144.1 (Linux build, under WSL) | ✅ the extension, both run from the repository and installed as a VSIX. Tested: problems in .ts and .vue files (without the Vue extension), a quick fix, unsaved edits in an imported file, and the hover |
| Neovim, Helix, Zed, JetBrains IDEs, others | not tried |
In the repository, crates/safe_ts_cli/tests/lsp.rs drives the server over stdio, the way an editor does.
What it can't do yet
- Only open files get problems. To check the whole program, run
safe-ts check. - The warnings
safe-ts checkprints are not shown: a feature pack outside its library's version range or without rules, a tsconfig flag SAFE-TS relies on left off (the table), or a package.json script that runs TypeScript without the loader. - An error type that doesn't fit the function's declared one (through
q) is still only found by the emitted type-check (Adopting SAFE-TS). - In a workspace with several folders, paths in messages are relative to the first one.