# lucisv for VS Code A thin extension: it registers the Verilog/SystemVerilog file types and starts `lucisv-server`. Every *analysis* feature you see — formatting, diagnostics, semantic highlighting, hover, go-to-definition, references, symbols — comes from the server, so this directory contains no language logic and no editor-specific commands. The two exceptions are the snippet library and the TextMate grammar below, both static data VS Code reads straight from the manifest — LSP has no channel for either. See `docs/features/lucisv-server/README.md` for the capability list, `docs/features/editor-packaging/README.md` for why the extension looks like this, and `docs/features/editor-snippets/README.md` for the snippets. ## 1. Build the server ```bash cargo build --release # from the repo root; binary at target/release/lucisv-server ``` Put it on your `PATH`: ```bash cp target/release/lucisv-server ~/.local/bin/ # or wherever your PATH points ``` Or leave it in `target/release` and point the extension at it with the `lucisv.serverPath` setting (below). ## 2. Smoke-test the spawn contract (no editor needed) `smoke.js` spawns the server exactly the way `extension.js` does — same argument list (none), same cwd, same inherited environment — and drives a full `initialize` / `didOpen` / `shutdown` / `exit` session over stdio with hand-rolled `Content-Length` framing. Plain `node`, no dependencies. ```bash node smoke.js # `lucisv-server` from PATH node smoke.js ../../target/release/lucisv-server # an explicit binary ``` It prints `smoke: OK — …` and exits 0, or names the failure and exits 1. Run it after every server change and before packaging: it is the only check that catches "the binary moved" or "the handshake broke" without launching VS Code. ## 3. Install the extension ```bash npm ci # installs vscode-languageclient (the only dependency) npx @vscode/vsce package code --install-extension lucisv-0.5.0.vsix ``` Then reload VS Code and open a `.v`/`.sv`/`.vh`/`.svh` file. `tools/release.sh` from the repo root does all of the above (plus the release binaries and checksums) and drops the `.vsix` in `dist/`, so `code --install-extension dist/lucisv-0.5.0.vsix` is the one-command path. `editors/vscode/LICENSE` is a copy of the repo's MIT license and is what lets `vsce package` run without `--skip-license`. If you are packaging a fork that dropped `package.json`'s `repository` field, add `--allow-missing-repository`. **Running from source instead**, for development: open this directory in VS Code and press F5. That starts an Extension Development Host with the extension loaded from disk, with no packaging step. **Sideloading is the supported install.** Marketplace publishing is optional and deferred: `publisher` is `guoliangchen` (unregistered on any marketplace), so `vsce publish` would fail, while packaging a `.vsix` and installing it locally works exactly as above. `tools/RELEASING.md` records what publishing would take if it ever happens. ## Settings | Setting | Default | What it does | |---|---|---| | `lucisv.serverPath` | `"lucisv-server"` | Path to the executable. A bare name is looked up on `PATH`; an absolute path is used as given. | | `lucisv.rainbowBeginEnd` | `true` | Colour each nesting level of `begin`/`end` and `fork`/`join` differently, and half a pair in an error colour. Takes effect immediately — no reload. | | `lucisv.lineLength` | unset | Maximum line width, same as `line-length` in a `lucisv.toml`. 40–400. | | `lucisv.indent` | unset | Indent width in spaces, same as `indent` in a `lucisv.toml`. 1–8. | | `lucisv.exclude` | `[]` | Extra patterns to keep out of the workspace index, same as `exclude` in a `lucisv.toml`. **Added to** the project's excludes, never replacing them. | | `lucisv.filelist` | `""` | Path to an EDA filelist (`.f`), absolute or relative to the workspace folder. When set, exactly the files it names are indexed. Overrides a `filelist` key in the project's `lucisv.toml`. | The last four mirror the four keys `lucisv.toml` supports, for people with no config file in the tree. **A `lucisv.toml` always wins over them** — except `lucisv.filelist`, which is a scope, not a style, and is explained below. So a project that checks one in keeps one source of truth and format-on-save cannot drift from CI's `lucisv --check`. Full precedence, highest first: 1. `lucisv.toml`, discovered per file exactly as the CLI discovers it. 2. `lucisv.lineLength` / `lucisv.indent` — typed on purpose, but one user's editor. 3. VS Code's tab size — sent on every request whether or not you chose it, so the weakest thing that is still a signal. (`lucisv.lineLength` has no analog here at all: LSP carries no line-length option.) 4. The built-in defaults: indent 2, width 100. Each rung applies only where the ones above it say nothing, so a `lucisv.toml` naming only `indent` still lets `lucisv.lineLength` choose the width. Changes take effect on the next format — no reload — and out-of-range or wrong-typed values are ignored rather than half-honoured. ## Which files are indexed Navigation, hover and workspace symbols answer from an index of the project's files. What goes into it, highest first: 1. **A filelist**, if there is one — `lucisv.filelist`, else a `filelist` key in the project's `lucisv.toml`. Exactly the files it names are indexed, so a vendored copy your build does not compile stops showing up in go-to-definition. Standard `.f` syntax: one path per line, `-f other.f` to nest, `+incdir+`/`+define+` (recorded, unused for now), `#` and `//` comments, `$VAR`/`${VAR}` expansion, paths relative to the filelist itself. 2. **The workspace folder**, walked as `lucisv` itself walks it — same extensions, same `.gitignore`, same excludes. 3. **The open file's own directory**, when no folder is open at all. Open buffers are always indexed on top of that, so a scratch file the project does not list still works. A filelist that names a file which has moved warns and skips it; a filelist that cannot be read at all warns and falls back to walking the folder — the index is never silently empty. ## Syntax highlighting Two highlighters, and they are not rivals: - **Semantic tokens, from the server.** What actually colours your buffer while the server is running — it knows a name is a port, a parameter or a macro, which no regex can. Fourteen token types; nothing to configure. - **A TextMate grammar, from this extension** (`syntaxes/`). Keywords, comments, strings, numbers (`8'hFF`, `4'b10xz`, `'0`, `1.5e-3`, `10ns`), `$system_tasks`, `` `directives `` and macro uses. Semantic tokens win wherever they have something to say, so in a live buffer this mostly fills in the gaps — but it is the only highlighter in three places that matter: **hover cards and completion documentation** (the server sends those as ```` ```systemverilog ```` markdown, and markdown is coloured by grammar, not by semantic tokens), a file before the server has started, and previews VS Code renders without a language server at all, such as a diff or a git blame. One grammar file serves both `verilog` and `systemverilog`, because lucisv's lexer draws no line between the two. Its keyword list is generated from that lexer's own list and a test in the repository fails if they drift apart. It covers no operators and no `(* attributes *)` — see `docs/features/editor-packaging/README.md` for why. ## Rainbow begin/end Each nesting level of `begin`/`end` and `fork`/`join` is coloured differently, and a keyword whose counterpart is missing — a `begin` you have just typed, an `end` that closes nothing — is painted in a bright error red until you finish the pair. The pairs are matched by the server over the token stream, not by a regex, so an `end` inside a comment or a string is never coloured and the `end` that lights up is genuinely the one that closes that `begin`. The seven colours are the extension's own, so they are always visible whatever theme you use, and you can change any of them in `workbench.colorCustomizations`: ```jsonc "workbench.colorCustomizations": { "lucisv.rainbow1": "#FFD700", // and rainbow2 … rainbow6 "lucisv.rainbowUnmatched": "#FF1212" // the half-pair colour } ``` (They are deliberately *not* `editorBracketHighlight.foreground1`…`6`: VS Code defaults the last three of those to transparent, so borrowing them made deeply nested `begin`s invisible in most themes.) Turn it off with `"lucisv.rainbowBeginEnd": false`; the colours disappear immediately. Cursor on a `begin` also highlights its matching `end` — that is `documentHighlight`, always on, and it needs no setting. ## Snippets Type a prefix and pick the snippet from the completion list; `Tab` walks the placeholders. These are the **file-level** templates, a static manifest contribution, so they work with no server on `PATH` and before the extension has activated. Bodies are dialect-specific — `module` gives `input wire` in a `.v` file and `input logic` in a `.sv` one. The everyday statement and block templates — `if`, `if/else`, `else if`, `case`, `for`, `while`, `always_ff`, `always_comb`, `always @(...)`, `initial` and the `logic`/`reg`/`wire`/`parameter` declarations — come from the **server** instead, since 0.4.0: they are offered only where the construct may actually be written, and they were removed from the lists below so no prefix offers the same thing twice. See `docs/features/completion-templates/README.md` in the repository. | Verilog (`.v`, `.vh`) | | |---|---| | `module` | module with a port list | | `function` / `task` | Verilog-2001 declaration with an ANSI argument list | | `genfor` | `generate`+`genvar` loop with a named block | | `tb` | testbench module: clock, reset, `$display`, `$finish` | | `guard` | `` `ifndef ``/`` `define `` include guard from the file name | | SystemVerilog (`.sv`, `.svh`) | | |---|---| | `module` / `modulep` | module with ports / with a parameter list too | | `uniquecase` | `unique case` with a `default` arm | | `fsm` | two-process state machine: enum, next-state logic, state register | | `enum` / `struct` | `typedef enum` / `typedef struct packed` | | `function` / `task` | `automatic` declaration | | `interface` | interface with two modports | | `package` / `class` | package named after the file / class with a constructor | | `assertp` | labelled concurrent assertion with `disable iff` and `$error` | | `genfor` | `for (genvar …)` with a named block | | `tb` | testbench module: clock, reset, `$finish` | | `guard` | `` `ifndef ``/`` `define `` include guard from the file name | To add your own without editing the extension, use VS Code's **Snippets: Configure Snippets** command and pick `verilog` or `systemverilog`; user snippets sit alongside these, they do not replace them. ## Format on save The extension registers no formatter of its own — the server advertises `documentFormattingProvider`, so VS Code's normal machinery applies: ```jsonc // .vscode/settings.json { "[verilog]": { "editor.formatOnSave": true }, "[systemverilog]": { "editor.formatOnSave": true } } ``` ## Troubleshooting - **Nothing happens on a `.sv` file.** Check the language mode in the status bar. Another Verilog extension may own the `.sv` extension with a different language id; this one attaches to `verilog` and `systemverilog`. - **"command not found" style failure on startup.** The server is not on `PATH`. Set `lucisv.serverPath` to an absolute path, and confirm the binary itself works with `node smoke.js `. - **See what the server is saying.** View → Output → the `lucisv` channel carries the client/server log, including anything the server writes to stderr.