Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71d13b5fbe | ||
|
|
3823b85667 | ||
|
|
10cb6e020f | ||
|
|
cc1e2c8b72 | ||
|
|
c1c1407498 | ||
|
|
a8c22dcab0 | ||
|
|
934d472af2 | ||
|
|
dbb2349267 |
No files matched your search
+29
-2
@@ -1,7 +1,11 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
# CI: the three checks CLAUDE.md requires before any work is finished,
|
||||
# plus the extension's JavaScript tests and the corpus gate, enforced on
|
||||
# every push. Runs on the self-hosted mac-arm64 runner in host mode (no
|
||||
# containers), so the toolchain is the same one releases are built with.
|
||||
# every push. Runs on the self-hosted macOS runner in host mode (no
|
||||
# containers), so the toolchain is the same one releases are built with —
|
||||
# and, since 0.65.9, the same checks on Linux (the `linux` job below), where
|
||||
# the released Linux binaries had never been compiled-and-tested before.
|
||||
name: ci
|
||||
on:
|
||||
push:
|
||||
@@ -41,3 +45,26 @@ jobs:
|
||||
run: cargo build --release -p lucisv
|
||||
- name: Score and gate
|
||||
run: scripts/corpus_gate.sh "$CORPUS"
|
||||
|
||||
# The suite on Linux x86-64: the luhpe-linux-x64 runner starts each job in
|
||||
# the runner image (as root, 4 CPUs / 8 GB for the whole runner), with no
|
||||
# Rust in it, so the toolchain is installed per job and the build is cold
|
||||
# (a few minutes). Clippy is here as well as on macOS because code behind
|
||||
# cfg(unix)/cfg(target_os) is only compiled on the platform it names: the
|
||||
# first Linux trial failed clippy on imports macOS never saw. To run the
|
||||
# same thing from a working tree without a push: tools/linux_check.sh.
|
||||
linux:
|
||||
runs-on: linux-x64
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install the Rust toolchain
|
||||
run: |
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
|
||||
| sh -s -- -y --profile minimal -c clippy,rustfmt
|
||||
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||
- name: cargo clippy
|
||||
run: cargo clippy --all-targets -- -D warnings
|
||||
- name: cargo test
|
||||
run: cargo test --workspace
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
# Release: pushing a tag `vX.Y.Z` builds every distribution artifact and
|
||||
# publishes a Gitea release with the CHANGELOG section for that version as
|
||||
# its notes. What the release page carries is the seven .vsix packages —
|
||||
@@ -67,3 +69,5 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
LUCISV_API_URL: ${{ vars.LUCISV_API_URL }}
|
||||
run: tools/publish_release.sh "$GITHUB_REF_NAME" dist
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
/target
|
||||
/corpus
|
||||
/corpus-check-results.tsv
|
||||
@@ -8,3 +10,5 @@
|
||||
/.zcode
|
||||
/.claude
|
||||
__pycache__/
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
+338
@@ -1,9 +1,345 @@
|
||||
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||||
|
||||
# Changelog
|
||||
|
||||
All notable changes to lucisv are recorded here. Versions follow
|
||||
[semantic versioning](https://semver.org/); until 1.0 the CLI's exit codes
|
||||
(see `README.md`) are the only frozen contract.
|
||||
|
||||
## 0.66.2 — 2026-11-24
|
||||
|
||||
### Every source file names its author
|
||||
|
||||
- **No behaviour change.** Every tracked file that can carry a comment — 880
|
||||
of them: the Rust sources, the extension's JavaScript, the scripts, the
|
||||
manifests, the workflows and the documentation — now opens with an author
|
||||
line and closes with one. The binaries and the formatter's, linter's and
|
||||
language server's output are what 0.66.1 produced.
|
||||
- `tools/stamp_author.py` writes the lines and is idempotent; run it after
|
||||
adding files (`--check` lists what is missing). It leaves alone what a
|
||||
comment would break or what is regenerated: test fixtures, cases and
|
||||
snapshots, JSON and JSONL, logs, images, lockfiles, the built site under
|
||||
`docs/site/dist` and the `LICENSE` files.
|
||||
- `tools/linux_check.sh --help` reads its own header one line further down,
|
||||
since the author line now sits under the shebang.
|
||||
|
||||
## 0.66.1 — 2026-11-19
|
||||
|
||||
### Sticky scroll pins the module instance
|
||||
|
||||
- **A module instantiation folds, so its header lines stay pinned** (TODO
|
||||
§72, `docs/features/instance-folding`). `textDocument/foldingRange` answers
|
||||
one range per multi-line instantiation from its module-type line, and one
|
||||
more per instance from the line its name is on when that is a later line,
|
||||
so both `aes_control_fsm #(` and `) u_aes_control_fsm (` are pinned while
|
||||
the reader is in the connection list. The closing `);` line stays visible.
|
||||
What is an instantiation comes from `vlog_semantic::instantiations::sites`;
|
||||
where it closes is re-read from the tokens, and a statement whose tokens
|
||||
are not exactly that shape folds nothing.
|
||||
- Every fold answered before is unchanged and first on a shared start line
|
||||
(0.66.0 against this tree on 4 933 files: 75 256 ranges identical once the
|
||||
instance folds are removed). OpenTitan `hw`: 18 200 multi-line
|
||||
instantiations, none without its fold. Worst file about 2 ms per request
|
||||
(1.1 ms before).
|
||||
- Not folded: two-dimensional instance arrays; an instance whose head an
|
||||
`` `ifdef `` splits.
|
||||
|
||||
## 0.66.0 — 2026-11-19
|
||||
|
||||
### The overnight queue, complete
|
||||
|
||||
0.66.0 closes TODO §71: eight owner-ordered features, each shipped as its own
|
||||
0.65.x release with a dev round, a QA round and the full gates. Nothing in
|
||||
the engine changed between 0.65.11 and this release; it adds the topology
|
||||
and size re-measurement (`docs/topo.md`, `CLAUDE.md`) and is the version to
|
||||
install. Each line names the release that carries the detail below.
|
||||
|
||||
- **Editing and saving no longer re-index the workspace** (0.65.6/0.65.7).
|
||||
A saved or changed file updates its own records and the files that depend
|
||||
on it; only a change that can reach everything (a config, a filelist)
|
||||
rescans.
|
||||
- **Actions on the open file do not wait for the workspace** (0.65.11).
|
||||
Hover, go-to-definition, highlights, the outline and folding for names the
|
||||
file declares answer in milliseconds during a scan or a rescan, and
|
||||
completion lists what the file can reach first.
|
||||
- **Highlighting does not wait for the index** (0.65.10). Colours come from
|
||||
the buffer at once, as a best guess for cross-file names, and are
|
||||
corrected by one refresh when the index settles.
|
||||
- **`` `ifdef `` / `` `else `` / `` `endif `` branches fold** and take part
|
||||
in sticky scroll (0.65.4).
|
||||
- **Formatter styles** (0.65.5): `auto` follows the file's own style, or
|
||||
choose `lucisv`, `ansi`, `google`, `lowrisc`, `microsoft` or `nxp`; the presets are one readable
|
||||
table in `vlog_formatter/src/style.rs`.
|
||||
- **The module view marks where you are** (0.65.2): the current file's
|
||||
module and its parents, in shades of orange.
|
||||
- **Find References next to a name** (0.65.8): a caret just past a name's
|
||||
last letter now finds it — the cause of "no references" that worked on a
|
||||
second try — and edits arriving during a rescan are applied in order.
|
||||
- **Comments are comments** (0.65.3): no bracket or code colouring inside
|
||||
them, and `TODO`, `FIXME`, `FIX_ME`, `TBD` and your own words
|
||||
(`lucisv.commentKeywords.custom`) are highlighted.
|
||||
|
||||
Also since 0.65.0: releases are gated by `tools/gates.sh`, which
|
||||
compile-checks Windows and Linux (0.65.1, 0.65.7); CI runs the suite on
|
||||
Linux as well as macOS, and `lucisv-mcp` no longer serves stale contents
|
||||
after a same-instant rewrite (0.65.9).
|
||||
|
||||
One test change in this release: 0.65.11's Linux CI run failed on a
|
||||
wall-clock test of the large-file path (24.9x measured against a 24x limit
|
||||
on a loaded runner; nothing in that path had changed). The test now
|
||||
re-measures up to three times before failing — a real quadratic regression
|
||||
measures ~64x every time.
|
||||
|
||||
**Not yet seen in a running editor by a human** — every feature above was
|
||||
verified through the server's protocol and the extension's tests, on
|
||||
OpenTitan's `hw` tree. Open follow-ups are listed in TODO §71.
|
||||
|
||||
## 0.65.11 — 2026-11-19
|
||||
|
||||
### Actions on the open file no longer wait for the workspace
|
||||
|
||||
(`docs/features/fast-actions`; TODO §71.2. Measured on OpenTitan's `hw` tree
|
||||
and on generated 20 000- and 40 000-file trees, with the server driven the
|
||||
way VS Code drives it.)
|
||||
|
||||
- **Same-file answers come from the file.** A hover, a go-to-definition, a
|
||||
type definition, highlights, a rename's first check or a signature help on
|
||||
a name the file itself declares — and the outline, folding and selection
|
||||
ranges — are answered from the open buffer at once, even while the index
|
||||
is being built or rebuilt. Anything that might live in another file still
|
||||
waits for the index it needs.
|
||||
|
||||
| hover on a local name (4 000 / 20 000 / 40 000 files) | 0.65.10 | now |
|
||||
|---|---:|---:|
|
||||
| during the startup scan | 547 / 665 / 831 ms | 2.4 / 1.5 / 1.9 ms |
|
||||
| a new file triggers a rescan, request 5 ms later | 1.2 / 6.0 / 12.3 s | 47 / 167 / 321 ms |
|
||||
| the same, request read together with the event | 1.2 / 6.0 / 12.3 s | 0.3 / 0.1 / 0.1 ms |
|
||||
| the same, server busy with a previous delete | 1.3 / 7.0 / 14.3 s | 0.17 / 0.99 / 2.2 s |
|
||||
|
||||
- **Every early answer is the settled answer.** A request goes ahead only
|
||||
when its buffer is open, every older message that could change the buffer
|
||||
has been applied, its analysis is current, no settings are still on their
|
||||
way, and the answer is the buffer's alone. 2.9 million early answers were
|
||||
compared with the answer the finished index gives; none differed.
|
||||
- **Completion keeps what the file can reach near the top.** Right after the
|
||||
file's own names it now offers the members of the packages the file
|
||||
imports, what its class inherits and the macros of the headers it
|
||||
includes, so a huge workspace no longer pushes them out of the list; such
|
||||
a name shows the icon and detail of the declaration the file actually
|
||||
reaches. Completion answers are half the size for VS Code.
|
||||
- **A new `lucisv.largeFile.threshold` applies to files already open,** the
|
||||
editor's first settings answer included — not at each file's next edit.
|
||||
- **Fixed on the way** (present since 0.65.8 and 0.65.10): the editor's
|
||||
answer to a settings request could be applied ahead of an older settings
|
||||
change or edit; colours answered while a file-watcher event was waiting
|
||||
were not refreshed afterwards.
|
||||
- **What it costs.** Until the editor has answered the server's first
|
||||
settings request, same-file requests wait (the threshold may change how
|
||||
the file is read): with an editor that takes 0.5 s to answer, the first
|
||||
outline arrives after 515 ms — it was 1 043 ms on 0.65.10.
|
||||
- **Still to come.** Not yet seen in a running editor by a human.
|
||||
|
||||
## 0.65.10 — 2026-11-19
|
||||
|
||||
### Highlighting no longer waits for the index
|
||||
|
||||
(`docs/features/viewport-highlight`; TODO §71.3. Measured on OpenTitan's `hw`
|
||||
tree with the server driven the way VS Code drives it.)
|
||||
|
||||
- **Colours arrive at once.** Building a file's colours takes 0.3–6.5 ms;
|
||||
nearly all of the wait before first colour was the server holding every
|
||||
request until the index was ready. A colouring request for a buffer whose
|
||||
text is current is now answered from that buffer alone, even while a scan
|
||||
or a widening of the index holds everything else.
|
||||
|
||||
| first colour after opening a file | before | now |
|
||||
|---|---:|---:|
|
||||
| cold start, whole-workspace scope | 660–685 ms | 3.5–39 ms |
|
||||
| cold start, folder scope (the default) | 38–74 ms | 3–32 ms |
|
||||
| a file opened after startup settled, folder scope | 611–641 ms | 2–32 ms |
|
||||
| a file in a folder not indexed yet, mid-session | 375 ms | 6 ms |
|
||||
| while a rescan runs | 325–791 ms | 70–159 ms |
|
||||
|
||||
The larger figure in each range is a 545 KB file, whose own parse is most
|
||||
of what remains.
|
||||
- **Imperfect first, then corrected — once.** Before the index settles,
|
||||
names that resolve through it (a module or package in another file, an
|
||||
inherited method) are coloured as local guesses: 96.8 % of tokens already
|
||||
match the final answer, and nothing is ever coloured as code inside a
|
||||
comment or a string. When the index settles the server sends one
|
||||
`workspace/semanticTokens/refresh` and the editor's next answer is the
|
||||
accurate one. This also fixes colours that used to stay wrong until the
|
||||
next edit: the first answer was built from a half-finished index and never
|
||||
revisited (2 745 tokens in one OpenTitan file).
|
||||
- **The viewport request costs the viewport.** `semanticTokens/range` built
|
||||
the whole file's tokens and filtered them; it now classifies only the
|
||||
visible lines (0.3 ms for 60 lines of a 4 000-module buffer, against 98 ms).
|
||||
- **What it will not do.** A buffer with edits the server has not applied
|
||||
yet still waits — its existing colours stay on screen. An editor that
|
||||
cannot be asked to refresh gets early viewport colours only, and its
|
||||
whole-file answer waits as before. Hover, go-to-definition and every other
|
||||
request still wait for the index they need; QA compared 978 such answers
|
||||
with 0.65.8's and they are identical.
|
||||
- **Still to come.** The file-discovery walk at the start of every scan
|
||||
answers nothing while it runs, which is what is left of the wait in
|
||||
whole-workspace scope (62–86 ms for a late open) and during rescans. Not
|
||||
yet seen in a running editor by a human.
|
||||
|
||||
## 0.65.9 — 2026-11-19
|
||||
|
||||
### `lucisv-mcp` no longer serves stale contents; the suite runs on Linux
|
||||
|
||||
(`docs/features/linux-test-portability`, Round 2; TODO §70.)
|
||||
|
||||
- **`lucisv-mcp` no longer answers from a file's old contents after a
|
||||
same-size rewrite that restores its old modification time.** The server
|
||||
decides whether a file changed from its size, mtime, change time and
|
||||
inode, and re-reads a file whose mtime is too fresh to trust — but it did
|
||||
not apply that caution to the change time. On Linux, where the change time
|
||||
moves in 1 ms ticks, a file rewritten at the same size with its mtime put
|
||||
back (`cp -p`, `rsync -t`, `touch -r`, a rename-over) inside the same tick
|
||||
as the server's read matched in every field, and index-based answers
|
||||
(`find`, `hierarchy`, `check`) came from the old text until the file
|
||||
changed again. `read` and `outline` were never affected. The rule now
|
||||
covers every timestamp the stamp trusts, its window is 3 s (2 s was too
|
||||
close to FAT's 2-second timestamps), and a wall clock stepped backwards
|
||||
since a read distrusts the stamp. Reproduced on purpose on 0.65.8 (every
|
||||
run with an identical stat was stale) and gone on this build across
|
||||
overlayfs, tmpfs and APFS; ordinary reads cause no extra re-read.
|
||||
- **What it still cannot see**, now written down in
|
||||
`docs/features/mcp-transport`: on Windows there is no change time or
|
||||
inode, so a same-size rewrite that restores the old mtime more than 3 s
|
||||
after a read goes unseen; and a store through a writable memory map that
|
||||
the kernel has not yet reflected in the file's timestamps. A tree whose
|
||||
files carry modification times in the future is re-read on every call.
|
||||
- **The test suite is stable on Linux, and CI runs it there.** It was green
|
||||
on Linux most of the time and failed about one run in three: two test
|
||||
helpers insisted that writing to a child's input succeed (a usage error
|
||||
exits before reading), one latency test used a fixed 200 ms budget (it now
|
||||
measures against a parse of the same buffer in the same process), and one
|
||||
MCP test could hang on macOS under load on a pipe inherited across
|
||||
threads. Ten consecutive green runs as root and ten as an unprivileged
|
||||
user, then six and six by QA. `ci.yml` has a `linux` job (clippy and the
|
||||
whole suite on Linux x86-64) beside the macOS one.
|
||||
|
||||
## 0.65.8 — 2026-11-19
|
||||
|
||||
### Find References next to a name, edits kept in order, and a startup that could take minutes
|
||||
|
||||
(`docs/features/scan-ordering`; TODO §71.7. Three bugs, all older than this
|
||||
series of releases.)
|
||||
|
||||
- **Find All References, Go to Definition, hover, highlight and rename work
|
||||
with the cursor just after a name.** A double-click, a click on the right
|
||||
half of a name's last letter, or a click on a row of lucisv's References
|
||||
view leaves the cursor there, and the server used to look at the character
|
||||
*after* the name — so VS Code said "No references found" until you clicked
|
||||
away and back. Nine requests now resolve the name the cursor touches
|
||||
(hover, definition, type definition, references, document highlight,
|
||||
prepare-rename, rename, and the call- and type-hierarchy prepares); the
|
||||
ones with boundary rules of their own (completion, signature help, linked
|
||||
editing, selection range) are unchanged. The References view now opens a
|
||||
row with the cursor at the start of the name. Checked on every identifier
|
||||
of 350 files: the answer at the end of a name equals the answer at its
|
||||
start, and a rename there never touches the neighbouring token.
|
||||
- **Edits made while the workspace is re-indexing are applied in order.**
|
||||
The server held requests during a scan but applied notifications at once,
|
||||
so a newer edit could overtake an older one still queued — and since the
|
||||
editor sends edits as differences, the server's copy of the file then
|
||||
differed from the editor's until the file was closed and reopened: wrong
|
||||
symbols, wrong diagnostics, wrong references. Edits, opens, closes, saves
|
||||
and the other notifications the editor sends are now applied in the order
|
||||
sent. QA's independent driver: 9 118 bursts, 87 % of them sent mid-scan,
|
||||
no wrong text, no lost or duplicated answer; the same check fails on
|
||||
0.65.7 at once.
|
||||
- **Opening a file while the first index is built no longer makes that index
|
||||
take minutes.** A request followed by a file open in the same batch was
|
||||
handed back and re-held at every file of the startup scan: about 300–400 s
|
||||
on OpenTitan instead of 2 s. Now a held batch is handed back at most once
|
||||
per file actually opened; the same sequence takes 2.6–3.3 s.
|
||||
- **Known and left for later**, all present before: a request held during a
|
||||
scan is answered against the newest text, so a position-based request can
|
||||
land on a different symbol if an edit moved the text under it (and rename
|
||||
edits carry no document version for the client to reject a stale one by);
|
||||
deleting a directory is not seen by the server (VS Code reports the folder,
|
||||
which the client's source-file filter drops); an excluded file stays in the
|
||||
index after it is closed; symlinked files can be held under two spellings;
|
||||
renaming a port of a module defined twice gives an edit or a refusal at
|
||||
random.
|
||||
|
||||
## 0.65.7 — 2026-11-19
|
||||
|
||||
### 0.65.6, built for every platform
|
||||
|
||||
0.65.6 was tagged but never published: it passed every gate on the Mac and
|
||||
then failed to compile for Windows, so the release stopped before anything
|
||||
was built for distribution. This release is 0.65.6 with that fixed; its
|
||||
notes are below, unchanged.
|
||||
|
||||
- **The Windows build compiles again.** One comparison in the language
|
||||
server's new "is this file already held under another spelling" check moved
|
||||
a directory identity that is a small copyable pair on macOS and Linux but an
|
||||
owned path on Windows (`lucisv_server/src/state/incremental.rs`).
|
||||
- **The gates now compile for the other platforms.** `tools/gates.sh` has a
|
||||
new `cross` step: `cargo check` of the three shipped binaries for Windows
|
||||
and Linux, with the same toolchain the release build uses. Until now
|
||||
platform-conditional code was first compiled by the release build itself,
|
||||
after the gates.
|
||||
|
||||
### Saving a file no longer re-indexes the workspace
|
||||
|
||||
(`docs/features/localized-reindex`; TODO §71.1. Measured on OpenTitan's `hw`
|
||||
tree, 4 058 files, with the server driven the way VS Code drives it.)
|
||||
|
||||
- **What was happening.** Every save cost about 160 ms of whole-index work
|
||||
whatever was edited — 117 ms of it re-resolving all 470 000 cross-file
|
||||
references — and VS Code triggered it twice, once for the save and once for
|
||||
its own file watcher. Watcher events for files the index could not hold (a
|
||||
generated file in a gitignored directory, a file outside the filelist or
|
||||
folder scope, a held file reported through a symlinked root or in another
|
||||
letter case) started a whole rescan with the progress bar, 270–750 ms.
|
||||
- **Now the index does only what the edit can reach.**
|
||||
|
||||
| edit, then save | before | now |
|
||||
|---|---:|---:|
|
||||
| a comment, or the watcher's echo of any save | ~160 ms | under 0.3 ms |
|
||||
| a local signal in `uart_tx` or `prim_flop` | ~170 ms | 4 ms |
|
||||
| a member added to `uart_reg_pkg` | ~167 ms | 12 ms |
|
||||
| a line above a module 125 files instantiate | ~163 ms | 47 ms |
|
||||
| a member added to a package 677 files import | ~162 ms | 92 ms |
|
||||
| a watcher event for a file outside the scope | up to 746 ms, with the bar | 3.5 ms |
|
||||
|
||||
The index records which names each file looked up — including the ones it
|
||||
did not find — and re-resolves only the readers of names whose meaning
|
||||
changed. A save whose index record is unchanged merges nothing.
|
||||
- **Still wide, on purpose.** Adding or deleting a file; a burst of more
|
||||
files in one watcher event than half the index holds (a branch switch),
|
||||
which takes the one rescan it always did; an edit above a declaration many
|
||||
files use. Every save still re-checks every open file's diagnostics, so a
|
||||
`lucisv.toml` or waiver edit takes effect at the next save as before — with
|
||||
200 files open that is most of a save (53 ms, against ~205 ms before).
|
||||
- **The price.** Every whole rescan costs a few per cent more for the table
|
||||
that makes the rest cheap: warm OpenTitan startup is 40–120 ms slower,
|
||||
depending on machine load.
|
||||
- **How it is known to be right.** After any sequence of edits, everything
|
||||
the server answers must equal what a freshly started server answers for the
|
||||
same files. QA built that oracle independently and it failed the first cut
|
||||
on four stale answers (include links to headers outside the scope, lint
|
||||
configuration, a file-age check macOS defeats, excluded open buffers); all
|
||||
four are fixed and are now tests. The final build: 312 hand-written
|
||||
comparisons and twelve random 300–500-step runs over the corpus and
|
||||
OpenTitan with no divergence it caused.
|
||||
- **Also.** The language server's `line-length` lint now follows the chosen
|
||||
formatting style's width (80 under `ansi` and `nxp`, 120 under
|
||||
`microsoft`), closing the limit noted in 0.65.5. Removing an included
|
||||
header no longer leaves other files' include links pointing at it.
|
||||
- **Known, and next.** Found by this round's QA and present in earlier
|
||||
releases too: an edit made while a whole rescan is running can be applied
|
||||
out of order, leaving the server's copy of the buffer wrong until the file
|
||||
is reopened; a watcher event that names only a directory leaves stale
|
||||
state; an excluded file stays indexed after it is closed. These are the
|
||||
next round's work.
|
||||
|
||||
## 0.65.6 — 2026-11-19
|
||||
|
||||
### Saving a file no longer re-indexes the workspace
|
||||
@@ -3125,3 +3461,5 @@ compiler directive any more. Details:
|
||||
[macro items](docs/features/macro-items/README.md),
|
||||
[directives in lists](docs/features/directives-in-lists/README.md) and
|
||||
[in instances](docs/features/directives-in-instances/README.md).
|
||||
|
||||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|
||||
@@ -1,3 +1,5 @@
|
||||
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||||
|
||||
# CLAUDE.md — rules for all agents working on lucisv
|
||||
|
||||
lucisv is a ruff-style Verilog/SystemVerilog formatter/linter in Rust.
|
||||
@@ -89,6 +91,16 @@ Re-measured 2026-10-14 after TODO §55 (pure move, `docs/features/decomposition-
|
||||
files over 600 workspace-wide: `lucisv_server/src/perf.rs` 907 (reasoned),
|
||||
`vlog_parser/src/lexer.rs` 771, `vlog_formatter/src/format/stmt.rs` 604.
|
||||
|
||||
Re-measured 2026-11-19 at 0.66.0, after the overnight queue (TODO §71; non-blank,
|
||||
non-comment lines before `mod tests`): two files over 600 — `perf.rs` 907
|
||||
(reasoned) and `lexer.rs` 771 — then `vlog_semantic/src/resolve.rs` 587 and
|
||||
`vlog_parser/src/parser/item.rs` 582, both at the mark: the next addition to
|
||||
either goes in a new module. The queue's new modules are all small
|
||||
(`server/ahead.rs`, `same_file.rs`, `completion/related.rs`, `server/viewport.rs`,
|
||||
`server/caret.rs`, `state/watched.rs`, `folding/directives.rs`, formatter
|
||||
`style.rs` / `auto.rs`); `server/dispatch.rs` is 503 and `server/index.rs`
|
||||
is where four of the eight features met.
|
||||
|
||||
## Rust standards
|
||||
|
||||
- `cargo fmt` clean, `cargo clippy --all-targets` clean (no `#[allow]`
|
||||
@@ -215,3 +227,5 @@ proven independent and run serially. Rules for a parallel wave:
|
||||
not actually independent, which is a planning failure to record.
|
||||
- After merging, the lead updates `docs/topo.md` for any edge a lane added
|
||||
or amended, so the next wave plans against reality.
|
||||
|
||||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|
||||
Generated
+9
-9
@@ -97,7 +97,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lucisv"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
dependencies = [
|
||||
"lucisv_core",
|
||||
"rayon",
|
||||
@@ -108,11 +108,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lucisv_core"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
|
||||
[[package]]
|
||||
name = "lucisv_mcp"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
dependencies = [
|
||||
"lucisv_core",
|
||||
"serde",
|
||||
@@ -126,7 +126,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lucisv_server"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
dependencies = [
|
||||
"lsp-server",
|
||||
"lsp-types",
|
||||
@@ -262,14 +262,14 @@ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "vlog_formatter"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
dependencies = [
|
||||
"vlog_parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vlog_linter"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
dependencies = [
|
||||
"lucisv_core",
|
||||
"vlog_formatter",
|
||||
@@ -279,11 +279,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "vlog_parser"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
|
||||
[[package]]
|
||||
name = "vlog_refactor"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
dependencies = [
|
||||
"vlog_formatter",
|
||||
"vlog_parser",
|
||||
@@ -292,7 +292,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "vlog_semantic"
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
dependencies = [
|
||||
"vlog_parser",
|
||||
]
|
||||
+5
-1
@@ -1,3 +1,5 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
@@ -13,7 +15,7 @@ members = [
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.65.6"
|
||||
version = "0.66.2"
|
||||
authors = ["Guoliang Chen"]
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
@@ -44,3 +46,5 @@ serde_json = "=1.0.140"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||||
|
||||
# lucisv — Language Utility for Coding In SystemVerilog
|
||||
|
||||
A Verilog and SystemVerilog formatter, linter, and language server written in Rust.
|
||||
@@ -1145,3 +1147,5 @@ where the version number lives, how the `.vsix` is packaged, and what
|
||||
marketplace publishing would take if it ever happens — is in
|
||||
[`tools/RELEASING.md`](tools/RELEASING.md). lucisv is MIT licensed
|
||||
([`LICENSE`](LICENSE)).
|
||||
|
||||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|
||||
@@ -1,3 +1,5 @@
|
||||
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||||
|
||||
# ROADMAP — autonomous coverage loop
|
||||
|
||||
Running log of the coverage-improvement loop (started 2026-08-20). The metric
|
||||
@@ -175,3 +177,5 @@ needs macro expansion, a deliberate non-goal) or not valid standalone
|
||||
Verilog. The stop condition holds before round 1 of a restart, so **no dev
|
||||
round was dispatched**. The loop resumes only if open question 2 is decided
|
||||
(a preprocessing model would put ~1.7% back in reach) or the corpus grows.
|
||||
|
||||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|
||||
@@ -1,3 +1,5 @@
|
||||
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||||
|
||||
# TODO-MCP — the Model Context Protocol block
|
||||
|
||||
Planned 2026-09-23 by the lead at 0.55.0. The analysis and design are in
|
||||
@@ -498,3 +500,5 @@ Feature README `docs/features/mcp-read-only`. One dev (Opus), one QA
|
||||
item's lines through `format_range` automatically — costs a refusal
|
||||
path when the safety net objects. Default in this plan: not automatic;
|
||||
the agent calls `format` with `lines`.
|
||||
|
||||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|
||||
@@ -1,3 +1,5 @@
|
||||
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||||
|
||||
# TODO — best practices adopted from ruff and Verible
|
||||
|
||||
Curated backlog for lucisv, drawn from `astral-sh/ruff` (architecture, CLI/UX,
|
||||
@@ -7299,9 +7301,9 @@ as the trial shows. One lane, `docs/features/linux-test-portability`;
|
||||
left implicit, assertions on wall-clock or environment that the runner
|
||||
shows to be fragile. No test is deleted and the test count does not
|
||||
drop; no production code and nothing in `verify.rs` changes.
|
||||
- [ ] `cargo test --workspace` green on Linux as root and with `--user`,
|
||||
- [x] `cargo test --workspace` green on Linux as root and with `--user`,
|
||||
and `tools/gates.sh` green on macOS.
|
||||
- [ ] (lead) `.gitea/workflows/ci.yml` gains a `linux` job on `linux-x64`;
|
||||
- [x] (lead) `.gitea/workflows/ci.yml` gains a `linux` job on `linux-x64`;
|
||||
`docs/topo.md` and `tools/RELEASING.md` updated.
|
||||
|
||||
## 71. The overnight queue (2026-11-19, owner's order) — eight features, one release each
|
||||
@@ -7319,11 +7321,12 @@ subsection, plan and `docs/features/<name>/README.md` when its turn comes.
|
||||
Today every
|
||||
file edit re-indexes everything. A change to a `define` may have to;
|
||||
a typical, localized edit must not.
|
||||
- [ ] **71.2 Actions stay fast on a huge, heavily-dependent tree.** Do the
|
||||
- [x] **71.2 Actions stay fast on a huge, heavily-dependent tree.** (0.65.11, `docs/features/fast-actions`) Do the
|
||||
work dynamically: answer first from what is already in the same file
|
||||
(hover to a definition in this file), and use the relationship map to
|
||||
load completion candidates on demand.
|
||||
- [ ] **71.3 Highlighting does not wait for the index.** Always run a
|
||||
- [x] **71.3 Highlighting does not wait for the index.** (0.65.10, `docs/features/viewport-highlight`)
|
||||
Always run a
|
||||
localized, viewport-only highlight; it may be imperfect and be
|
||||
corrected later, but basic colours must not wait for the whole
|
||||
database.
|
||||
@@ -7340,7 +7343,8 @@ subsection, plan and `docs/features/<name>/README.md` when its turn comes.
|
||||
file's instance and its parents in different shades — bright light
|
||||
orange for the instance, dimmer the further up — or anything in that
|
||||
spirit that makes the hierarchy easy to read.
|
||||
- [ ] **71.7 Find References sometimes answers "not found"** on a
|
||||
- [x] **71.7 Find References sometimes answers "not found"** (0.65.8, `docs/features/scan-ordering`: a server bug — the caret just past a name)
|
||||
on a
|
||||
port/signal, then works after clicking elsewhere and back. VS Code or
|
||||
the server? Investigate, then fix what is ours.
|
||||
- [x] **71.8 Comments: no code colours inside them** (0.65.3, `docs/features/comment-highlighting`; the bracket colour is VS Code's, explained not changed)
|
||||
@@ -7348,7 +7352,7 @@ subsection, plan and `docs/features/<name>/README.md` when its turn comes.
|
||||
`signal[]` gets highlighted today), **but do highlight `TODO`,
|
||||
`FIXME`, `FIX_ME`, `TBD`**, plus a user setting for custom words that
|
||||
are highlighted only in comments.
|
||||
- [ ] **71.9 Release `0.66.0`** once 71.1–71.8 have each shipped.
|
||||
- [x] **71.9 Release `0.66.0`** once 71.1–71.8 have each shipped.
|
||||
|
||||
### 71 — wave 1 (lead, 2026-11-19): 71.6 runs beside §70
|
||||
|
||||
@@ -7410,14 +7414,14 @@ indexing, collide with each other and with §70's test files, and wait for
|
||||
stale answers), a fix round, a QA pass and a last small round. What the
|
||||
QA rounds and a read-only investigation turned up, all present before this
|
||||
wave, becomes lane **71.7** (the owner's Find References item, widened):
|
||||
- [ ] A caret just past an identifier's last letter asks about the next
|
||||
- [x] A caret just past an identifier's last letter asks about the next
|
||||
character: references, definition, hover and highlight come back
|
||||
empty (`server/dispatch.rs` `Server::offset`). This is the owner's
|
||||
"not found, then works after clicking back".
|
||||
- [ ] A `didChange` arriving during a whole rescan can overtake an older
|
||||
- [x] A `didChange` arriving during a whole rescan can overtake an older
|
||||
one still queued (`server/mod.rs` `process_batch`): with incremental
|
||||
sync the server's buffer is corrupted until the file is reopened.
|
||||
- [ ] A burst `[request, didOpen]` during the startup scan is re-held at
|
||||
- [x] A burst `[request, didOpen]` during the startup scan is re-held at
|
||||
every file (`server/index.rs` `answer_what_is_waiting`): the scan
|
||||
takes ~300 s on OpenTitan instead of ~1.7 s.
|
||||
- [ ] A watcher event naming only a directory leaves stale state; an
|
||||
@@ -7426,3 +7430,101 @@ indexing, collide with each other and with §70's test files, and wait for
|
||||
71.3 (viewport highlighting) passed QA with a gap in the default folder
|
||||
scope (colours wait out a widen, ~630 ms); it is rebased after 71.7 and
|
||||
closes that in its fix round. Then 71.2.
|
||||
|
||||
- 0.65.6 never published (lead, 2026-11-19): the release build failed to
|
||||
compile `lucisv-server` for Windows — `dir_id` is a `Copy` pair on unix and
|
||||
a `PathBuf` elsewhere, and 71.1's new code moved it in a closure
|
||||
(`state/incremental.rs`). The gate caught nothing because nothing before
|
||||
the release build compiles for another platform. Fixed by the lead (one
|
||||
line) and shipped as 0.65.7 with 0.65.6's notes; `tools/gates.sh` gains a
|
||||
`cross` step so the next one is caught before the tag. Seven of the eight
|
||||
§71 items therefore have releases 0.65.2–0.65.5 and 0.65.7.
|
||||
|
||||
- Wave 6 (lead, 2026-11-19): 71.7 shipped as 0.65.8. Left open from it and
|
||||
from its QA, all older than this series:
|
||||
- [ ] A request held during a scan is answered against the newest text; a
|
||||
position-based one can resolve a different symbol when an edit moved
|
||||
the text under it, and rename edits carry no document version.
|
||||
- [ ] An unheld buffer opened while a scan runs is never taken in
|
||||
afterwards; closing an unsaved in-scope buffer a rescan had indexed
|
||||
leaves its text in the index.
|
||||
- [ ] Renaming a port of a module defined twice gives an edit or a refusal
|
||||
at random (`qa717/drv/dup.py`).
|
||||
- [ ] Directory-only watcher events (needs a broader watcher
|
||||
registration — the owner's call), excluded buffers after close (a
|
||||
cheap fix belongs in the index layer: adding a file is a wide
|
||||
change), symlink spellings.
|
||||
|
||||
- §70 closed (lead, 2026-11-19), shipped with 0.65.9. Once ssh was back the
|
||||
suite proved flaky on Linux (3 of 9 runs): two test helpers that insisted
|
||||
a write to a child's stdin succeed, a 200 ms wall-clock bound, an MCP test
|
||||
that could hang on an inherited pipe — and one real bug, `lucisv-mcp`
|
||||
serving stale contents after a same-tick, same-size rewrite on Linux
|
||||
(`project/files.rs`, the racy rule covered the mtime alone). All fixed in
|
||||
lane 70b (`docs/features/linux-test-portability`, Round 2); Linux is green
|
||||
10/10 as root and as a user (dev) and 6/6 each (QA); `ci.yml` has its
|
||||
`linux` job. Left open:
|
||||
- [ ] A file with an mtime in the future is re-read by `lucisv-mcp` on
|
||||
every call, forever (67 ms against 7 ms per `find` on 4 000 files).
|
||||
- [ ] `crates/lucisv/tests/cli.rs:2149` asserts only an empty stdout, no
|
||||
exit code.
|
||||
- [ ] `crates/lucisv_mcp/tests/qa_m3.rs` uses unix-only APIs with no cfg:
|
||||
`cargo check --all-targets` for Windows fails there (tests only).
|
||||
- [ ] The release is still gated on macOS alone; Windows is compile-checked
|
||||
(`cross`), never executed.
|
||||
|
||||
- Wave 7 (lead, 2026-11-19): 71.3 shipped as 0.65.10, re-applied onto
|
||||
0.65.8's message loop by hand and re-validated by a second QA round. Left
|
||||
open from it:
|
||||
- [ ] The discovery walk at the start of every scan answers nothing while
|
||||
it runs: a late open in workspace scope still waits 62–86 ms for
|
||||
colour and a rescan holds colours 70–159 ms. Making the walk
|
||||
resumable needs its own identical-result proof (`state/discover.rs`).
|
||||
- [ ] A `range` answered during a rescan always counts as a guess and
|
||||
costs one refresh at settle even when nothing changed.
|
||||
- [ ] An edit in one file that changes how another OPEN file colours sends
|
||||
no refresh (as before this lane).
|
||||
|
||||
- Wave 8 (lead, 2026-11-19): 71.2 shipped as 0.65.11 after four dev rounds
|
||||
and four QA rounds — two QA failures, so the last round ran with Fable 5.2
|
||||
as dev and QA (`docs/features/fast-actions`, Review). Left open from it:
|
||||
- [ ] Inside the startup settings wait, the client's answer to the pull is
|
||||
applied ahead of an older settings push held with it
|
||||
(`server/startup.rs`, `take_the_answer_out_of_held`; predates the
|
||||
lane; needs a client whose push and answer disagree in one burst).
|
||||
- [ ] `tests/fast_actions_bursts.rs`'s oracle accepts an answer the
|
||||
reference gives after any later message of the round: 2–9 % of
|
||||
injected stale answers pass when a later message restores the state.
|
||||
- [ ] Whether a large open buffer is in the index depends on when it was
|
||||
opened, saved or scanned (predates the lane; 77–98 answers differ
|
||||
between a settled session and a fresh server on OpenTitan).
|
||||
- [ ] The 40 000-file rescan after a delete takes either 12.3 s or
|
||||
14.5–15.5 s, on 0.65.10 and on this tree alike; cause not found.
|
||||
|
||||
## 72. Sticky scroll pins the module instance (planned 2026-11-19, owner's order)
|
||||
|
||||
Owner: "only the module definition is floating. I want to extend this a
|
||||
little so that the module instance would be floating as well." Folds come
|
||||
only from keyword pairs and `` `ifdef `` branches, so nothing delimited by
|
||||
`( )` pins. Surveyed on OpenTitan `hw` (4 047 files): 162 instances of 50+
|
||||
lines, none pinned; 132 of them write `#(` on the type line, so the instance
|
||||
name sits on a later `) u_name (` line. Example:
|
||||
`hw/ip/aes/rtl/aes_control_fsm_n.sv:382-594`. One lane (dev, then QA),
|
||||
feature README `docs/features/instance-folding/README.md`.
|
||||
|
||||
- [x] `crates/lucisv_server/src/folding/instances.rs` (new): one fold per
|
||||
multi-line module instantiation from its module-type line, and one more
|
||||
per instance from the line its name is on when that is a different
|
||||
line, so both `aes_control_fsm #(` and `) u_aes_control_fsm (` pin
|
||||
while the reader is in the connection list. The closing line stays
|
||||
visible, as for every scope fold.
|
||||
- [x] `crates/lucisv_server/src/folding.rs`: the third source merged through
|
||||
`in_answer_order`; every fold the server answered before is still
|
||||
there, unchanged and first on a shared start line.
|
||||
- [x] Tests in the same change, and `folding/opentitan_sweep.rs` extended:
|
||||
instances counted independently, existing folds proven unchanged.
|
||||
- [x] `editors/vscode/README.md`: the sticky-scroll row names the instance.
|
||||
- [x] Seen in a running VS Code (owner, 2026-11-19, on the local 0.66.1
|
||||
build). Shipped as 0.66.1.
|
||||
|
||||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|
||||
@@ -1,3 +1,5 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
[package]
|
||||
name = "lucisv"
|
||||
version.workspace = true
|
||||
@@ -15,3 +17,5 @@ vlog_parser = { path = "../vlog_parser" }
|
||||
vlog_formatter = { path = "../vlog_formatter" }
|
||||
vlog_linter = { path = "../vlog_linter" }
|
||||
rayon = { workspace = true }
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Hand-rolled command line parsing for the `lucisv` binary.
|
||||
|
||||
use lucisv_core::cache;
|
||||
@@ -751,3 +753,5 @@ mod tests {
|
||||
assert!(!parse(&["check", "rtl"]).unwrap().rules_doc);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,5 +1,9 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `--diff`'s unified diff. The printer lives in `lucisv_core::diff`, shared
|
||||
//! with the MCP server's `dry_run` (Handshake MCP-1, a pure move); this module
|
||||
//! keeps the CLI's `diff::unified` path.
|
||||
|
||||
pub use lucisv_core::diff::unified;
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The `lucisv check` driver: lint files, print diagnostics, apply fixes.
|
||||
//!
|
||||
//! Everything about *which* files are linted — the walk, `--exclude`,
|
||||
@@ -880,3 +882,5 @@ mod tests {
|
||||
assert_eq!(quote("bell\u{7}"), "\"bell\\u0007\"");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! lucisv — a Verilog/SystemVerilog formatter and linter in the spirit of
|
||||
//! `ruff format` and `ruff check`.
|
||||
//!
|
||||
@@ -666,3 +668,5 @@ mod tests {
|
||||
assert!(err.contains("parse error"), "{err}");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
+28
-10
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! End-to-end tests that drive the real `lucisv` binary.
|
||||
//!
|
||||
//! Fixtures use the most trivial Verilog possible so these tests stay
|
||||
@@ -92,16 +94,29 @@ fn run_in(dir: &TempDir, args: &[&str]) -> Output {
|
||||
Command::new(LUCISV).args(args).current_dir(&dir.path).output().expect("run lucisv")
|
||||
}
|
||||
|
||||
/// Runs lucisv with the cache switched off, `input` on its stdin.
|
||||
fn run_with_stdin(args: &[&str], input: &str) -> Output {
|
||||
let mut child = Command::new(LUCISV)
|
||||
.args(with_no_cache(args))
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("spawn lucisv");
|
||||
child.stdin.as_mut().expect("stdin").write_all(input.as_bytes()).expect("write stdin");
|
||||
child.wait_with_output().expect("run lucisv")
|
||||
run_with_stdin_raw(&with_no_cache(args), input)
|
||||
}
|
||||
|
||||
/// Writes `input` to the child's stdin and closes it.
|
||||
///
|
||||
/// A child that exits without reading — a usage error refuses before it
|
||||
/// looks at stdin — is legitimate, and the write then races its exit: it
|
||||
/// fails with `BrokenPipe` when the child is already gone. That one error is
|
||||
/// not the test's business; the exit code and output the caller asserts on
|
||||
/// are. (A successful write never meant the child read anything either:
|
||||
/// every input here is far smaller than a pipe's buffer, so the write lands
|
||||
/// in the buffer whether or not the child ever reads it.) Any other error is
|
||||
/// a failure.
|
||||
fn feed(child: &mut std::process::Child, input: &str) {
|
||||
let mut stdin = child.stdin.take().expect("stdin");
|
||||
match stdin.write_all(input.as_bytes()) {
|
||||
Err(error) if error.kind() != std::io::ErrorKind::BrokenPipe => {
|
||||
panic!("write stdin: {error:?}")
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn code(out: &Output) -> i32 {
|
||||
@@ -1755,6 +1770,7 @@ fn lines_neither_reads_nor_writes_the_cache() {
|
||||
assert!(!fresh.cache_file().exists(), "a range run must not seed the cache");
|
||||
}
|
||||
|
||||
/// Runs lucisv exactly as given, cache and all, `input` on its stdin.
|
||||
fn run_with_stdin_raw(args: &[&str], input: &str) -> Output {
|
||||
let mut child = Command::new(LUCISV)
|
||||
.args(args)
|
||||
@@ -1763,7 +1779,7 @@ fn run_with_stdin_raw(args: &[&str], input: &str) -> Output {
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("spawn lucisv");
|
||||
child.stdin.as_mut().expect("stdin").write_all(input.as_bytes()).expect("write stdin");
|
||||
feed(&mut child, input);
|
||||
child.wait_with_output().expect("run lucisv")
|
||||
}
|
||||
|
||||
@@ -2449,3 +2465,5 @@ fn text_that_merely_says_package_changes_no_finding() {
|
||||
"{plain}\n---\n{with_noise}"
|
||||
);
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `--style` and `[format] style` through the real `lucisv` binary: the
|
||||
//! flag, the config key, their precedence over each other and under the
|
||||
//! explicit `indent`/`line-length`, the error for a name that is not a
|
||||
@@ -169,3 +171,5 @@ fn changing_the_style_invalidates_the_cache_entry() {
|
||||
let out = run(&["--check", &path, "--cache-dir", &cache]);
|
||||
assert_eq!(code(&out), 1, "{}", stderr(&out));
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
[package]
|
||||
name = "lucisv_core"
|
||||
version.workspace = true
|
||||
@@ -10,3 +12,5 @@ name = "lucisv_core"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Replacing a file's contents without ever leaving it half written.
|
||||
//!
|
||||
//! `fs::write` truncates the target and then writes into it, so a crash, a
|
||||
@@ -449,3 +451,5 @@ mod tests {
|
||||
assert_eq!(fs::metadata(&target).expect("stat").permissions().mode() & 0o777, 0o600);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The "already formatted" cache: a per-path record of content that a
|
||||
//! previous run verified is a fixed point, so a repeat run can skip the
|
||||
//! file entirely.
|
||||
@@ -539,3 +541,5 @@ mod tests {
|
||||
assert!(!Cache::load(&dir.path).is_clean(&weird, entry(1)));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `lucisv.toml` / `.lucisv.toml` discovery and its TOML-subset parser.
|
||||
//!
|
||||
//! Only what a small config file needs is supported (comments, `key = int`,
|
||||
@@ -987,3 +989,5 @@ exclude = [ \"build\", \"*_gen.sv\", ]
|
||||
assert_eq!(discovery.for_file(Path::new("y.sv")).unwrap().indent, Some(4));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! A small line-oriented unified diff: the CLI's `--diff` and the MCP
|
||||
//! server's `dry_run` print the same hunks through this one function.
|
||||
//! Moved here from `crates/lucisv/src/diff.rs` unchanged (Handshake MCP-1,
|
||||
@@ -219,3 +221,5 @@ mod tests {
|
||||
assert!(d.contains("-a\n-b\n+x\n+y\n"), "{d}");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! EDA filelist (`-f`) parsing: the project file every Verilog build
|
||||
//! already has.
|
||||
//!
|
||||
@@ -591,3 +593,5 @@ missing.sv
|
||||
assert_eq!(list.warnings.len(), 2, "{:?}", list.warnings);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The parts of lucisv that decide *which* files are processed and *with what
|
||||
//! settings*, shared by the `lucisv` CLI and the `lucisv-server` language server.
|
||||
//!
|
||||
@@ -20,3 +22,5 @@ pub mod config;
|
||||
pub mod diff;
|
||||
pub mod filelist;
|
||||
pub mod walk;
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! File discovery: directory walking, `--exclude` matching and the
|
||||
//! `.gitignore` subset documented in
|
||||
//! `docs/features/parallel-files/README.md`.
|
||||
@@ -1103,3 +1105,5 @@ mod tests {
|
||||
assert!(!tracker.has_conflict());
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
[package]
|
||||
name = "lucisv_mcp"
|
||||
version.workspace = true
|
||||
@@ -21,3 +23,5 @@ vlog_formatter = { path = "../vlog_formatter" }
|
||||
vlog_linter = { path = "../vlog_linter" }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The one write path every edit tool goes through.
|
||||
//!
|
||||
//! A tool hands over a [`Plan`] — per file, the text it computed against and
|
||||
@@ -361,3 +363,5 @@ mod tests {
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The index caches a startup reads instead of parsing (PLAN §6): the
|
||||
//! language server's `index-cache`, **read only, never written**, and this
|
||||
//! server's own `index-cache-mcp` beside it, in the same codec, written once
|
||||
@@ -221,3 +223,5 @@ fn store_lines(bytes: &[u8]) -> Vec<&[u8]> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
Vendored
+4
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The caches against the rebuild oracle: an index started from records is
|
||||
//! the index a cold build over the same files makes
|
||||
//! (`WorkspaceIndex::fingerprint`), and every record that is not exactly
|
||||
@@ -141,3 +143,5 @@ fn a_record_filed_under_another_path_or_hash_is_not_taken() {
|
||||
assert!(parse("0000000000000007\tx").is_none(), "no checksum");
|
||||
assert!(parse("7\tx\t0000000000000000").is_none(), "a hash of the wrong width");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `lucisv-mcp` — lucisv as a Model Context Protocol server, over stdio.
|
||||
//!
|
||||
//! A coding agent (Claude Code, Cursor, VS Code's agent mode) spawns this
|
||||
@@ -142,3 +144,5 @@ mod tests {
|
||||
assert_eq!(parse(&[]).unwrap(), Options::default());
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! One file, fully analyzed, and a small cache of them keyed by content.
|
||||
//!
|
||||
//! The index answers workspace questions without keeping any file's text;
|
||||
@@ -140,3 +142,5 @@ mod tests {
|
||||
assert!(cache.get(Path::new("a"), 1).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Which files the project is made of, and what each one looked like when it
|
||||
//! was last read: the filelist-or-walk ladder of PLAN §4.4 over
|
||||
//! `lucisv_core`, and the per-file stamp the freshness sweep compares against.
|
||||
@@ -5,7 +7,7 @@
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime};
|
||||
use std::time::{Duration, Instant, SystemTime};
|
||||
|
||||
use lucisv_core::cache::content_hash;
|
||||
use lucisv_core::config::Discovery;
|
||||
@@ -16,11 +18,25 @@ use lucisv_core::walk::collect_files_with;
|
||||
/// something an agent wants summarised.
|
||||
pub const MAX_FILE_BYTES: u64 = 1024 * 1024;
|
||||
|
||||
/// A file whose mtime is this close to the moment it was read may have been
|
||||
/// written again within the filesystem's timestamp resolution, so its stamp
|
||||
/// proves nothing: it is re-read (and re-hashed) until it is older than
|
||||
/// this. Git's "racy clean" rule, for the same reason.
|
||||
const RACY: Duration = Duration::from_secs(2);
|
||||
/// A file whose mtime or ctime is this close to the moment it was read may
|
||||
/// have been written again within the filesystem's timestamp resolution, so
|
||||
/// its stamp proves nothing: it is re-read (and re-hashed) until it is older
|
||||
/// than this. Git's "racy clean" rule, for the same reason.
|
||||
///
|
||||
/// The window must outlast the coarsest timestamp a filesystem keeps plus
|
||||
/// how far its clock can lag the one `read_at` comes from. Linux stamps
|
||||
/// files from a clock that moves in 1–4 ms ticks; ext3 and many network
|
||||
/// mounts keep whole seconds, FAT two. Three seconds covers FAT's two with
|
||||
/// a second to spare. A just-changed file costs a few more re-reads; a
|
||||
/// window too short costs stale contents.
|
||||
const RACY: Duration = Duration::from_secs(3);
|
||||
|
||||
/// How far the wall clock may fall behind the monotonic one since a read
|
||||
/// before the stamp stops being trusted: a clock stepped back can give a
|
||||
/// later write the very timestamp the stamp holds. Large next to the
|
||||
/// microseconds between the paired clock reads, small next to the margin
|
||||
/// [`RACY`] keeps over the coarsest timestamps.
|
||||
const STEP_BACK: Duration = Duration::from_millis(100);
|
||||
|
||||
/// The files one discovery found, and what it had to say about the rest.
|
||||
#[derive(Debug, Default)]
|
||||
@@ -137,13 +153,16 @@ pub struct Stamp {
|
||||
pub mtime: Option<SystemTime>,
|
||||
/// `content_hash` of its bytes.
|
||||
pub hash: u64,
|
||||
/// When it was read.
|
||||
/// When it was read, by the wall clock file timestamps are compared with.
|
||||
pub read_at: SystemTime,
|
||||
/// The same moment by the monotonic clock: what tells a wall clock that
|
||||
/// was stepped back since the read.
|
||||
pub read_mono: Instant,
|
||||
/// Its ctime and inode — what still moves when a same-size rewrite puts
|
||||
/// the old mtime back (`cp -p`, `rsync -t`, `touch -r`), git's answer to
|
||||
/// the same problem. Zero off Unix, where size, mtime and the racy rule
|
||||
/// the same problem. `None` off Unix, where size, mtime and the racy rule
|
||||
/// are all there is.
|
||||
pub identity: (i64, i64, u64),
|
||||
pub identity: Option<Identity>,
|
||||
/// Whether its text spells `endprogram` — the cheap test that says a
|
||||
/// `Module`-kind unit in it might be a `program` (the semantic layer
|
||||
/// models both as a module).
|
||||
@@ -161,6 +180,42 @@ pub enum Change {
|
||||
Gone,
|
||||
}
|
||||
|
||||
/// A file's inode change time and inode number (Unix only).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Identity {
|
||||
/// The ctime, `None` when it does not fit a `SystemTime`.
|
||||
pub ctime: Option<SystemTime>,
|
||||
/// The inode number.
|
||||
pub ino: u64,
|
||||
}
|
||||
|
||||
/// What one `stat` says about a file, as far as a stamp is concerned.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
struct Seen {
|
||||
size: u64,
|
||||
mtime: Option<SystemTime>,
|
||||
identity: Option<Identity>,
|
||||
}
|
||||
|
||||
impl Seen {
|
||||
fn of(meta: &fs::Metadata) -> Seen {
|
||||
Seen { size: meta.len(), mtime: meta.modified().ok(), identity: identity(meta) }
|
||||
}
|
||||
}
|
||||
|
||||
/// The two clocks, read back to back.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
struct Clocks {
|
||||
wall: SystemTime,
|
||||
mono: Instant,
|
||||
}
|
||||
|
||||
impl Clocks {
|
||||
fn now() -> Clocks {
|
||||
Clocks { wall: SystemTime::now(), mono: Instant::now() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Stamp {
|
||||
/// Compare the file on disk with this stamp, by one `stat`.
|
||||
pub fn check(&self, path: &Path) -> Change {
|
||||
@@ -170,18 +225,56 @@ impl Stamp {
|
||||
if !meta.is_file() || meta.len() > MAX_FILE_BYTES {
|
||||
return Change::Gone;
|
||||
}
|
||||
let mtime = meta.modified().ok();
|
||||
let racy = match mtime {
|
||||
Some(mtime) => mtime + RACY > self.read_at,
|
||||
None => true,
|
||||
};
|
||||
let moved = meta.len() != self.size || mtime != self.mtime;
|
||||
if moved || identity(&meta) != self.identity || racy {
|
||||
self.compare(Seen::of(&meta), Clocks::now())
|
||||
}
|
||||
|
||||
/// The decision [`Stamp::check`] makes, from what the `stat` saw and
|
||||
/// what the clocks say now.
|
||||
fn compare(&self, seen: Seen, now: Clocks) -> Change {
|
||||
let moved =
|
||||
seen.size != self.size || seen.mtime != self.mtime || seen.identity != self.identity;
|
||||
if moved || self.racy() || self.clock_stepped_back(now) {
|
||||
Change::Suspect
|
||||
} else {
|
||||
Change::Same
|
||||
}
|
||||
}
|
||||
|
||||
/// **Invariant: a stamp is trusted on a later match only if every
|
||||
/// timestamp it trusts (the mtime, and the ctime where there is one) is
|
||||
/// at least [`RACY`] older than the moment the stamp was taken** —
|
||||
/// otherwise a write inside the same timestamp tick, after the read,
|
||||
/// leaves every one of them as it was. A timestamp that is missing, or
|
||||
/// later than the read (a clock behind the filesystem's), is racy too.
|
||||
fn racy(&self) -> bool {
|
||||
let ctime = self.identity.map(|identity| identity.ctime);
|
||||
[Some(self.mtime), ctime].into_iter().flatten().any(|stamped| match stamped {
|
||||
Some(time) => time.checked_add(RACY).is_none_or(|settled| settled > self.read_at),
|
||||
None => true,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the wall clock is now more than [`STEP_BACK`] behind where
|
||||
/// the monotonic clock says it would be had it only run forward since
|
||||
/// the read. After such a step a new write can be stamped with an old
|
||||
/// time, so no timestamp match means anything until the file is re-read.
|
||||
fn clock_stepped_back(&self, now: Clocks) -> bool {
|
||||
let expected = match now.mono.checked_duration_since(self.read_mono) {
|
||||
Some(elapsed) => self.read_at.checked_add(elapsed),
|
||||
None => self.read_at.checked_sub(self.read_mono - now.mono),
|
||||
};
|
||||
match (expected, now.wall.checked_add(STEP_BACK)) {
|
||||
(Some(expected), Some(tolerated)) => tolerated < expected,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// This stamp as if it had been taken `by` later, on both clocks: how a
|
||||
/// test ages a stamp past the racy window without waiting for it.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn taken_later(self, by: Duration) -> Stamp {
|
||||
Stamp { read_at: self.read_at + by, read_mono: self.read_mono + by, ..self }
|
||||
}
|
||||
}
|
||||
|
||||
/// Read one source file and stamp it. `Err` for a file that is gone or is
|
||||
@@ -191,33 +284,43 @@ pub fn read_source(path: &Path) -> io::Result<(String, Stamp)> {
|
||||
// Stat before reading: a write that lands between the two leaves a stamp
|
||||
// older than the bytes, which the next sweep sees as a change.
|
||||
let meta = fs::metadata(path)?;
|
||||
let read_at = SystemTime::now();
|
||||
let read = Clocks::now();
|
||||
let bytes = fs::read(path)?;
|
||||
let hash = content_hash(&bytes);
|
||||
let text = String::from_utf8(bytes)
|
||||
.map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "not UTF-8 text"))?;
|
||||
let seen = Seen::of(&meta);
|
||||
let stamp = Stamp {
|
||||
size: meta.len(),
|
||||
mtime: meta.modified().ok(),
|
||||
size: seen.size,
|
||||
mtime: seen.mtime,
|
||||
hash,
|
||||
read_at,
|
||||
identity: identity(&meta),
|
||||
read_at: read.wall,
|
||||
read_mono: read.mono,
|
||||
identity: seen.identity,
|
||||
program: text.contains("endprogram"),
|
||||
};
|
||||
Ok((text, stamp))
|
||||
}
|
||||
|
||||
/// A file's ctime (seconds, nanoseconds) and inode number.
|
||||
/// A file's ctime and inode number.
|
||||
#[cfg(unix)]
|
||||
fn identity(meta: &fs::Metadata) -> (i64, i64, u64) {
|
||||
fn identity(meta: &fs::Metadata) -> Option<Identity> {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
(meta.ctime(), meta.ctime_nsec(), meta.ino())
|
||||
let nanos = Duration::from_nanos(u64::try_from(meta.ctime_nsec()).unwrap_or(0));
|
||||
let ctime = match u64::try_from(meta.ctime()) {
|
||||
Ok(secs) => SystemTime::UNIX_EPOCH.checked_add(Duration::from_secs(secs) + nanos),
|
||||
Err(_) => SystemTime::UNIX_EPOCH
|
||||
.checked_sub(Duration::from_secs(meta.ctime().unsigned_abs()))
|
||||
.and_then(|time| time.checked_add(nanos)),
|
||||
};
|
||||
Some(Identity { ctime, ino: meta.ino() })
|
||||
}
|
||||
|
||||
/// No ctime or inode off Unix: the stamp falls back to size and mtime.
|
||||
/// No ctime or inode off Unix (std has no change time on Windows): the
|
||||
/// stamp falls back to size and mtime, and the racy rule on the mtime.
|
||||
#[cfg(not(unix))]
|
||||
fn identity(_: &fs::Metadata) -> (i64, i64, u64) {
|
||||
(0, 0, 0)
|
||||
fn identity(_: &fs::Metadata) -> Option<Identity> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -273,7 +376,7 @@ mod tests {
|
||||
let (_, stamp) = read_source(&path).unwrap();
|
||||
// Just written: racy, so suspect even though nothing moved.
|
||||
assert_eq!(stamp.check(&path), Change::Suspect);
|
||||
let settled = Stamp { read_at: stamp.read_at + RACY + RACY, ..stamp };
|
||||
let settled = stamp.taken_later(RACY + RACY);
|
||||
assert_eq!(settled.check(&path), Change::Same);
|
||||
fs::write(&path, "module a2; endmodule\n").unwrap();
|
||||
assert_eq!(settled.check(&path), Change::Suspect);
|
||||
@@ -281,4 +384,131 @@ mod tests {
|
||||
assert_eq!(settled.check(&path), Change::Gone);
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
// The racy rule, decided from values: no file, no waiting, no clock but
|
||||
// the ones given.
|
||||
|
||||
/// A stamp taken at `read` (wall) / `mono`, of a file whose mtime and
|
||||
/// ctime are `mtime_age` and `ctime_age` before the read.
|
||||
fn stamp_aged(
|
||||
read: SystemTime,
|
||||
mono: Instant,
|
||||
mtime_age: Duration,
|
||||
ctime_age: Duration,
|
||||
) -> Stamp {
|
||||
Stamp {
|
||||
size: 20,
|
||||
mtime: Some(read - mtime_age),
|
||||
hash: 7,
|
||||
read_at: read,
|
||||
read_mono: mono,
|
||||
identity: Some(Identity { ctime: Some(read - ctime_age), ino: 42 }),
|
||||
program: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// What a `stat` of the unchanged file sees.
|
||||
fn unchanged(stamp: &Stamp) -> Seen {
|
||||
Seen { size: stamp.size, mtime: stamp.mtime, identity: stamp.identity }
|
||||
}
|
||||
|
||||
/// The clocks a second after the read, both having run forward.
|
||||
fn a_second_later(stamp: &Stamp) -> Clocks {
|
||||
let second = Duration::from_secs(1);
|
||||
Clocks { wall: stamp.read_at + second, mono: stamp.read_mono + second }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_match_is_trusted_only_when_every_timestamp_was_settled_at_the_read() {
|
||||
let (read, mono) = (SystemTime::now(), Instant::now());
|
||||
let old = Duration::from_secs(3600);
|
||||
let fresh = Duration::from_millis(1);
|
||||
let cases = [
|
||||
("neither racy", old, old, Change::Same),
|
||||
("mtime racy", fresh, old, Change::Suspect),
|
||||
// The Linux hole: an old mtime put back, a ctime from this tick.
|
||||
("ctime racy", old, fresh, Change::Suspect),
|
||||
("both racy", fresh, fresh, Change::Suspect),
|
||||
("just inside the window", old, RACY - Duration::from_nanos(1), Change::Suspect),
|
||||
("exactly the window old", old, RACY, Change::Same),
|
||||
];
|
||||
for (what, mtime_age, ctime_age, expected) in cases {
|
||||
let stamp = stamp_aged(read, mono, mtime_age, ctime_age);
|
||||
assert_eq!(
|
||||
stamp.compare(unchanged(&stamp), a_second_later(&stamp)),
|
||||
expected,
|
||||
"{what}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_timestamp_later_than_the_read_or_missing_is_racy() {
|
||||
let (read, mono) = (SystemTime::now(), Instant::now());
|
||||
let old = Duration::from_secs(3600);
|
||||
let mut ahead = stamp_aged(read, mono, old, old);
|
||||
ahead.identity = Some(Identity { ctime: Some(read + Duration::from_secs(60)), ino: 42 });
|
||||
assert_eq!(ahead.compare(unchanged(&ahead), a_second_later(&ahead)), Change::Suspect);
|
||||
let mut no_ctime = stamp_aged(read, mono, old, old);
|
||||
no_ctime.identity = Some(Identity { ctime: None, ino: 42 });
|
||||
assert_eq!(
|
||||
no_ctime.compare(unchanged(&no_ctime), a_second_later(&no_ctime)),
|
||||
Change::Suspect
|
||||
);
|
||||
let mut no_mtime = stamp_aged(read, mono, old, old);
|
||||
no_mtime.mtime = None;
|
||||
assert_eq!(
|
||||
no_mtime.compare(unchanged(&no_mtime), a_second_later(&no_mtime)),
|
||||
Change::Suspect
|
||||
);
|
||||
// Off Unix there is no ctime to trust: the mtime alone decides.
|
||||
let mut off_unix = stamp_aged(read, mono, old, old);
|
||||
off_unix.identity = None;
|
||||
assert_eq!(off_unix.compare(unchanged(&off_unix), a_second_later(&off_unix)), Change::Same);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wall_clock_stepped_back_since_the_read_distrusts_the_stamp() {
|
||||
let (read, mono) = (SystemTime::now(), Instant::now());
|
||||
let old = Duration::from_secs(3600);
|
||||
let stamp = stamp_aged(read, mono, old, old);
|
||||
let ten = Duration::from_secs(10);
|
||||
// Ten seconds of real time, but the wall clock shows one: stepped back.
|
||||
let back = Clocks { wall: read + Duration::from_secs(1), mono: mono + ten };
|
||||
assert_eq!(stamp.compare(unchanged(&stamp), back), Change::Suspect);
|
||||
// Behind the read itself.
|
||||
let behind = Clocks { wall: read - ten, mono: mono + Duration::from_secs(1) };
|
||||
assert_eq!(stamp.compare(unchanged(&stamp), behind), Change::Suspect);
|
||||
// A wall clock that ran ahead (a suspend the monotonic clock slept
|
||||
// through) is no reason to doubt anything.
|
||||
let ahead = Clocks { wall: read + ten, mono: mono + Duration::from_secs(1) };
|
||||
assert_eq!(stamp.compare(unchanged(&stamp), ahead), Change::Same);
|
||||
// Jitter under the tolerance is not a step.
|
||||
let jitter = Clocks { wall: read + ten - STEP_BACK / 2, mono: mono + ten };
|
||||
assert_eq!(stamp.compare(unchanged(&stamp), jitter), Change::Same);
|
||||
// A stamp aged on both clocks at once is not a step either.
|
||||
let aged = stamp.taken_later(ten);
|
||||
assert_eq!(aged.compare(unchanged(&aged), a_second_later(&stamp)), Change::Same);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn any_moved_field_is_suspect_however_settled() {
|
||||
let (read, mono) = (SystemTime::now(), Instant::now());
|
||||
let old = Duration::from_secs(3600);
|
||||
let stamp = stamp_aged(read, mono, old, old);
|
||||
let now = a_second_later(&stamp);
|
||||
let same = unchanged(&stamp);
|
||||
let identity = stamp.identity.unwrap();
|
||||
let moved = [
|
||||
Seen { size: 21, ..same },
|
||||
Seen { mtime: Some(read), ..same },
|
||||
Seen { identity: Some(Identity { ino: 43, ..identity }), ..same },
|
||||
Seen { identity: Some(Identity { ctime: Some(read - old / 2), ..identity }), ..same },
|
||||
];
|
||||
for seen in moved {
|
||||
assert_eq!(stamp.compare(seen, now), Change::Suspect, "{seen:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The project one server answers about: its roots, its files, the workspace
|
||||
//! index over them, and the promise that no answer is older than the disk
|
||||
//! was when the call arrived (PLAN §4.4).
|
||||
@@ -359,3 +361,5 @@ fn relative_to(roots: &[PathBuf], path: &Path) -> String {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,10 +1,12 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The freshness promise, against the rebuild oracle: after every update
|
||||
//! path the incrementally maintained index is the index a full build over
|
||||
//! the files now on disk produces (`WorkspaceIndex::fingerprint`).
|
||||
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime};
|
||||
use std::time::Duration;
|
||||
|
||||
use vlog_semantic::WorkspaceIndex;
|
||||
|
||||
@@ -29,9 +31,8 @@ fn rebuilt(project: &Project) -> String {
|
||||
|
||||
/// Age every stamp past the racy window, so only a real change is suspect.
|
||||
fn settle(project: &mut Project) {
|
||||
let later = SystemTime::now() + Duration::from_secs(10);
|
||||
for stamp in project.files.values_mut() {
|
||||
stamp.read_at = later;
|
||||
*stamp = stamp.taken_later(Duration::from_secs(10));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,3 +108,5 @@ fn a_path_argument_must_land_inside_a_root() {
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
fs::remove_dir_all(outside).unwrap();
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The rendering rules every tool's text answer follows (PLAN §10.2): the
|
||||
//! token budget is the product.
|
||||
//!
|
||||
@@ -205,3 +207,5 @@ mod tests {
|
||||
assert_eq!(by_file(&sites), ["b.sv:3,9", "a.sv:1"]);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The `lucisv://` resources: the project overview, the lint rule
|
||||
//! reference, one unit's outline and one file's outline — the same answers
|
||||
//! `hierarchy` and `outline` give, addressable by URI for a host that
|
||||
@@ -176,3 +178,5 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The JSON-RPC 2.0 envelope and the MCP methods this server answers: the
|
||||
//! `initialize` handshake and its version negotiation, `ping`, the tool
|
||||
//! methods, the `lucisv://` resources, and an empty prompt list.
|
||||
@@ -421,3 +423,5 @@ mod tests {
|
||||
assert!(bad_tool["error"]["message"].as_str().unwrap().contains("nope"));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The declarations the files' own symbol tables hold — every one the
|
||||
//! semantic model knows and `outline` lists: typedefs, enum values,
|
||||
//! functions, tasks, genvars, generate blocks and what they declare,
|
||||
@@ -94,3 +96,5 @@ fn unit_at(items: &[Item], span: TextRange) -> Option<&str> {
|
||||
let inner = child_items(&item.kind).into_iter().find_map(|items| unit_at(items, span));
|
||||
inner.or(own.filter(|(_, name_span)| *name_span != span).map(|(name, _)| name))
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `check`: what `lucisv check` would say about one file or the whole
|
||||
//! design — the tolerant parse's errors, then the lint findings — one line
|
||||
//! each, `file:line:col severity message [rule]`, errors first.
|
||||
@@ -325,3 +327,5 @@ impl MentionOracle for Mentions<'_> {
|
||||
PackageExports::exports(self.index, package)
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `rename`, and what every design-wide edit shares: the whole-set read the
|
||||
//! engines are handed, and the step from a verified `RefactorEdit` to a
|
||||
//! written plan with the name's unresolved mentions listed.
|
||||
@@ -221,3 +223,5 @@ fn written_ranges(edits: &[TextEdit]) -> Vec<TextRange> {
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `find`: where a name is declared and, on `refs`, where each declaration
|
||||
//! is used — the question an agent otherwise answers by grepping and
|
||||
//! reading. Declarations come from the index (`names.rs`); uses from
|
||||
@@ -197,3 +199,5 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `format`: the CLI's `lucisv format` over a path or a glob, and with
|
||||
//! `fix` the CLI's `lucisv check --fix` first — each file through the one
|
||||
//! write path (`apply.rs`).
|
||||
@@ -218,3 +220,5 @@ mod tests {
|
||||
assert!(formatter_config(&auto).auto_style);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Path globs, as `format`'s `files` takes them: `*` and `?` within one
|
||||
//! path component, `**` for any run of components, and a bare directory
|
||||
//! for everything below it — the `.gitignore` / `rg -g` reading.
|
||||
@@ -100,3 +102,5 @@ mod tests {
|
||||
assert!(!path_match("ip/**", "hw/ip/aes.sv"));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `hierarchy`: the project's shape. Without a `root`, the counts and the
|
||||
//! top modules; with one, the instance tree down from it or every
|
||||
//! instantiation of it up to `depth` levels — read off the index's
|
||||
@@ -369,3 +371,5 @@ fn statement(project: &Project, texts: &mut Texts, child: &Child) -> Vec<String>
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `outline unit:` — what a unit offers the code that uses it: a module's
|
||||
//! or interface's parameters and ports in declaration order (plus an
|
||||
//! interface's modports), a package's or class's members — without the
|
||||
@@ -228,3 +230,5 @@ fn class_base(items: &[Item], name_span: TextRange) -> Option<String> {
|
||||
}
|
||||
child_items(&item.kind).into_iter().find_map(|items| class_base(items, name_span))
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `edit_item` — the structural edits under one name (`replace`,
|
||||
//! `insert_before`, `insert_after`, `delete`), the general token saver: an
|
||||
//! agent sends one item's text, never the file.
|
||||
@@ -373,3 +375,5 @@ fn end_spot(analysis: &Analysis, unit: &str, file: &str) -> Result<Spot, String>
|
||||
|
||||
/// The keywords that close a unit `end` may name.
|
||||
const END_WORDS: &[&str] = &["endmodule", "endinterface", "endprogram", "endpackage", "endclass"];
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The verifier's lexical rules — what a splice may do to the token stream
|
||||
//! and its comments, before any parse is asked:
|
||||
//!
|
||||
@@ -173,3 +175,5 @@ fn markers(tokens: &[Token], start: u32, end: u32) -> Vec<&str> {
|
||||
.map(|e| e.text.trim())
|
||||
.collect()
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `op: delete`'s macro rule: a name spelled inside a macro call's
|
||||
//! arguments (`` `ASSERT_KNOWN(k, sig) ``) or a `` `define`` body is a use
|
||||
//! no lucisv engine resolves — the lexer keeps a macro call as one token and
|
||||
@@ -106,3 +108,5 @@ mod tests {
|
||||
assert!(spellings("`define S \"sig\"\n", "sig").is_empty(), "a string is not a use");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `edit_item op: delete`'s reference rule: an item is not deleted while a
|
||||
//! name it owns (`verify::owned`) is still used anywhere in the project.
|
||||
//!
|
||||
@@ -260,3 +262,5 @@ fn position(project: &Project, set: &WholeSet, file: &Path, span: TextRange) ->
|
||||
let (line, col) = LineIndex::new(text).line_col(span.start);
|
||||
format!("{}:{line}:{col}", project.relative(file))
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Which bytes an item owns: the lines `edit_item`'s inserts and deletes
|
||||
//! work on, and the span its `replace` replaces when its text brings comments.
|
||||
//!
|
||||
@@ -155,3 +157,5 @@ mod tests {
|
||||
assert_eq!(slice(replace_region(src, item, "logic b;\n// own line")), "logic a;");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `op: delete`'s implicit-connection rule: a `.*` binds a signal without
|
||||
//! spelling it, so `find_references` (which returns only spans that spell
|
||||
//! the name) never lists it. For each deleted name, every `.*`
|
||||
@@ -94,3 +96,5 @@ fn binds(index: &WorkspaceIndex, module: &str, name: &str) -> Option<bool> {
|
||||
}
|
||||
Some(index.member(module, name).iter().any(|def| def.kind == SymbolKind::Port))
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The verifier the three structural edits share — the one new piece of
|
||||
//! logic in the MCP block, so it is guilty until proven innocent: every rule
|
||||
//! here has an attack in `tests/attacks.rs`.
|
||||
@@ -573,3 +575,5 @@ mod tests {
|
||||
assert!(owned_names(&analysis, always).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Unresolved mentions: every whole-word spelling of a name that no engine
|
||||
//! answer accounted for and that sits where no lucisv engine looks — inside
|
||||
//! a string literal, a comment, a macro call's text, a `` `define`` body, or
|
||||
@@ -345,3 +347,5 @@ mod tests {
|
||||
assert_eq!(shared_components(a, b), 4);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The tool registry: every tool's name, description, argument list and
|
||||
//! handler, in one table. The argument list is the single source of both the
|
||||
//! `inputSchema` a host shows the agent and the validation a call's
|
||||
@@ -313,3 +315,5 @@ mod tests {
|
||||
assert_eq!(schema(hierarchy.params)["properties"]["depth"], json!({"type": "integer"}));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Names looked up — the by-name half every lean tool shares: every
|
||||
//! declaration of a name (the index's units, exported members and module
|
||||
//! internals, every declaration the files' own symbol tables hold, and the
|
||||
@@ -232,3 +234,5 @@ mod tests {
|
||||
assert_eq!(qualified(".x"), (None, ".x"));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `outline`: a file's declarations as a tree with line ranges (its parse
|
||||
//! errors first), or — for `unit` — what a unit offers the code that uses
|
||||
//! it (`interface.rs`), so an agent reads the shape before the source.
|
||||
@@ -59,3 +61,5 @@ fn tree(analysis: &Analysis, nodes: &[DocumentSymbol], level: usize, out: &mut V
|
||||
tree(analysis, &node.children, level + 1, out);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `port`'s `after`: the new port placed right after a named one, in the
|
||||
//! layout of the line it follows, and each named connection placed right
|
||||
//! after the instance's `.after(…)`.
|
||||
@@ -446,3 +448,5 @@ mod tests {
|
||||
assert_eq!(appended_expr(".e(x)", "d"), None);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Where a new list element goes after its anchor, and how it is written.
|
||||
//!
|
||||
//! The element always goes **after the separator that follows the anchor**
|
||||
@@ -304,3 +306,5 @@ mod tests {
|
||||
assert_eq!(split_declaration("input dbg_i").unwrap().ty, "");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The check a placement must pass before anything is written: the placed
|
||||
//! edit is the engine's verified edit with elements **moved and nothing
|
||||
//! else**. Per file, against the engine's result:
|
||||
@@ -308,3 +310,5 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `port`: add a port to a module and connect it by name in every
|
||||
//! instantiation, or remove one and its connection everywhere — the
|
||||
//! design-wide edit a file write cannot do safely. `add` is
|
||||
@@ -144,3 +146,5 @@ fn instantiations(project: &Project, module: &str) -> (usize, usize) {
|
||||
let files: BTreeSet<_> = edges.iter().map(|edge| edge.file).collect();
|
||||
(count, files.len())
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `read`: one item's exact source — a slice, never the file — preceded by
|
||||
//! `file:first–last`. In a named `file` the item is sliced as
|
||||
//! `read_item::select` slices it; without one the name is looked up
|
||||
@@ -78,3 +80,5 @@ fn locate(project: &mut Project, selector: &str) -> Result<PathBuf, String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The item slicer `read` and `edit_item` share: one item's exact span in
|
||||
//! a file — a module, a function, a declaration, an instance, or an
|
||||
//! unlabelled `always` block named by the line it covers.
|
||||
@@ -317,3 +319,5 @@ module n; logic q; endmodule
|
||||
assert!(refused.contains("`\\b` on line 12"), "{refused}");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Declaration sites read back off the disk: `find` and the by-name tools
|
||||
//! answer with `file:line` for declarations in files no analysis is held
|
||||
//! for. One read per file per call ([`Texts`]); the index's spans are
|
||||
@@ -271,3 +273,5 @@ mod tests {
|
||||
assert_eq!(capped("x y", 3), "x y");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The MCP stdio transport: one JSON-RPC message per line in, one per line
|
||||
//! out. stdout carries protocol lines and nothing else; stderr is the log.
|
||||
//!
|
||||
@@ -93,3 +95,5 @@ mod tests {
|
||||
assert_eq!(written, "{\"text\":\"a\\nb\"}\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The dev's attack suite on the structural edits' verifier (lane M4) —
|
||||
//! CLAUDE.md invariant 4 applied to the MCP block's own safety net: every
|
||||
//! case is an edit the verifier could plausibly let through, asserted
|
||||
@@ -784,3 +786,5 @@ fn a_signal_bound_by_a_dot_star_is_still_referenced() {
|
||||
let clk = json!({"file": "rtl/sw.sv", "item": "clk"});
|
||||
refused(&tree, &mut server, "delete_item", clk, "bound by `.*` at rtl/sw.sv:7:18 `clk`");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The index caches over the wire (TODO-MCP M6, PLAN §6): the language
|
||||
//! server's `index-cache` is read and never written — its bytes are hashed
|
||||
//! before and after a whole session that indexes, answers and edits — every
|
||||
@@ -276,3 +278,5 @@ fn an_unwritable_cache_directory_still_answers_and_says_so_on_exit() {
|
||||
assert_eq!(stderr.matches("cannot write the index cache").count(), 1, "{stderr}");
|
||||
assert!(fs::read_dir(scratch.cache()).unwrap().next().is_none(), "nothing was written");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The `hierarchy` cap counts instances, never `peek` lines (census round 5,
|
||||
//! 2026-09-29): an agent asking for every instantiation of a module with
|
||||
//! `peek` gets every one up to 100 (300 without `peek`), each with its
|
||||
@@ -135,3 +137,5 @@ fn over_100_instances_with_peek_shows_100_and_over_300_without_shows_300() {
|
||||
assert_eq!(plain.lines().count(), 301);
|
||||
assert!(plain.ends_with("\n… and 51 more\n"), "{plain}");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The opentitan census (TODO-MCP M2, ported to the lean catalogue in M7):
|
||||
//! `find`, `hierarchy`, `check` and `outline` over a real checkout,
|
||||
//! read-only, each answer checked against what the language server answers
|
||||
@@ -288,3 +290,5 @@ fn opentitan_startup_cold_and_warm_and_the_stat_sweep() {
|
||||
let _ = std::fs::remove_dir_all(&cache);
|
||||
assert_eq!(status(&root), before, "the checkout was only read");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane feedback-1 (unresolved mentions, `add_port`'s `after`
|
||||
//! and its move-checker, the trimmed catalogue, the temp-store sweep),
|
||||
//! 2026-09-23 — ported to the lean catalogue: `add_port` is `port` with
|
||||
@@ -696,3 +698,5 @@ fn qa_the_sweep_takes_only_old_files_of_the_exact_temp_name() {
|
||||
}
|
||||
assert!(dir.join("inside").is_dir(), "a directory is never swept");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane feedback-2 (the count line on every paged answer, the
|
||||
//! `in` path glob, the post-edit check line), 2026-09-23 — ported to the
|
||||
//! lean catalogue: paging, `in` and the check line are gone (PLAN §10.2),
|
||||
@@ -282,3 +284,5 @@ fn qa_the_glob_matches_paths_never_names_even_escaped_ones_holding_a_star() {
|
||||
assert_eq!(formatted("esc/*.sv"), "1");
|
||||
assert!(formatted("\\esc*mod").contains("\\esc*mod"), "a unit name is not a path");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane M1 (transport + read tools), 2026-09-23.
|
||||
//!
|
||||
//! Every test spawns the real binary over a scratch tree, as a host would.
|
||||
@@ -954,3 +956,5 @@ fn qa_rework_a_rename_over_with_an_old_mtime_and_the_same_size_is_seen() {
|
||||
set_mtime(&scratch.path("c.sv"), long_ago);
|
||||
assert_eq!(s.text("find", json!({"name": "chyrlie"})), "module chyrlie c.sv:1\n");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane M2 (navigation, diagnostics, defines, resources),
|
||||
//! 2026-09-23 — ported to the lean catalogue (`find`, `hierarchy`, `check`;
|
||||
//! `docs/features/mcp-lean-catalogue/README.md` lists what was deleted: the
|
||||
@@ -796,3 +798,5 @@ fn qa_recheck_one_files_check_is_its_lines_of_lucisv_check_dot() {
|
||||
);
|
||||
assert_eq!(s.text("check", json!({"file": "leaf.sv"})), "ok\n");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane M3 (the edit tools and their one write path),
|
||||
//! 2026-09-23 — ported to the lean catalogue (`rename`, `port`,
|
||||
//! `edit_item`, `format`); the tools it dropped took their attacks with
|
||||
@@ -706,6 +708,15 @@ fn qa_lucisv_check_over_the_same_tree_while_the_server_formats() {
|
||||
copy_tree(&scratch.0, &reference.0);
|
||||
let status = Command::new(&cli).arg("--no-cache").arg(&reference.0).output().unwrap();
|
||||
assert!(status.status.success(), "{status:?}");
|
||||
// The server is spawned before the checker starts, never while it runs.
|
||||
// A spawn on one thread can inherit a pipe another thread is just
|
||||
// creating for its child: macOS has no `pipe2`, so close-on-exec is set
|
||||
// in a second step. Seen once under load (2026-11-19, `lsof`): the
|
||||
// server held the write end of a `lucisv --check`'s stdout. That
|
||||
// `output()` never saw EOF, `join` below waited on it, and the server,
|
||||
// which lives until this test ends, never let go, so the test hung.
|
||||
// Spawned first, the server cannot hold any of the checker's pipes.
|
||||
let mut server = Session::over(&scratch);
|
||||
let stop = Arc::new(AtomicBool::new(false));
|
||||
let checker = {
|
||||
let (stop, cli, root) = (Arc::clone(&stop), cli.clone(), scratch.0.clone());
|
||||
@@ -719,7 +730,6 @@ fn qa_lucisv_check_over_the_same_tree_while_the_server_formats() {
|
||||
codes
|
||||
})
|
||||
};
|
||||
let mut server = Session::over(&scratch);
|
||||
for _ in 0..5 {
|
||||
for (name, text) in &messy {
|
||||
scratch.write(name, text);
|
||||
@@ -1218,3 +1228,5 @@ fn qa_a_large_file_behind_a_link_out_of_the_root_is_not_in_the_skipped_set() {
|
||||
let text = text_of(&server.rename_d());
|
||||
assert!(!text.contains(outside.root()), "{text}");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane M4 (the structural edits and their verifier),
|
||||
//! 2026-09-23.
|
||||
//!
|
||||
@@ -1308,3 +1310,5 @@ fn qa_recheck_a_define_item_may_be_inserted_but_not_nested_in_an_always() {
|
||||
}
|
||||
assert!(strict(&tree.read("rtl/d.sv")));
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane M6 (the index caches and the rule-6 ruling),
|
||||
//! 2026-09-23.
|
||||
//!
|
||||
@@ -702,3 +704,5 @@ fn qa_the_instructions_are_short_and_name_only_real_tools() {
|
||||
assert!(text.contains(phrase), "{phrase}: {text}");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane M7 (the lean catalogue), 2026-09-24.
|
||||
//!
|
||||
//! Every test writes a small design into its own scratch directory, spawns
|
||||
@@ -867,3 +869,5 @@ fn a_members_rename_lists_only_its_own_mentions_and_dotted_ones_elsewhere() {
|
||||
let found = text(&tree, "find", json!({"name": "p.W", "refs": true}));
|
||||
assert!(found.contains("unresolved:\n rtl/u.sv:2\n"), "a package member lists all: {found}");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! QA attacks on lane M8 (`--read-only`), 2026-09-29.
|
||||
//!
|
||||
//! Every test copies a fixture into its own scratch directory, spawns the
|
||||
@@ -113,7 +115,14 @@ fn run(args: &[&str], lines: &[Value]) -> Output {
|
||||
Value::String(raw) => raw.clone(),
|
||||
other => other.to_string(),
|
||||
};
|
||||
writeln!(stdin, "{text}").unwrap();
|
||||
// A refused argument list exits 2 before reading a byte, so the write
|
||||
// races that exit and can fail with `BrokenPipe`. That is the child
|
||||
// being gone, not the test failing: what it said and its exit code
|
||||
// are what the caller asserts on. Any other error is a failure.
|
||||
match writeln!(stdin, "{text}") {
|
||||
Err(error) if error.kind() == std::io::ErrorKind::BrokenPipe => break,
|
||||
result => result.unwrap(),
|
||||
}
|
||||
}
|
||||
drop(stdin);
|
||||
child.wait_with_output().unwrap()
|
||||
@@ -555,3 +564,5 @@ fn qa_the_node_cap_is_exact_at_300_and_301_plain_and_100_and_101_with_peek() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `lucisv-mcp --read-only` (PLAN §11), pinned against the real binary: the
|
||||
//! five read tools within their budget, the edit tools unknown, full mode as
|
||||
//! 0.58.0 shipped it, and the promise that nothing inside a root is created,
|
||||
@@ -339,3 +341,5 @@ fn the_edit_calls_write_in_full_mode() {
|
||||
assert_ne!(before, snapshot(&tree), "{name} wrote nothing in full mode");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The wire contract, pinned against the real binary: each test copies the
|
||||
//! fixture design into its own temporary directory, spawns `lucisv-mcp` over
|
||||
//! it and talks newline-delimited JSON-RPC to it, as a host would.
|
||||
@@ -1264,3 +1266,5 @@ fn a_stale_temp_store_is_swept_and_a_young_one_and_other_files_are_spared() {
|
||||
assert!(young.exists(), "a young one may be a live writer's");
|
||||
assert!(other.exists(), "only `<store>.<pid>.tmp` is ours to sweep");
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
# Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
[package]
|
||||
name = "lucisv_server"
|
||||
version.workspace = true
|
||||
@@ -19,3 +21,5 @@ lsp-server = { workspace = true }
|
||||
lsp-types = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
# Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The preset `style = "auto"` last settled on, per document.
|
||||
//!
|
||||
//! Under `auto`, every formatting request needs a concrete preset, and
|
||||
@@ -402,3 +404,5 @@ endmodule
|
||||
assert_eq!(styles.recall(&uri), None, "a whole-document format under a named style");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The tables a completion request reads instead of walking the workspace.
|
||||
//!
|
||||
//! Completion fires on every keystroke, so nothing here may be computed per
|
||||
@@ -843,7 +845,7 @@ fn macros_of(index: &WorkspaceIndex) -> Vec<Macro> {
|
||||
}
|
||||
|
||||
/// One `` `define``'s completion entry.
|
||||
fn macro_of(define: &vlog_parser::defines::Define) -> Macro {
|
||||
pub(crate) fn macro_of(define: &vlog_parser::defines::Define) -> Macro {
|
||||
let args = match &define.params {
|
||||
Some(params) => format!("({})", params.join(", ")),
|
||||
None => String::new(),
|
||||
@@ -1670,3 +1672,5 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -0,0 +1,131 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Which byte a "symbol under the cursor" request is about.
|
||||
//!
|
||||
//! An LSP position is a caret *between* two characters, and a span here is
|
||||
//! end-exclusive, so a caret just past an identifier's last letter names the
|
||||
//! character **after** the name. VS Code calls that caret "on the word" — a
|
||||
//! double-click, a click on the right half of the last letter, or a jump that
|
||||
//! selects the name all leave it there, and its own word highlight and the
|
||||
//! title of a references search both use the word before it. Asking about the
|
||||
//! next character instead answered `[]`, and VS Code said "No references
|
||||
//! found" for a name it was showing as selected
|
||||
//! (`docs/features/scan-ordering/README.md`, A1).
|
||||
//!
|
||||
//! The rule is VS Code's: a caret touching a name on its right edge is on
|
||||
//! that name — unless a name also starts at the caret, which then wins
|
||||
//! (`a|b` cannot happen; `a|.b` is on `a`, `a.|b` is on `b`).
|
||||
|
||||
/// The byte offset a request about the name under the cursor should resolve,
|
||||
/// given the caret's byte offset in `text`.
|
||||
///
|
||||
/// Moves one byte left when the caret is just past a name and not at the
|
||||
/// start of another; every other caret is returned unchanged. A name is an
|
||||
/// identifier, keyword, system task, macro or number written with
|
||||
/// [`is_name_byte`] — or an escaped identifier, `\` up to the whitespace that
|
||||
/// ends it, whose own characters can be anything.
|
||||
pub fn symbol_offset(text: &str, caret: u32) -> u32 {
|
||||
let bytes = text.as_bytes();
|
||||
let at = caret as usize;
|
||||
if at == 0 || at > bytes.len() || bytes.get(at).copied().is_some_and(is_name_byte) {
|
||||
return caret;
|
||||
}
|
||||
let before = bytes[at - 1];
|
||||
if is_name_byte(before) || ends_an_escaped_identifier(bytes, at) {
|
||||
return caret - 1;
|
||||
}
|
||||
caret
|
||||
}
|
||||
|
||||
/// Whether `byte` can be part of a simple identifier (IEEE 1800-2017 §5.6):
|
||||
/// a letter, a digit, `_` or `$`. A system task's leading `$` and a macro
|
||||
/// name after its backtick are covered by the same set.
|
||||
fn is_name_byte(byte: u8) -> bool {
|
||||
byte.is_ascii_alphanumeric() || byte == b'_' || byte == b'$'
|
||||
}
|
||||
|
||||
/// Whether the caret at `at` sits on the whitespace (or the end of the text)
|
||||
/// that terminates an escaped identifier — a `\` followed by at least one
|
||||
/// non-whitespace byte, all of it before the caret.
|
||||
fn ends_an_escaped_identifier(bytes: &[u8], at: usize) -> bool {
|
||||
if bytes.get(at).is_some_and(|b| !b.is_ascii_whitespace()) {
|
||||
return false;
|
||||
}
|
||||
let start = bytes[..at].iter().rposition(u8::is_ascii_whitespace).map_or(0, |ws| ws + 1);
|
||||
at - start >= 2 && bytes[start] == b'\\'
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::symbol_offset;
|
||||
|
||||
/// The offset `symbol_offset` picks for the caret written as `|` in
|
||||
/// `marked`, as the character it lands on (`None` past the end).
|
||||
fn lands_on(marked: &str) -> Option<char> {
|
||||
let caret = marked.find('|').expect("a caret") as u32;
|
||||
let text = marked.replacen('|', "", 1);
|
||||
let at = symbol_offset(&text, caret) as usize;
|
||||
text[at..].chars().next()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_caret_just_past_a_name_is_on_its_last_letter() {
|
||||
assert_eq!(lands_on("logic tx|,"), Some('x'));
|
||||
assert_eq!(lands_on("assign y = tx|;"), Some('x'));
|
||||
assert_eq!(lands_on("tx|"), Some('x'), "at the end of the text");
|
||||
assert_eq!(lands_on("logic tx|\nwire w;"), Some('x'), "at the end of a line");
|
||||
assert_eq!(lands_on("logic tx|\r\nwire w;"), Some('x'), "before a CRLF");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_caret_on_or_inside_a_name_is_left_alone() {
|
||||
assert_eq!(lands_on("logic |tx;"), Some('t'), "at the start");
|
||||
assert_eq!(lands_on("logic t|x;"), Some('x'), "in the middle");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_caret_touching_two_names_takes_the_one_that_starts_there() {
|
||||
// VS Code's word at `a|.b` is `a`; at `a.|b` it is `b`.
|
||||
assert_eq!(lands_on("u_a|.sig"), Some('a'), "before the dot: the instance");
|
||||
assert_eq!(lands_on("u_a.|sig"), Some('s'), "after the dot: the member");
|
||||
assert_eq!(lands_on(".clk|(clk_i)"), Some('k'), "a port name before its paren");
|
||||
assert_eq!(lands_on(".clk(|clk_i)"), Some('c'), "the signal after the paren");
|
||||
assert_eq!(lands_on("mem|[3]"), Some('m'), "a name before an index");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_caret_after_anything_but_a_name_is_left_alone() {
|
||||
assert_eq!(lands_on("a = b;|"), None, "past a semicolon at the end");
|
||||
assert_eq!(lands_on("a = b; |"), None, "past whitespace");
|
||||
assert_eq!(lands_on("f(x)|;"), Some(';'), "past a paren");
|
||||
assert_eq!(lands_on("|"), None, "an empty text");
|
||||
assert_eq!(lands_on("|tx"), Some('t'), "the very start");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_tasks_macros_and_keywords_are_names_too() {
|
||||
assert_eq!(lands_on("$display|("), Some('y'));
|
||||
assert_eq!(lands_on("`WIDTH|-1"), Some('H'));
|
||||
assert_eq!(lands_on("begin|\n"), Some('n'), "so a keyword pair highlights");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_escaped_identifier_ends_at_its_whitespace() {
|
||||
// `\a+b ` is one name whose last byte is not an identifier byte.
|
||||
assert_eq!(lands_on(r"assign \a+b+ |= 1;"), Some('='), "past the space: not on it");
|
||||
assert_eq!(lands_on(r"assign \a+b+| = 1;"), Some('+'), "on the space that ends it");
|
||||
assert_eq!(lands_on(r"\bus[0]|"), Some(']'), "at the end of the text");
|
||||
assert_eq!(lands_on(r"x = a \| b;"), Some(' '), "a lone backslash is not a name");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_ascii_text_before_the_name_does_not_move_the_byte() {
|
||||
// The caret arrives as a byte offset already converted from UTF-16;
|
||||
// the rule reads bytes, and a multi-byte character is never a name.
|
||||
assert_eq!(lands_on("// é\nlogic tx|;"), Some('x'));
|
||||
assert_eq!(lands_on("é|tx"), Some('t'), "a name starting after a non-ASCII letter");
|
||||
assert_eq!(lands_on("é|;"), Some(';'), "a non-ASCII letter is not a name");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `textDocument/codeAction` — one quick fix per Safe lint fix, plus one
|
||||
//! `source.fixAll.lucisv` that applies all of them in a single pass.
|
||||
//!
|
||||
@@ -476,3 +478,5 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Tiers 2 and 3: what the buffer being typed in declares, and the words it
|
||||
//! uses (TODO §68.1, `completion-ux`).
|
||||
//!
|
||||
@@ -142,3 +144,5 @@ endmodule
|
||||
assert!(sort("al_used") < sort("always_ff"));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! What a connection-list entry inserts (TODO §68.1, `completion-ux`).
|
||||
//!
|
||||
//! After the `.` of `sub u_sub (.cl|` or `sub #(.WI|`, accepting a port or a
|
||||
@@ -100,3 +102,5 @@ mod tests {
|
||||
assert!(!paren_follows(".cl, .b(x)", 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The completion tests' harness: a scratch workspace on disk, and the
|
||||
//! handful of helpers every provider's tests ask through.
|
||||
//!
|
||||
@@ -112,3 +114,5 @@ pub(super) fn find<'a>(items: &'a [CompletionItem], label: &str) -> Option<&'a C
|
||||
pub(super) fn labels(items: &[CompletionItem]) -> Vec<&str> {
|
||||
items.iter().map(|item| item.label.as_str()).collect()
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The member answer: after a `.` or a `::`, the members of what stands
|
||||
//! before it and nothing else.
|
||||
//!
|
||||
@@ -1203,3 +1205,5 @@ endmodule
|
||||
assert!(items.iter().any(|i| tier(i) == TIER_WORD || tier(i) == TIER_KEYWORD));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! `textDocument/completion` — module hinting, templates, keywords, and every
|
||||
//! name the project uses.
|
||||
//!
|
||||
@@ -79,6 +81,7 @@ use buffer::{buffer_word_tier, declared_tier};
|
||||
use connection::Connection;
|
||||
use member::member_answer;
|
||||
use module::module_tier;
|
||||
use related::{related_macros, related_tier};
|
||||
use site::{at_module_item, at_statement, enclosing_scopes};
|
||||
use tiers::{index_tier, keyword_tier, scope_tier, template_tier, word_tier};
|
||||
use word::typed_word;
|
||||
@@ -90,6 +93,7 @@ pub(crate) use module::{nearest_definition, plan_for};
|
||||
pub(crate) use module::module_header;
|
||||
pub(crate) use site::at_instantiation_site;
|
||||
pub(crate) use tiers::layout_at;
|
||||
pub(crate) use wire::{item_defaults_support, with_item_defaults};
|
||||
|
||||
mod buffer;
|
||||
mod connection;
|
||||
@@ -97,8 +101,10 @@ mod connection;
|
||||
mod harness;
|
||||
mod member;
|
||||
mod module;
|
||||
mod related;
|
||||
mod site;
|
||||
mod tiers;
|
||||
mod wire;
|
||||
mod word;
|
||||
|
||||
/// How many items one response carries, over every tier.
|
||||
@@ -151,10 +157,14 @@ const TIER_SCOPE: char = '1';
|
||||
/// (`completion-ux`, TODO §68.1).
|
||||
const TIER_DECLARED: char = '2';
|
||||
const TIER_BUFFER_WORD: char = '3';
|
||||
const TIER_INDEX: char = '4';
|
||||
const TIER_TEMPLATE: char = '5';
|
||||
const TIER_KEYWORD: char = '6';
|
||||
const TIER_WORD: char = '7';
|
||||
/// What the file is related to — the packages it imports, the classes its
|
||||
/// class extends, the headers it includes — below the file itself and above
|
||||
/// the rest of the workspace (`related.rs`).
|
||||
const TIER_RELATED: char = '4';
|
||||
const TIER_INDEX: char = '5';
|
||||
const TIER_TEMPLATE: char = '6';
|
||||
const TIER_KEYWORD: char = '7';
|
||||
const TIER_WORD: char = '8';
|
||||
|
||||
/// What a multi-line item tells the client about its own whitespace.
|
||||
///
|
||||
@@ -205,6 +215,7 @@ pub fn completions(
|
||||
// The backtick itself is replaced, so the item may carry its own.
|
||||
let replacing = TextRange::new(word.start.saturating_sub(1), offset);
|
||||
let mut items = Items::new(doc, replacing);
|
||||
related_macros(&mut items, ws, doc, &word.text);
|
||||
for entry in ws.candidates().macros(&word.text) {
|
||||
items.simple(
|
||||
&format!("`{}", entry.name),
|
||||
@@ -243,6 +254,7 @@ pub fn completions(
|
||||
scope_tier(&mut items, doc, &word, fuzzy.as_ref());
|
||||
declared_tier(&mut items, doc, &word, fuzzy.as_ref());
|
||||
buffer_word_tier(&mut items, doc, &word, fuzzy.as_ref());
|
||||
related_tier(&mut items, ws, doc, &word, fuzzy.as_ref());
|
||||
index_tier(&mut items, ws, &word, fuzzy.as_ref());
|
||||
template_tier(&mut items, ws, doc, &word, snippets, at_item, at_statement);
|
||||
keyword_tier(&mut items, &word);
|
||||
@@ -273,6 +285,10 @@ struct Items {
|
||||
items: Vec<CompletionItem>,
|
||||
seen: HashSet<String>,
|
||||
incomplete: bool,
|
||||
/// How many of `items` the related tier added — which [`LIMIT`] does not
|
||||
/// count, so every other tier fills exactly as far as it would without
|
||||
/// them (`related.rs`).
|
||||
related: usize,
|
||||
}
|
||||
|
||||
impl Items {
|
||||
@@ -282,6 +298,7 @@ impl Items {
|
||||
items: Vec::new(),
|
||||
seen: HashSet::new(),
|
||||
incomplete: false,
|
||||
related: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,7 +306,7 @@ impl Items {
|
||||
/// only sets [`Items::incomplete`] — which is why the tiers ask first
|
||||
/// rather than building items nobody will see.
|
||||
fn full(&mut self) -> bool {
|
||||
if self.items.len() >= LIMIT {
|
||||
if self.items.len() - self.related >= LIMIT {
|
||||
self.incomplete = true;
|
||||
return true;
|
||||
}
|
||||
@@ -310,6 +327,14 @@ impl Items {
|
||||
if self.full() || self.seen.contains(name) {
|
||||
return;
|
||||
}
|
||||
self.unlimited(name, kind, tier, detail);
|
||||
}
|
||||
|
||||
/// [`Items::simple`] past the cap: the caller has its own.
|
||||
fn unlimited(&mut self, name: &str, kind: CompletionItemKind, tier: char, detail: String) {
|
||||
if !self.seen.insert(name.to_string()) {
|
||||
return;
|
||||
}
|
||||
let item = CompletionItem {
|
||||
label: name.to_string(),
|
||||
kind: Some(kind),
|
||||
@@ -322,7 +347,7 @@ impl Items {
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
self.push(item);
|
||||
self.items.push(item);
|
||||
}
|
||||
|
||||
/// A port or parameter after a connection list's `.`: the bare name, or
|
||||
@@ -894,3 +919,5 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Tier 0 — module names at module-item position — and the instantiation
|
||||
//! planning that `inline.rs`'s ghost and `instantiate.rs`'s command share.
|
||||
//!
|
||||
@@ -921,3 +923,5 @@ endmodule
|
||||
assert!(vlog_refactor::module_definition(&index, "nope").is_err());
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -0,0 +1,345 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The **related** tier: what this file is related to through the workspace
|
||||
//! index, ranked above the rest of the workspace and below the file itself
|
||||
//! (`docs/features/fast-actions/README.md`, completion through the
|
||||
//! relationship map).
|
||||
//!
|
||||
//! The tier-5 table answers "every package member, typedef, class and module
|
||||
//! the workspace declares whose name matches", alphabetically, until the
|
||||
//! response is full — so in a workspace of tens of thousands of files the
|
||||
//! members of the one package this file actually imports were cut off behind
|
||||
//! names from files it has nothing to do with (measured: 46 of 47 matching
|
||||
//! `aes_pkg` names offered at `ae` in 4 000 files, 11 of 47 in 40 000). What a
|
||||
//! file is related to is known without reading anything: the packages its
|
||||
//! scope chain imports, the classes its enclosing class extends, the headers
|
||||
//! its `` `include``s reach. Those names come first.
|
||||
//!
|
||||
//! **No item is taken away.** A related item does not count against
|
||||
//! [`LIMIT`](super::LIMIT): the tiers after it fill exactly as far as they
|
||||
//! did before, and a name the related tier claimed is skipped by them
|
||||
//! without being counted, so every label of the old answer is still offered,
|
||||
//! with the same edit and format (the completion-equivalence test holds the
|
||||
//! server to that). **What does change** for a name the related tier claims
|
||||
//! is its icon and its detail: they now describe the declaration the file is
|
||||
//! related to — the member of the package it imports, the macro of the header
|
||||
//! it includes, the member of the class it extends — where the workspace tier
|
||||
//! described the first declaration of that name in the whole workspace
|
||||
//! (`NumRegs` of whichever register package sorts first; a module of the name
|
||||
//! where the imported package declares a function). The tier has its own
|
||||
//! cap, [`RELATED_LIMIT`], past which it says the answer is incomplete.
|
||||
|
||||
use lsp_types::CompletionItemKind;
|
||||
use vlog_parser::defines::DefineKind;
|
||||
use vlog_semantic::{Def, ScopeKind, Semantics, SymbolKind};
|
||||
|
||||
use super::tiers::innermost_scope;
|
||||
use super::word::Word;
|
||||
use super::{completion_kind, Items, TIER_RELATED};
|
||||
use crate::candidates::{rank_cmp, starts_with_ignore_case, Query, Score};
|
||||
use crate::state::{Document, Workspace};
|
||||
use crate::symbols::kind_label;
|
||||
|
||||
/// How many related names one response carries at most.
|
||||
///
|
||||
/// A package of a few hundred members is the large case (`aes_pkg` has 259
|
||||
/// on its connection surface); at an empty prefix the related tier would
|
||||
/// otherwise double a response that is already incomplete.
|
||||
pub(super) const RELATED_LIMIT: usize = 256;
|
||||
|
||||
/// One related name: what to show, and how it ranks.
|
||||
struct Related {
|
||||
name: String,
|
||||
kind: SymbolKind,
|
||||
detail: String,
|
||||
}
|
||||
|
||||
impl Items {
|
||||
/// Add a related item, unless a higher tier already offered that name or
|
||||
/// the tier is full. Not counted against [`LIMIT`](super::LIMIT).
|
||||
fn related(&mut self, name: &str, kind: CompletionItemKind, detail: String) {
|
||||
if self.seen.contains(name) {
|
||||
return;
|
||||
}
|
||||
if self.related >= RELATED_LIMIT {
|
||||
self.incomplete = true;
|
||||
return;
|
||||
}
|
||||
self.related += 1;
|
||||
self.unlimited(name, kind, TIER_RELATED, detail);
|
||||
}
|
||||
}
|
||||
|
||||
/// The related tier for a name being typed: the members of every package
|
||||
/// the scope chain at the cursor imports, and of the classes the enclosing
|
||||
/// class extends.
|
||||
pub(super) fn related_tier(
|
||||
items: &mut Items,
|
||||
ws: &Workspace,
|
||||
doc: &Document,
|
||||
word: &Word,
|
||||
fuzzy: Option<&Query>,
|
||||
) {
|
||||
let mut found = imported(ws, &doc.semantics, word.start);
|
||||
found.extend(inherited(ws, &doc.semantics, word.start));
|
||||
let mut matched: Vec<(Related, Option<Score>)> = found
|
||||
.into_iter()
|
||||
.filter_map(|related| match fuzzy {
|
||||
None => starts_with_ignore_case(&related.name, &word.text).then_some((related, None)),
|
||||
Some(query) => query.score(&related.name).map(|score| (related, Some(score))),
|
||||
})
|
||||
.collect();
|
||||
matched.sort_by(|(a, sa), (b, sb)| match (sa, sb) {
|
||||
(Some(sa), Some(sb)) => rank_cmp((&a.name, *sa), (&b.name, *sb)),
|
||||
_ => a.name.cmp(&b.name),
|
||||
});
|
||||
for (related, _) in matched {
|
||||
items.related(&related.name, completion_kind(related.kind), related.detail);
|
||||
}
|
||||
}
|
||||
|
||||
/// The related tier after a backtick: the macros the headers this buffer
|
||||
/// reaches through its `` `include``s define, ahead of every other macro in
|
||||
/// the workspace.
|
||||
pub(super) fn related_macros(items: &mut Items, ws: &Workspace, doc: &Document, prefix: &str) {
|
||||
let mut names: Vec<(String, String)> = Vec::new();
|
||||
for path in crate::includes::reachable_from(ws, doc) {
|
||||
let Some(table) = ws.index().file_id(&path).and_then(|file| ws.index().defines(file))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let defines = table.entries().iter().filter(|d| d.kind == DefineKind::Define);
|
||||
for define in defines.filter(|d| starts_with_ignore_case(&d.name, prefix)) {
|
||||
names.push((define.name.clone(), crate::candidates::macro_of(define).detail));
|
||||
}
|
||||
}
|
||||
names.sort();
|
||||
names.dedup_by(|a, b| a.0 == b.0);
|
||||
for (name, detail) in names {
|
||||
items.related(&format!("`{name}"), CompletionItemKind::CONSTANT, detail);
|
||||
}
|
||||
}
|
||||
|
||||
/// Every member of every package imported by a scope enclosing `offset`,
|
||||
/// innermost scope first, a wildcard bringing all of a package's members and
|
||||
/// an explicit import the one it names.
|
||||
fn imported(ws: &Workspace, semantics: &Semantics, offset: u32) -> Vec<Related> {
|
||||
let mut out = Vec::new();
|
||||
let mut at = innermost_scope(semantics, offset).or(Some(semantics.file_scope()));
|
||||
while let Some(id) = at {
|
||||
let Some(scope) = semantics.scope(id) else { break };
|
||||
at = scope.parent;
|
||||
for import in &scope.imports {
|
||||
for (name, defs) in ws.index().members_of(&import.package) {
|
||||
if import.item.as_deref().is_some_and(|item| item != name) {
|
||||
continue;
|
||||
}
|
||||
let Some(def) = defs.first() else { continue };
|
||||
out.push(Related {
|
||||
name: name.to_string(),
|
||||
kind: def.kind,
|
||||
detail: format!("{} — {}::{name}", kind_label(def.kind), import.package),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Every member the enclosing class inherits, as the index's member chain for
|
||||
/// that class lists it — its own members included, which the scope tier has
|
||||
/// already claimed — each named after the class that **declares** it, the
|
||||
/// way the workspace tier names a member (`base_c::count`).
|
||||
fn inherited(ws: &Workspace, semantics: &Semantics, offset: u32) -> Vec<Related> {
|
||||
let mut at = innermost_scope(semantics, offset);
|
||||
while let Some(id) = at {
|
||||
let Some(scope) = semantics.scope(id) else { break };
|
||||
if scope.kind == ScopeKind::Class {
|
||||
let Some(key) = semantics.member_key(id) else { return Vec::new() };
|
||||
let index = ws.index();
|
||||
return index
|
||||
.members_of_chain(&key)
|
||||
.into_iter()
|
||||
.map(|(name, def)| {
|
||||
let owner = declaring_class(ws, &key, name, def).unwrap_or(&key);
|
||||
Related {
|
||||
name: name.to_string(),
|
||||
kind: def.kind,
|
||||
detail: format!("{} — {owner}::{name}", kind_label(def.kind)),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
at = scope.parent;
|
||||
}
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Which class of `class`'s `extends` chain declares `def` as `name`: the
|
||||
/// class itself, then its base, then that base's base — each hop the one
|
||||
/// `vlog_semantic`'s `base_chain` takes, a recorded base or else the class a
|
||||
/// typedef aliases (`typedef mid_c alias_t; class leaf_c extends alias_t;`).
|
||||
/// `None` only for a chain the index cannot follow, and the caller then
|
||||
/// names the class it started from.
|
||||
fn declaring_class<'a>(
|
||||
ws: &'a Workspace,
|
||||
class: &'a str,
|
||||
name: &str,
|
||||
def: &Def,
|
||||
) -> Option<&'a str> {
|
||||
let index = ws.index();
|
||||
let mut hop = Some(class);
|
||||
let mut seen: Vec<&str> = Vec::new();
|
||||
while let Some(unit) = hop.filter(|unit| !seen.contains(unit)) {
|
||||
if index.members_of(unit).any(|(member, defs)| member == name && defs.first() == Some(def))
|
||||
{
|
||||
return Some(unit);
|
||||
}
|
||||
seen.push(unit);
|
||||
hop = index.base_of(unit).or_else(|| aliased_class(ws, unit)).map(last_segment);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// The class a typedef names, when `unit` is a typedef the index holds once —
|
||||
/// the alias hop of `vlog_semantic`'s `base_chain` (`aliased_unit`), read
|
||||
/// through the index's public tables.
|
||||
fn aliased_class<'a>(ws: &'a Workspace, unit: &str) -> Option<&'a str> {
|
||||
match ws.index().units(unit) {
|
||||
[def] if def.kind == SymbolKind::Typedef => def.type_name.as_deref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The last `::` segment of a possibly qualified class path — the name the
|
||||
/// member and inheritance tables are keyed by.
|
||||
fn last_segment(path: &str) -> &str {
|
||||
path.rsplit("::").next().unwrap_or(path)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::completion::harness::*;
|
||||
use crate::completion::*;
|
||||
|
||||
/// A package the buffer imports, and one it does not, both holding names
|
||||
/// that start alike.
|
||||
fn two_packages(name: &str) -> Tree {
|
||||
let tree = Tree::new(name);
|
||||
tree.write(
|
||||
"near.sv",
|
||||
"package near_pkg;\n localparam int ZED_NEAR = 1;\n typedef logic zed_t;\nendpackage\n",
|
||||
);
|
||||
tree.write("far.sv", "package far_pkg;\n localparam int ZED_FAR = 2;\nendpackage\n");
|
||||
tree
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_imported_packages_members_rank_above_the_rest_of_the_workspace() {
|
||||
let top = "module top;\n import near_pkg::*;\n assign x = ze\nendmodule\n";
|
||||
let (_tree, ws, uri, position) = opened(two_packages("rel_import"), top, "= ze");
|
||||
let items = items(completions(&ws, &uri, position, true));
|
||||
let near = find(&items, "ZED_NEAR").expect("the imported member");
|
||||
let far = find(&items, "ZED_FAR").expect("the other package's member is still offered");
|
||||
assert_eq!(tier(near), TIER_RELATED);
|
||||
assert_eq!(tier(far), TIER_INDEX);
|
||||
assert!(near.sort_text < far.sort_text, "related above the workspace");
|
||||
assert_eq!(near.detail.as_deref(), Some("localparam — near_pkg::ZED_NEAR"));
|
||||
assert_eq!(tier(find(&items, "zed_t").expect("the typedef")), TIER_RELATED);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_explicit_import_relates_the_one_name_it_imports() {
|
||||
let top = "module top;\n import near_pkg::zed_t;\n assign x = ze\nendmodule\n";
|
||||
let (_tree, ws, uri, position) = opened(two_packages("rel_explicit"), top, "= ze");
|
||||
let items = items(completions(&ws, &uri, position, true));
|
||||
// The binder makes an explicitly imported name a declaration of this
|
||||
// scope, so it is offered by the scope tier, above even this one.
|
||||
assert!(tier(find(&items, "zed_t").expect("imported")) <= TIER_RELATED);
|
||||
assert_eq!(tier(find(&items, "ZED_NEAR").expect("still offered")), TIER_INDEX);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn related_items_take_nothing_from_the_tiers_after_them() {
|
||||
// More project names than the cap, and an import whose members all
|
||||
// match too: the workspace tiers still fill the whole cap.
|
||||
let tree = two_packages("rel_cap");
|
||||
let mut many = String::from("package many_pkg;\n");
|
||||
for i in 0..LIMIT + 40 {
|
||||
many.push_str(&format!(" localparam int ZED_{i:04} = {i};\n"));
|
||||
}
|
||||
many.push_str("endpackage\n");
|
||||
tree.write("many.sv", &many);
|
||||
let top = "module top;\n import near_pkg::*;\n assign x = ZE\nendmodule\n";
|
||||
let (_tree, ws, uri, position) = opened(tree, top, "= ZE");
|
||||
let Some(CompletionResponse::List(list)) = completions(&ws, &uri, position, true) else {
|
||||
panic!("a list");
|
||||
};
|
||||
let related = list.items.iter().filter(|i| tier(i) == TIER_RELATED).count();
|
||||
assert_eq!(related, 2, "the two near_pkg names");
|
||||
assert_eq!(list.items.len() - related, LIMIT, "the cap counts the others only");
|
||||
assert!(list.is_incomplete);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_class_relates_what_it_inherits() {
|
||||
let tree = Tree::new("rel_class");
|
||||
tree.write(
|
||||
"base.sv",
|
||||
"class base_c;\n int zed_count;\n function void zed_reset();\n endfunction\nendclass\n",
|
||||
);
|
||||
let top = "class derived_c extends base_c;\n function void go();\n ze\n endfunction\nendclass\n";
|
||||
let (_tree, ws, uri, position) = opened(tree, top, " ze");
|
||||
let items = items(completions(&ws, &uri, position, true));
|
||||
let count = find(&items, "zed_count").expect("inherited");
|
||||
assert_eq!(tier(count), TIER_RELATED);
|
||||
assert_eq!(tier(find(&items, "zed_reset").expect("inherited")), TIER_RELATED);
|
||||
// Named after the class that declares it, as the workspace tier
|
||||
// names a member — not after the class that inherits it.
|
||||
assert_eq!(count.detail.as_deref(), Some("variable — base_c::zed_count"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_backtick_ranks_what_the_included_headers_define_first() {
|
||||
let tree = Tree::new("rel_macro");
|
||||
tree.write("near.svh", "`define ZED_NEAR 1\n");
|
||||
tree.write("far.svh", "`define ZED_FAR 2\n");
|
||||
let top = "`include \"near.svh\"\nmodule top;\n assign x = `ZE\nendmodule\n";
|
||||
let (_tree, ws, uri, position) = opened(tree, top, "`ZE");
|
||||
let items = items(completions(&ws, &uri, position, true));
|
||||
let near = find(&items, "`ZED_NEAR").expect("the included header's macro");
|
||||
let far = find(&items, "`ZED_FAR").expect("every other macro is still offered");
|
||||
assert_eq!(tier(near), TIER_RELATED);
|
||||
assert!(near.sort_text < far.sort_text);
|
||||
assert_eq!(near.detail.as_deref(), Some("`define ZED_NEAR"), "the detail tier 5 gives");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_member_two_classes_up_names_the_class_that_declares_it() {
|
||||
let tree = Tree::new("rel_grand");
|
||||
tree.write("base.sv", "class root_c;\n int zed_deep;\nendclass\nclass mid_c extends root_c;\n int zed_mid;\nendclass\n");
|
||||
let top =
|
||||
"class leaf_c extends mid_c;\n function void go();\n ze\n endfunction\nendclass\n";
|
||||
let (_tree, ws, uri, position) = opened(tree, top, " ze");
|
||||
let items = items(completions(&ws, &uri, position, true));
|
||||
let detail = |label: &str| find(&items, label).and_then(|i| i.detail.clone());
|
||||
assert_eq!(detail("zed_deep").as_deref(), Some("variable — root_c::zed_deep"));
|
||||
assert_eq!(detail("zed_mid").as_deref(), Some("variable — mid_c::zed_mid"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_member_reached_through_a_typedef_alias_names_the_class_that_declares_it() {
|
||||
// QA R2: `leaf_c extends alias_t`, and `alias_t` is a typedef of
|
||||
// `mid_c` — the member is `mid_c`'s.
|
||||
let tree = Tree::new("rel_alias");
|
||||
tree.write("base.sv", "class mid_c;\n int zed_mid;\nendclass\ntypedef mid_c alias_t;\n");
|
||||
let top = "class leaf_c extends alias_t;\n function void go();\n ze\n endfunction\nendclass\n";
|
||||
let (_tree, ws, uri, position) = opened(tree, top, " ze");
|
||||
let items = items(completions(&ws, &uri, position, true));
|
||||
let mid = find(&items, "zed_mid").expect("inherited through the alias");
|
||||
assert_eq!(tier(mid), TIER_RELATED);
|
||||
assert_eq!(mid.detail.as_deref(), Some("variable — mid_c::zed_mid"));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! What may be written here: the module-item gate and the statement gate,
|
||||
//! judged over the token stream's scope chain.
|
||||
//!
|
||||
@@ -262,3 +264,5 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Tiers 1 to 5: the five ordinary tiers, in the order they fill the
|
||||
//! response.
|
||||
//!
|
||||
@@ -944,3 +946,5 @@ endmodule
|
||||
assert!(labels(&items).contains(&"ov_in_buffer"), "{:?}", labels(&items));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -0,0 +1,152 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! What a completion answer costs on the wire, for a client that can take
|
||||
//! less (`docs/features/fast-actions/README.md`, "payload").
|
||||
//!
|
||||
//! Every item of one answer replaces the same range, and almost every item
|
||||
//! inserts its own label as plain text — so the `textEdit` each one carries
|
||||
//! (49 % of a 130 KB answer, measured) and its `insertTextFormat` (8 %) say
|
||||
//! the same thing five hundred times. LSP 3.17's `CompletionList.itemDefaults`
|
||||
//! says it once: an item with no `textEdit` replaces `editRange` with its
|
||||
//! `textEditText`, or with its label when it has none, in
|
||||
//! `insertTextFormat`. `vscode-languageclient` 9 applies exactly that rule
|
||||
//! (`protocolConverter.asCompletionInsertText`), and advertises both defaults.
|
||||
//!
|
||||
//! **The same edits, fewer bytes.** The rewrite is lossless by construction:
|
||||
//! an item keeps its own `textEdit` unless its range *is* the default, keeps
|
||||
//! its own format unless it *is* the default, and moves a `newText` that is
|
||||
//! not its label into `textEditText`. Done on the serialized answer because
|
||||
//! `lsp-types` 0.97 has neither field.
|
||||
|
||||
use lsp_types::InitializeParams;
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
/// `insertTextFormat: PlainText`, the format nearly every item has.
|
||||
const PLAIN_TEXT: u64 = 1;
|
||||
|
||||
/// Whether the client applies `itemDefaults.editRange` and
|
||||
/// `itemDefaults.insertTextFormat` — `textDocument.completion.completionList
|
||||
/// .itemDefaults` listing both. A client that said nothing gets every item
|
||||
/// whole, which is what every client got before this was read.
|
||||
pub(crate) fn item_defaults_support(params: &InitializeParams) -> bool {
|
||||
let listed = params
|
||||
.capabilities
|
||||
.text_document
|
||||
.as_ref()
|
||||
.and_then(|text_document| text_document.completion.as_ref())
|
||||
.and_then(|completion| completion.completion_list.as_ref())
|
||||
.and_then(|list| list.item_defaults.as_ref());
|
||||
listed.is_some_and(|names| {
|
||||
["editRange", "insertTextFormat"].iter().all(|wanted| names.iter().any(|n| n == wanted))
|
||||
})
|
||||
}
|
||||
|
||||
/// Rewrite a serialized `CompletionList` so the range and the format every
|
||||
/// item shares are said once, in `itemDefaults`. Anything that is not a list
|
||||
/// with items comes back as it was.
|
||||
pub(crate) fn with_item_defaults(mut answer: Value) -> Value {
|
||||
let Some(list) = answer.as_object_mut() else { return answer };
|
||||
let Some(Value::Array(items)) = list.get_mut("items") else { return answer };
|
||||
let Some(range) = items.first().and_then(edit_range).cloned() else { return answer };
|
||||
for item in items.iter_mut().filter_map(Value::as_object_mut) {
|
||||
lift_edit(item, &range);
|
||||
if item.get("insertTextFormat").and_then(Value::as_u64) == Some(PLAIN_TEXT) {
|
||||
item.remove("insertTextFormat");
|
||||
}
|
||||
}
|
||||
let mut defaults = Map::new();
|
||||
defaults.insert("editRange".to_string(), range);
|
||||
defaults.insert("insertTextFormat".to_string(), Value::from(PLAIN_TEXT));
|
||||
list.insert("itemDefaults".to_string(), Value::Object(defaults));
|
||||
answer
|
||||
}
|
||||
|
||||
/// The range a plain `textEdit` replaces, if the item has one.
|
||||
fn edit_range(item: &Value) -> Option<&Value> {
|
||||
let edit = item.get("textEdit")?;
|
||||
edit.get("newText")?;
|
||||
edit.get("range")
|
||||
}
|
||||
|
||||
/// Drop `item`'s `textEdit` when it replaces `range`, keeping its text in
|
||||
/// `textEditText` unless that text is the label.
|
||||
fn lift_edit(item: &mut Map<String, Value>, range: &Value) {
|
||||
let Some(edit) = item.get("textEdit") else { return };
|
||||
if edit.get("range") != Some(range) {
|
||||
return;
|
||||
}
|
||||
let Some(Value::Object(mut edit)) = item.remove("textEdit") else { return };
|
||||
let new_text = edit.remove("newText").unwrap_or(Value::Null);
|
||||
if item.get("label") != Some(&new_text) {
|
||||
item.insert("textEditText".to_string(), new_text);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
fn range(line: u32) -> Value {
|
||||
json!({ "start": { "line": line, "character": 4 }, "end": { "line": line, "character": 6 } })
|
||||
}
|
||||
|
||||
/// The edit an item makes under the LSP 3.17 rule, defaults applied.
|
||||
fn effective(item: &Value, defaults: &Value) -> (Value, Value, Value) {
|
||||
let format = item.get("insertTextFormat").unwrap_or(&defaults["insertTextFormat"]).clone();
|
||||
match item.get("textEdit") {
|
||||
Some(edit) => (edit["range"].clone(), edit["newText"].clone(), format),
|
||||
None => (
|
||||
defaults["editRange"].clone(),
|
||||
item.get("textEditText").unwrap_or(&item["label"]).clone(),
|
||||
format,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_item_makes_the_same_edit_with_the_defaults_applied() {
|
||||
let before = json!({ "isIncomplete": true, "items": [
|
||||
{ "label": "sig", "insertTextFormat": 1,
|
||||
"textEdit": { "range": range(2), "newText": "sig" } },
|
||||
{ "label": "if begin/end", "insertTextFormat": 2,
|
||||
"textEdit": { "range": range(2), "newText": "if (${1:cond}) begin\n$0\nend" } },
|
||||
{ "label": "`W", "insertTextFormat": 1,
|
||||
"textEdit": { "range": range(2), "newText": "`W" } },
|
||||
{ "label": "odd", "insertTextFormat": 1,
|
||||
"textEdit": { "range": range(7), "newText": "odd" } },
|
||||
]});
|
||||
let after = with_item_defaults(before.clone());
|
||||
let defaults = &after["itemDefaults"];
|
||||
assert_eq!(defaults["editRange"], range(2));
|
||||
for (old, new) in
|
||||
before["items"].as_array().unwrap().iter().zip(after["items"].as_array().unwrap())
|
||||
{
|
||||
let old_effect = (
|
||||
old["textEdit"]["range"].clone(),
|
||||
old["textEdit"]["newText"].clone(),
|
||||
old["insertTextFormat"].clone(),
|
||||
);
|
||||
assert_eq!(effective(new, defaults), old_effect, "{new}");
|
||||
}
|
||||
assert!(after["items"][0].get("textEdit").is_none(), "the label is the text");
|
||||
assert!(after["items"][0].get("textEditText").is_none());
|
||||
assert_eq!(after["items"][1]["textEditText"], before["items"][1]["textEdit"]["newText"]);
|
||||
assert!(after["items"][3].get("textEdit").is_some(), "another range keeps its edit");
|
||||
assert!(after.to_string().len() < before.to_string().len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_answer_that_is_not_a_list_of_edits_is_left_alone() {
|
||||
for answer in [
|
||||
Value::Null,
|
||||
json!([]),
|
||||
json!({ "isIncomplete": false, "items": [] }),
|
||||
json!({ "items": [{ "label": "x", "insertText": "x" }] }),
|
||||
] {
|
||||
assert_eq!(with_item_defaults(answer.clone()), answer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! What is typed: the identifier run ending at the cursor and what stands
|
||||
//! around it — a backtick, a `.` or a `::`, and the spine a separator
|
||||
//! follows.
|
||||
@@ -244,3 +246,5 @@ pub(super) fn line_head_is_blank(text: &str, at: u32) -> bool {
|
||||
let line_start = head.rfind('\n').map_or(0, |newline| newline + 1);
|
||||
head.get(line_start..).is_some_and(|head| head.chars().all(|c| c == ' ' || c == '\t'))
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Byte offsets ↔ LSP positions.
|
||||
//!
|
||||
//! Everything below the protocol speaks UTF-8 byte offsets; LSP `Position`
|
||||
@@ -518,3 +520,5 @@ mod tests {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! The VS Code instance-oriented design hierarchy.
|
||||
//!
|
||||
//! LSP call hierarchy deliberately groups a module's calls by target module
|
||||
@@ -523,3 +525,5 @@ mod tests {
|
||||
.unwrap_or_else(|| panic!("no module {name}: {modules:#?}"))
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Diagnostics, published on every buffer change.
|
||||
|
||||
use lsp_types::{Diagnostic, DiagnosticSeverity};
|
||||
@@ -199,3 +201,5 @@ mod tests {
|
||||
assert!(diags[0].range.start < diags[0].range.end, "must be drawable");
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
@@ -1,3 +1,5 @@
|
||||
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
||||
|
||||
//! Single-step macro expansion, for hover **display** only.
|
||||
//!
|
||||
//! One step means one thing: the definition's body with the call site's
|
||||
@@ -430,3 +432,5 @@ mod tests {
|
||||
assert!(!has_macro_use("plain text"));
|
||||
}
|
||||
}
|
||||
|
||||
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|
||||
Loaded 100 of 883 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user