# Editor tooling and analyzers

> Running the declaration-incremental ranvierautocomplete LSP with Ionide, static Ranvier graph analysis, Ranvier.Analyzers, and rfs.

Three static tools inspect F# and Ranvier code before it runs — complementing runtime
[tracing and journaling](tracing-and-journal.md) and interactive [signal maps](signal-maps.md):

| Tool | Package / CLI | Where it runs | What it provides |
| --- | --- | --- | --- |
| **`Ranvier.AutoComplete`** | `ranvierautocomplete` ([`ranvier-fsharp`](https://github.com/ranvier-org/ranvier-fsharp)) | Ionide (VS Code), Neovim, Helix, Zed, Emacs | Drop-in declaration-incremental F# LSP server, opt-in static reactive graph hints/lenses (`RVR001`–`RVR003`), and colour swatches |
| **`Ranvier.Analyzers`** | `Ranvier.Analyzers` ([`Ranvier.View`](https://ranvier-org.github.io/Ranvier.View/analyzers/)) | CI (`fsharp-analyzers`), MSBuild (`RanvierAnalyze`), FSAC/LSP | Compile-time F# AST rules (`RAN001`–`RAN016`) catching untracked post-`await` reads, nested effects, and view/reactive pitfalls |
| **`Ranvier.FSharp.Agent`** | `rfs` ([`ranvier-fsharp`](https://github.com/ranvier-org/ranvier-fsharp)) | Terminal CLI, stdio MCP (`rfs_*`), `rfs tui` | Persistent per-workspace incremental F# compiler daemon for type-checking, symbol lookup, call graphs, and safe renames |

## `Ranvier.AutoComplete` with Ionide

`ranvierautocomplete` is a drop-in stdio replacement for `fsautocomplete` built on `Ranvier`
itself and `fickle-fsharp` (`FSharp.Compiler.Service`).

Instead of re-checking entire files and retaining compiler `TcState` graphs across open tabs, it
models F# declarations, signatures, and `ProjectReference` edges as a demand-driven `Ranvier`
graph:

- **Declaration-level cutoff:** editing inside a function body re-checks only that declaration
  (~`1.7–12.6` declarations per edit) and cuts off downstream files when the inferred signature is
  unchanged.

- **Zero compiler retention at rest:** hovers, classifications, diagnostics, and symbol uses are
  projected into compact immutable records (`0` `FSharpCheckFileResults` retained on the heap).

- **Live cross-project propagation:** unsaved buffer edits propagate across `ProjectReference`
  boundaries in memory without rebuilding DLLs on disk.

### Installing and connecting to Ionide

Requires the **.NET 10 SDK** (plus `fantomas` on `PATH` or in `.config/dotnet-tools.json` for
document formatting):

```bash
dotnet tool install -g Ranvier.AutoComplete
ranvierautocomplete --version
```

Point Ionide's `FSharp.fsac.netCoreDllPath` at `ranvierautocomplete.dll` (from a portable release
bundle or the global `.NET` tool store), enable semantic highlighting, and run
**`F#: Restart Language Server`** (or **`Developer: Reload Window`**):

::::tabs
:::tab VS Code (Ionide settings.json)
```json
{
  "FSharp.fsac.netCoreDllPath": "C:\\tools\\ranvier\\ranvierautocomplete.dll",
  "editor.semanticHighlighting.enabled": true,
  "FSharp.keywordsAutocomplete": true,
  "FSharp.resolveNamespaces": true,
  "FSharp.unusedOpensAnalyzer": true,
  "FSharp.unusedDeclarationsAnalyzer": true,
  "FSharp.workspaceDiagnostics": false
}
```
:::
:::tab Tool-store DLL path
```text
# Windows
%USERPROFILE%\.dotnet\tools\.store\ranvier.autocomplete\<version>\ranvier.autocomplete\<version>\tools\net10.0\any\ranvierautocomplete.dll

# Linux / macOS
~/.dotnet/tools/.store/ranvier.autocomplete/<version>/ranvier.autocomplete/<version>/tools/net10.0/any/ranvierautocomplete.dll
```
:::
:::tab Neovim 0.11+ (vim.lsp.config)
```text
-- Non-Ionide LSP clients do not send fsharp/workspacePeek;
-- set AutomaticWorkspaceInit = true so .slnx/.sln/.fsproj load automatically.
vim.lsp.config('fsautocomplete', {
  cmd = { 'ranvierautocomplete', '--ranvier-analysis' },
  filetypes = { 'fsharp' },
  root_markers = { '*.slnx', '*.sln', '*.fsproj', '.git' },
  init_options = { AutomaticWorkspaceInit = true },
})
vim.lsp.enable('fsautocomplete')
```
:::
::::

## Static Ranvier graph analysis (`FSharp.ranvierAnalysis`)

In projects referencing `Ranvier.dll`, `ranvierautocomplete` can extract your reactive graph
directly from the compiler's typed F# AST without executing user code.

It is **off by default** (zero background threads or memory when disabled) and updates 500 ms
after edits pause when enabled via `"FSharp.ranvierAnalysis": true` (or `--ranvier-analysis`):

![Ionide running ranvierautocomplete with RanvierAnalysis wake CodeLenses, write inlay hints, and RVR002/RVR003 diagnostics](/Ranvier/img/tooling/ionide-ranvier-analysis.png)

### What the static graph surfaces

The analyzer models `Signal`{fsharp}, `SignalPort`{fsharp} (`Post`{fsharp},
`Signal.post`{fsharp}), `Memo`{fsharp}, `MemoTable`{fsharp} (`memoTable { ... }`{fsharp}),
`Effect`{fsharp}, `bridge`{fsharp}, `bindSignalTo`{fsharp} / `bindMemoTo`{fsharp}, record/class
fields holding signals or ports, and `Ranvier.View` template bindings:

| Surface | Default | Example & behaviour |
| --- | --- | --- |
| **Write inlay hints** (`writes`) | `"on"` | Shown at the end of `sig.Value <- v`{fsharp} or `port.Post v`{fsharp}: `may run 1 effect · updates 2 bindings · via 2 memos · at end of batch`, or `wakes nothing`. Click effects or bindings to jump to each target. |
| **Wake CodeLenses** (`wakes`) | `"on"` | Shown above `memo`{fsharp} and `effect`{fsharp} bindings: `woken by 2 signals · 4 write sites`. Click to inspect every write site (kept even under `"FSharp.lineLens.enabled": "replaceCodeLens"`). |
| **Field hints** (`fields`) | `"off"` | Shown on record/class fields holding nodes: `written in bump (:19) · read by 2 bindings` or `never written · read by 1 binding`. |
| **Binding hints** (`bindings`) | `"off"` | Shown on `Ranvier.View` bindings and bridges: `reads Count · woken by bump (:19)`. |
| **`RVR001` warning** | active | Feedback write cycle where an effect or binding writes back into an upstream signal it reads and may never settle. |
| **`RVR002` warning** | active | Two unbatched `Value <-`{fsharp} writes in one execution path wake the same downstream effect or binding twice — wrap them in `batched { ... }`{fsharp}. |
| **`RVR003` warning** | active | Dead write to a signal or port that no tracked computation, binding, or escaping handle reads (`wakes nothing`). |

### Configuring `FSharp.ranvierHints`, hold, and toggle modes

Leaving `bindings` and `fields` on `"hold"` keeps editors clean while editing and reveals full
signal-flow provenance on demand when holding a chord (`ranvier.hold`) or toggling
(`ranvier.toggle`):

![VS Code split view showing Ionide RanvierHints configuration alongside CartView.fs with Alt+B hold hints and OKLCH colour swatch](/Ranvier/img/tooling/ionide-ranvier-hints-hold.png)

Each key in `"FSharp.ranvierHints"` accepts `"off"`, `"on"`, `"hold"`, or `"toggle"`
(`"everything"` expands all four surfaces in full without `+N more` truncation and explains every
`+ unknown` boundary):

::::tabs
:::tab .vscode/settings.json
```json
{
  "FSharp.ranvierAnalysis": true,
  "FSharp.ranvierHints": {
    "writes": "on",
    "wakes": "on",
    "bindings": "hold",
    "fields": "hold",
    "everything": "toggle",
    "holdDelayMs": 700
  },
  "[fsharp]": {
    "editor.inlayHints.maximumLength": 0
  }
}
```
:::
:::tab .vscode/keybindings.json
```json
[
  {
    "key": "alt+b",
    "command": "ranvier.hold",
    "args": ["bindings", "fields"],
    "when": "editorLangId == fsharp"
  },
  {
    "key": "alt+n",
    "command": "ranvier.toggle",
    "args": ["everything"],
    "when": "editorLangId == fsharp"
  }
]
```
:::
::::

:::note Static scope & `+ unknown` boundaries
- **Open boundaries:** when a signal or record escapes into unannotated external code or generic
  `#ISignalTarget`{fsharp} interfaces, hints append `+ unknown` rather than issuing false `RVR003`
  warnings.

- **Graph inference:** static hints model nodes as sharing one `Graph`{fsharp}. Bridges report
  `after the current update` even across separate runtime graphs.

- **Off-thread writes:** `SignalPort.Post`{fsharp} never triggers `RVR002` because off-thread
  posts coalesce in the target graph's inbox.

- **Timed builders:** `debounce`{fsharp} and `throttle*`{fsharp} report `+ unknown`.

- **Keyboard shortcut:** bind `ranvier.hold` to a repeating key chord (such as `alt+b`, avoiding
  `ctrl+alt` if VS Code's `editor.inlayHints.enabled` uses `onUnlessPressed`).

- **Hint length:** set `"[fsharp]": { "editor.inlayHints.maximumLength": 0 }` so VS Code does not
  truncate multi-site hints at 43 characters.
:::

### Parse-tree colour swatches & traced LSP packages

- **Colour swatches (`FSharp.colors.*`):** `ranvierautocomplete` renders editable VS Code colour
  swatches from the parse tree (even before project load completes) across CSS hex strings,
  `0xrrggbb` literals, `{ R; G; B }` records, tuples, and named `HSL`, `HSV`/`HSB`, `Lab`,
  `LCH`/`HCL`, `OKLab`, `OKLCH`, and `CMYK` bindings — writing edits back in the literal's
  original colour space and scale.

- **Embeddable `.Traced` checker & server:** library consumers embedding
  `Ranvier.FSharp.Checker$(RanvierSuffix)` or `Ranvier.FSharp.Server$(RanvierSuffix)` can switch
  to `.Traced` builds using the same `$(RanvierSuffix)` MSBuild property as core `Ranvier` to
  unlock live `rfs/why` causal declaration queries.

## Compile-time `Ranvier.Analyzers` (`RAN001`–`RAN016`)

`Ranvier.Analyzers` (shipped from
[`ranvier-org/Ranvier.View`](https://ranvier-org.github.io/Ranvier.View/analyzers/)) runs over the
typed F# AST via `fsharp-analyzers` in CI or MSBuild (`-p:RanvierAnalyze=true`) to enforce
reactive invariants as build errors or warnings:

| Rule family | What it catches |
| --- | --- |
| **Async tracking (`RAN012`)** | Reading `.Value`{fsharp} after a suspending `let!`{fsharp} / `do!`{fsharp} inside `task { ... }`{fsharp} or `async { ... }`{fsharp} where the tracking window is already closed ([Async and boundaries](async-and-boundaries.md#phase-1-reactive-tracking-and-ran012)). |
| **Lifecycle & purity (`RAN001`–`RAN011`)** | Creating unowned effects/memos inside recurring callbacks without a `root`{fsharp} scope, mutating signals synchronously inside memo bodies, or miswiring `cleanup`{fsharp} and `Ranvier.View` templates. |
| **Ports, bridges & tables (`RAN013`–`RAN016`)** | Redundant wrappers around `SignalPort`{fsharp} / `bridge`{fsharp}, untracked Phase-2 `MemoTable.Get`{fsharp} reads (`RAN016`), and hot-reload state hazards. |

In this repository, run the full analyzer gate across library projects with:

```bash
dotnet fsi --exec build.fsx -- analyze --group library --build
```

## CLI and coding-agent daemon (`rfs`)

`Ranvier.FSharp.Agent` (`dotnet tool install -g Ranvier.FSharp.Agent`) runs the same
declaration-incremental `Ranvier` compiler graph in a shared background daemon per workspace —
giving terminal users and AI coding agents sub-second type-checking without repeated
`dotnet build` loops:

| Command | Purpose |
| --- | --- |
| `rfs check --fail-on-error` | Re-check changed F# files on disk and all downstream referencing projects in memory |
| `rfs symbol <file> <line> --symbol <name>` | Inspect inferred F# signature, XML docs, and definition location (1-based line) |
| `rfs refs <file> <line> --symbol <name>` | List symbol uses, incoming callers (`--incoming`), or outgoing calls (`--outgoing`) |
| `rfs rename <file> <line> <new> --symbol <old> --dry-run` | Preview or apply workspace-wide semantic symbol renames |
| `rfs tui` / `rfs top --once` | Monitor live `rfs` daemons and `ranvierautocomplete` LSP memory, declaration counts, and leases |
| `rfs mcp` | Start the stdio MCP server (`rfs_check`, `rfs_symbol`, `rfs_references`, `rfs_search`, `rfs_rename`, `rfs_status`) |
