Files
lucioandClaude Fable 5 81df63d942 Bind semantics, the spaced macro call and the directive inside a connection, and lucisv.instantiate
TODO section 26; closes docs/topo.md 2.9-15 and 2.9-19; coverage_gaps
M4/M5/M6 corrected against a fresh opentitan census.
A bind directive's target is a path of segments with optional indices
(bind top.gen[0].u_core chk u_chk (...)); a lone target binds as a
module reference, an instance path records nothing rather than a guess.
Each connection's port half resolves against the module being bound in
and its expression half in the target module's scope first, the
workspace's member path when the target lives elsewhere, the writing
scope last (Target::BindScope, resolve::in_bind_target - the
inline-constraint shape). FACTS_FORMAT 14 -> 15: binds now post
references and an instantiation edge.
Expression-position spaced macro calls (assign x = `WIDTH (a + b);)
keep the author's gap, read from the source as glued_null_item reads
its gap; verify.rs untouched, both pins stand. A conditional directive
inside a connection value becomes ExprKind::Verbatim, byte-exact
through raw_inline as Doc::Inline, with the closing paren's line and
the list's break read from the source - so the instantiation keeps its
edge, lens and port references instead of collapsing to opaque bytes
(opentitan: the two padring sites in chip_earlgrey_{asic,cw340}.sv,
+2 edges, everything else byte-identical to 0.31.0).
lucisv.instantiate [uri, position, module] renders the inline ghost's
plan as plain text through workspace/applyEdit for clients without
inline completion; the Neovim README documents it.
QA: 3186 tests / 47 binaries, corpus 814/820, independent binary diff
over corpus and 2 645 opentitan files: only the two named files differ.

docs/features/bind-semantics/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-09-02 13:15:21 -07:00
..

lucisv for Vim / Neovim

There is no plugin here, on purpose: lucisv-server speaks plain LSP over stdio, and every editor in this family already ships a client. What follows is configuration, not code.

Build the server first and put it on your PATH:

cargo build --release           # from the repo root
cp target/release/lucisv-server ~/.local/bin/

Neovim 0.11+ (built-in vim.lsp.config, no plugins)

Neovim 0.11 has a native LSP configuration API — nvim-lspconfig is no longer needed for a server this simple.

-- ~/.config/nvim/init.lua
vim.filetype.add({ extension = { v = 'verilog', vh = 'verilog', sv = 'systemverilog', svh = 'systemverilog' } })

vim.lsp.config('lucisv', {
  cmd = { 'lucisv-server' },
  filetypes = { 'verilog', 'systemverilog' },
  root_markers = { 'lucisv.toml', '.lucisv.toml', '.git' },
})

vim.lsp.enable('lucisv')

Use an absolute path in cmd ({ '/path/to/target/release/lucisv-server' }) if you would rather not install the binary.

The vim.filetype.add line is not boilerplate. In the stock runtime (checked against vim 9.1's filetype.vim, which Neovim's tables descend from) *.sv and *.svh map to systemverilog outright, but *.v goes through a content heuristic — dist#ft#FTv() chooses between Verilog, Coq and V by sniffing the first lines — and *.vh is not mapped at all. Without the line, a short or unusual .v file can land on the wrong filetype and a .vh header never attaches the server. Drop the v = entry if you also write Coq or V.

Neovim 0.9 / 0.10 (nvim-lspconfig)

lucisv is not in nvim-lspconfig's registry, so register the config yourself:

local configs = require('lspconfig.configs')
local util = require('lspconfig.util')

if not configs.lucisv then
  configs.lucisv = {
    default_config = {
      cmd = { 'lucisv-server' },
      filetypes = { 'verilog', 'systemverilog' },
      root_dir = util.root_pattern('lucisv.toml', '.lucisv.toml', '.git'),
      single_file_support = true,
    },
  }
end

require('lspconfig').lucisv.setup({})

single_file_support = true matters: the server works with no workspace root at all (initialize with neither workspaceFolders nor rootUri succeeds), serving everything single-file. Only cross-file navigation needs a root.

Vim 9 (vim-lsp)

One autocmd, in ~/.vimrc:

au User lsp_setup call lsp#register_server({'name': 'lucisv', 'cmd': {server_info->['lucisv-server']}, 'allowlist': ['verilog', 'systemverilog']})

coc.nvim

coc has no vim.lsp; it takes servers from coc-settings.json (:CocConfig):

{
  "languageserver": {
    "lucisv": {
      "command": "lucisv-server",
      "filetypes": ["verilog", "systemverilog"],
      "rootPatterns": ["lucisv.toml", ".lucisv.toml", ".git"]
    }
  }
}

What you get, and what you don't

Everything in docs/features/lucisv-server/README.md's capability table: gd (definition), gr (references, in-file only for now), K (hover, including `define expansion), vim.lsp.buf.format(), document and workspace symbols, diagnostics as you type, and semantic tokens — Neovim applies those on top of its treesitter/syntax highlighting with no extra setup.

Range formatting, completion, rename and signature help are advertised too — Neovim's built-in client wires all four up with no extra config, same as everything above.

Inline completion (ghost text) needs a client that speaks it. The server advertises inlineCompletionProvider — grey ) begin … end after an if (, a matching end after a begin — but that is textDocument/inlineCompletion, still proposed in LSP 3.18, and Neovim's built-in LSP client does not implement it yet. The block skeletons and the module-instantiation ghost (typed a module's whole name plus a space → its parameters and ports in grey, since 2026-08-30) both ride that request. Without it the completion list offers module names only, though signature help still walks you through an instantiation's ports as you type them. Turn the server side off with lucisv.inlineTemplates = false and lucisv.inlineInstantiation = false in your settings table if you would rather it never answered.

lucisv.instantiate: the full skeleton without ghost text

This is the path to the whole instantiation for a client in exactly that position. It is a command, so a keybinding reaches it:

vim.keymap.set('n', '<leader>vi', function()
  local module = vim.fn.input('module: ')
  if module == '' then return end
  local position = vim.lsp.util.make_position_params(0, 'utf-16').position
  vim.lsp.buf.execute_command({
    command = 'lucisv.instantiate',
    arguments = { vim.uri_from_bufnr(0), position, module },
  })
end, { desc = 'lucisv: instantiate a module here' })

Three arguments, in this order: the buffer's URI, the position to insert at, and the module's name. The server plans the skeleton from the file that declares the module — the same plan the ghost shows, rendered as plain text with each fill-in written as its default instead of as a snippet tabstop — and pushes it back as a workspace/applyEdit, which Neovim's built-in client applies with no extra config. Ports whose names already match something in scope are connected for you, as they are in the ghost.

The position must be one where a module instantiation may actually stand: inside a module body, at the start of a line, not inside a function, an always block or a port list. Anywhere else the command answers with an error rather than writing something that will not compile. A module the workspace index does not know is refused the same way — and the index is built from the files under your root, so a module in a directory you did not open is not found.

Unlike the ghost, this path handles an escaped identifier (\my-mod) fine: there is no snippet grammar to escape it into.

Two behaviors worth knowing before you file a bug:

  • The workspace index rebuilds on save, not on keystroke. Cross-file answers about file A reflect A as of its last write. A's own buffer is always current. This is the documented staleness model, not a lag.
  • lucisv.toml is honored. The server discovers it per file exactly as the CLI does; a config setting beats your shiftwidth/tabstop (an editor default is not a deliberate override), and without a config your editor's tab size governs the indent.

Format on save, if you want it — one autocmd, and your client stays in charge of when it runs:

vim.api.nvim_create_autocmd('BufWritePre', {
  pattern = { '*.v', '*.vh', '*.sv', '*.svh' },
  callback = function() vim.lsp.buf.format() end,
})

Or let the server do it, for a client that speaks textDocument/willSaveWaitUntil — it asks before every write and applies what comes back:

vim.lsp.config('lucisv', {
  cmd = { 'lucisv-server' },
  filetypes = { 'verilog', 'systemverilog' },
  root_markers = { 'lucisv.toml', '.lucisv.toml', '.git' },
  settings = { lucisv = { formatOnSave = true } },
})

Pick one, not both. lucisv.formatOnSave is off unless you set it: the server answers the save hook with "no edits" until you ask, so an editor that already formats on save does not format twice. One difference from the autocmd above is worth knowing: willSaveWaitUntil carries no tab settings, so the indent comes from the project's lucisv.toml, then lucisv.indent, then the built-in 2 — your shiftwidth is not consulted on this path even though vim.lsp.buf.format() sends it. Set lucisv.indent if the two need to agree.

When it feels slow: --verbose

The server takes one argument, and it is the only one it takes. Start it with --verbose and every operation says how long it took, as ordinary window/logMessage lines in your client's LSP log:

vim.lsp.config('lucisv', {
  cmd = { 'lucisv-server', '--verbose' },   -- the one argument the server takes
  filetypes = { 'verilog', 'systemverilog' },
  root_markers = { 'lucisv.toml', '.lucisv.toml', '.git' },
})
timing: textDocument/hover answered in 0.42 ms
timing: textDocument/didChange handled in 0.03 ms
timing: flush of 1 dirty buffer took 1.87 ms
timing: scan started: 862 files, interleaved
timing: scan finished: 862 files (2 skipped, 858 from cache) in 141.20 ms
timing: workspace/symbol HELD behind a rescan (answering=true, wanted=false, already held=0)

That last line is the one worth knowing: the request was not slow, it had not started — the loop was rebuilding the index and the order contract makes a request queued behind a rebuild wait for it.

Neovim's built-in handler writes window/logMessage to the LSP log file at info level, and the default log level is WARN — so raise it once, or the lines are dropped before they are written:

vim.lsp.set_log_level('info')
-- then: :lua vim.cmd('edit ' .. vim.lsp.get_log_path())

coc.nvim puts them in its own output channel instead (:CocCommand workspace.showOutput); these are the same lines the VS Code extension shows when you turn on lucisv.verbose.

Anything other than --verbose is refused: the server prints one usage line on stderr and exits 2, so a misspelled flag shows up as a server that will not start rather than as a session that quietly logs nothing. Without the flag not one timing: line is ever sent — this is a diagnostic, not a default, and a busy session logs a line per keystroke.

Checking it works

:checkhealth vim.lsp      " Neovim 0.11+; 0.9/0.10: :checkhealth lsp
:LspInfo                  " nvim-lspconfig only
:lua =vim.lsp.get_clients({ bufnr = 0 })[1].server_capabilities

A healthy attach shows one client named lucisv with documentFormattingProvider, hoverProvider, definitionProvider, referencesProvider, documentSymbolProvider, workspaceSymbolProvider and semanticTokensProvider set, and positionEncoding utf-16.

If the client never attaches, the binary is the first thing to check, and you can check it without Neovim at all:

node ../vscode/smoke.js "$(command -v lucisv-server)"

That drives a full LSP session over stdio and exits 0 only if the handshake and the capabilities are intact — which separates "the server is broken" from "my editor config is wrong" in one command.