80 lines
4.3 KiB
Markdown
80 lines
4.3 KiB
Markdown
# Editing native TSX in VS Code
|
|
|
|
Open `kryon.code-workspace` from the repository or a generated app in VS Code
|
|
and install **Ziran Language** (`kryonlabs.ziran-language`) from
|
|
[ziranlang/ziran-vscode](https://git.waozi.xyz/ziranlang/ziran-vscode).
|
|
The repository and the `app`, `pages`, `tui` and `web` starters carry the same
|
|
editor settings. An extension update requires reloading an already open window.
|
|
Opening a file by itself does not load project settings; the workspace file selects this folder
|
|
and its native checking configuration explicitly.
|
|
|
|
## What is declared
|
|
|
|
`.ts` uses VS Code's built-in **TypeScript** language and `.tsx` uses
|
|
**TypeScript React** (`typescriptreact`). This is the built-in TSX grammar;
|
|
Kryon does not use React and does not need a fork of a TypeScript extension.
|
|
The `tsconfig.json` selects preserved JSX, no JavaScript emit and no implicit
|
|
DOM or npm `@types` libraries. It describes the editor project, not the native
|
|
build. Use the ordinary `kryon`/`ziran` commands to build.
|
|
|
|
These files are Ziran's native TypeScript frontend, which differs from
|
|
JavaScript TypeScript. Its imports resolve through `ziran.toml` exports and
|
|
`ziran.lock`, including real checked Ziran records and functions. Native scalar
|
|
conversions such as `s32(32)`, references such as `NativeRef<Native.State>`,
|
|
borrowed slices and value-returning JSX are part of that frontend. JSX is a native function
|
|
call: `<Button .../>` can return a boolean and `<Text .../>` returns void.
|
|
|
|
The compiler emits editor declarations from those checked native types. The
|
|
extension's TypeScript server plugin resolves the exact imports for each authored
|
|
file and supplies the native globals and JSX contract. Keep generated declarations
|
|
in `build/.ziran/types`; do not maintain copies of widget records or install React
|
|
declarations.
|
|
|
|
## What checks the files
|
|
|
|
Keep `js/ts.validate.enabled` enabled. Built-in TypeScript diagnostics,
|
|
completion and hover use the compiler-generated declarations through the Ziran
|
|
plugin. Ziran checks the native types, ownership, lifetimes and target rules;
|
|
stock TypeScript checks the syntax and types it understands. TypeScript checking
|
|
does not replace the native compiler check.
|
|
|
|
Use **Ziran: Check Current File**, **Run** or **Preview** to run the actual
|
|
compiler. For native TS/TSX the extension invokes
|
|
`ziran api --typescript --out build/.ziran/types --project FILE`, then refreshes
|
|
the TypeScript project. Problems from the native checker have source `ziran`:
|
|
unknown imports, invalid fields, types and native lifetime rules remain errors.
|
|
Those actions save the selected source before checking. Typing, opening,
|
|
saving (including auto-save) and switching files never start compiler checks
|
|
or rebuild previews. Native completion and hover use declarations from the last
|
|
explicit check; after edits, check or build again to refresh them. Stock
|
|
TypeScript services continue using the last generated bindings while editing.
|
|
A failed generation invalidates the old import mappings; unresolved imports
|
|
remain visible. If the extension is missing or the toolchain cannot run, native
|
|
checking is unavailable.
|
|
For a direct check from the repository root:
|
|
|
|
```sh
|
|
ziran check examples/hello.tsx
|
|
```
|
|
|
|
Use the project's pinned toolchain and package configuration; an optional local
|
|
checkout override belongs in ignored `ziran.local.toml` as usual. Do not install
|
|
React, `@types/react`, an npm package named `kryon`, or replace a native import
|
|
with a relative JavaScript import to satisfy TypeScript.
|
|
|
|
Use `nativeInit<RecordType>({...})` when storing a partially specified native
|
|
record: it applies the native record's zero/default initialization and gives the
|
|
editor the complete checked type. Native integer conversions such as `s32(7)`
|
|
keep arithmetic and action arguments explicit. Wide IDs remain native integers;
|
|
do not convert them to a JavaScript `number` for the editor.
|
|
|
|
## Inspecting the pipeline
|
|
|
|
Use **Ziran: Run** or the editor's **▶** button on a `.zi`, `.ts` or `.tsx`
|
|
source. The Run pane or Kryon preview shows the available checked IR and target
|
|
stages. `.zir` is checked binary IR
|
|
and `.zx` is a binary portable executable/library; the Ziran extension supplies
|
|
binary inspection views. They are not source text and should not be associated
|
|
with TypeScript or given a text grammar. Unsupported backend operations still
|
|
report the real compiler error.
|