Skip to content

S4: language server in Track as trackc lsp - #37

Merged
dev-dami merged 14 commits into
mainfrom
agent/s4-lsp
Nov 22, 2026
Merged

dev-dami merged 14 commits into
mainfrom
agent/s4-lsp

Conversation

@dev-dami

Copy link
Copy Markdown
Owner

Third step of retiring Rust: the language server is ported from src/lsp (Rust, tower-lsp) into trackc. The Rust server stays until S5 deletes src/.

What

  • compiler/src/lsp.trk. JSON-RPC 2.0 over stdio, with Content-Length framing (LF-only headers and extra headers are accepted), plus a small JSON reader and writer. main.trk only gains the lsp dispatch.
  • Analysis runs out of process. fail_at exits and Track has no unwinding, so each check runs as exec timeout -k 1 $secs "/proc/$PPID/exe" lsp --check <tag>. The buffer is loaded under its real path, so imports resolve. Diagnostics are parsed back into LSP JSON. A checker crash becomes a diagnostic; it does not kill the server.
  • Features, matching the Rust server:
    • initialize and initialized
    • diagnostics on didOpen, didChange and didSave, including markdown ```track blocks
    • completion: keywords, types, built-ins, macros, the file's own functions and variants
    • hover
    • shutdown and exit
    • error codes -32601, -32002, -32600 and -32700
  • Better than Rust: diagnostics now carry real line, column, code and warnings. Rust put everything at 0:0.
  • Hardening (S4b):
    • Check timeout: TRACKC_LSP_TIMEOUT, default 10s. On timeout the server publishes "check timed out" and stays responsive, with no sh in between and no orphans.
    • Temp dir: named from a /proc UUID, created with checked mkdir -m 700, and it fails closed. A reaper removes it on SIGTERM.
    • NUL bytes: a raw NUL gets a parse error instead of killing the server.
  • Runtime: adds track_stdin_read(n). file_read_all and rt_read_fd now read to end of file instead of trusting ftell or lseek, so /proc files work. As a side effect, reading a directory on the C backend no longer crashes; it returns "".
  • Seed: regenerated through the TRACKC route, because the runtime changed. update_seed.sh --check passes.
  • Tests: tests/lsp/run.sh runs 17 recorded sessions. They cover timeouts, planted symlinks, fail-closed and NUL bytes. The expected .out files are now committed; .gitignore had been dropping them.
  • Editors: editor/nvim and docs/lsp.md now launch trackc lsp.

Checks

  • S4 independent check: passed with notes. No regression against the Rust server. It tried split and merged messages, UTF-8, 200 rapid edits, a 1 MB document, symlinks and sh -c launch. It found two issues: no child timeout, and a guessable temp tag. Both are fixed in S4b.
  • S4b independent check: passed.
    • Runtime reads were identical to main on both backends, from 0 bytes to 10 MB, including the 4096 boundary and /proc.
    • A fresh clone with PATH=/usr/bin:/bin bootstraps from the new seed to the fixed point, and n2 = n3 = n4.
    • The LSP suite passes 17/17 and catches a tampered .out file.
    • SIGTERM mid-check leaves no processes and no temp dir.
  • Gates:
    • embed checks pass
    • seed bootstrap fixed point holds
    • selfhost n2 = n3 = n4
    • native parity is 60 SAME
    • check --deny-warnings passes
    • fmt is clean
    • cargo test has 0 failures
  • Perf: native self-compile takes 3.15% more instructions. All of it comes from compiling the roughly 690 new lines. On the same input the compiler is no slower (+0.03%).

🤖 Generated with Claude Code

dev-dami and others added 14 commits November 22, 2026 11:48
Adds compiler/src/lsp.trk, the track_stdin_read runtime primitive (C and
Track runtimes), loader load_source, and the tests/lsp session runner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fe reads

- the --check child runs under exec timeout -k 1 $TRACKC_LSP_TIMEOUT (10s),
  with a watchdog fallback; a timeout publishes one diagnostic
- the scratch dir is a kernel UUID made by mkdir -m 700 with its status
  checked; on failure diagnostics are off and one logMessage says so
- a reaper removes the dir when the server dies without lsp_quit
- a short body (raw NUL) gets a parse error instead of ending the server
- C runtime file_read_all reads to EOF like rt_read_fd (procfs, pipes)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e_read_all)

Built with TRACKC=<trackc from this tree> scripts/update_seed.sh: the old
seed has no track_stdin_read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The native runtime sized reads by lseek, so read_text of /proc files was
empty and the native trackc lsp could not make its scratch dir. The slow
case grows to 12000 lets so the native checker also outlasts 1s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 774dca51-351e-4bbd-a5e8-6b3a83aa0b42
Commits

Reviewing files that changed from the base of the PR and between 9c6f813 and 90960a2.

Files ignored due to path filters: 14

  • tests/lsp/cases/basic.out is excluded by !**/*.out
  • tests/lsp/cases/checker_error.out is excluded by !**/*.out
  • tests/lsp/cases/completion.out is excluded by !**/*.out
  • tests/lsp/cases/end_of_input.out is excluded by !**/*.out
  • tests/lsp/cases/exit_without_shutdown.out is excluded by !**/*.out
  • tests/lsp/cases/fail_closed.out is excluded by !**/*.out
  • tests/lsp/cases/hover.out is excluded by !**/*.out
  • tests/lsp/cases/imports.out is excluded by !**/*.out
  • tests/lsp/cases/markdown.out is excluded by !**/*.out
  • tests/lsp/cases/nul_byte.out is excluded by !**/*.out
  • tests/lsp/cases/planted.out is excluded by !**/*.out
  • tests/lsp/cases/protocol.out is excluded by !**/*.out
  • tests/lsp/cases/syntax_error.out is excluded by !**/*.out
  • tests/lsp/cases/timeout.out is excluded by !**/*.out
Files selected for processing: 31

  • .gitignore
  • bootstrap/seed/trackc.c
  • bootstrap/seed/trackc.rt.c
  • compiler/rt/io.trk
  • compiler/rt/sys.trk
  • compiler/src/checker.trk
  • compiler/src/life.trk
  • compiler/src/loader.trk
  • compiler/src/lsp.trk
  • compiler/src/main.trk
  • compiler/src/runtime_c.trk
  • compiler/src/runtime_trk.trk
  • docs/lsp.md
  • editor/nvim/README.md
  • editor/nvim/lua/track.lua
  • editor/nvim/track.lua
  • runtime/track_runtime.c
  • src/checker/mod.rs
  • tests/lsp/cases/basic.in
  • tests/lsp/cases/broken_helper.trk
  • tests/lsp/cases/checker_error.in
  • tests/lsp/cases/completion.in
  • tests/lsp/cases/end_of_input.in
  • tests/lsp/cases/exit_without_shutdown.in
  • tests/lsp/cases/helper.trk
  • tests/lsp/cases/hover.in
  • tests/lsp/cases/imports.in
  • tests/lsp/cases/markdown.in
  • tests/lsp/cases/protocol.in
  • tests/lsp/cases/syntax_error.in
  • tests/lsp/run.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dev-dami
dev-dami merged commit c1106d7 into main Nov 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant