Skip to content

fengys1996/rad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rad

rad is an abbreviation for rust-analyzer daemon. It decouples the rust-analyzer lifecycle from editor like neovim, so backend instances can outlive editor sessions. It also allows multiple editors opening the same workspace to reuse a single rust-analyzer instance.

Architecture

+----------------------+   stdio   +------------+                      +-------------+      stdio      +-----------------------+
| Neovim1              | <-------> | rad client | -------------------> |             | <-------------> | rust-analyzer A       |
| ~/source/greptimedb  |           +------------+                      |             |                 | ~/source/greptimedb   |
+----------------------+                                               |             |                 +-----------------------+
                                                                       |             |
+----------------------+   stdio   +------------+                      | rad server  |
| Neovim2              | <-------> | rad client | -------------------> | (mux/router)|      stdio      +-----------------------+
| ~/source/greptimedb  |           +------------+                      |             | <-------------> | rust-analyzer B       |
+----------------------+                                               |             |                 | ~/source/rad          |
                                                                       |             |                 +-----------------------+
+----------------------+   stdio   +------------+                      |             |
| VSCode               | <-------> | rad client | -------------------> |             |
| ~/source/rad         |           +------------+                      +-------------+
+----------------------+

Features

  • Reuse existing rust-analyzer instance for the same workspace.
  • Keep rust-analyzer alive when clients disconnect; idle reaper shuts it down after a configurable timeout.
  • Start rust-analyzer in the workspace directory to respect each project's Rust toolchain.

Configuration

The default config path is ~/.config/rad/rad.toml. Use -c / --config-file to override it.

An example config file is provided at rad.toml in the repository root.

How to Use

Run rad Server

Direct Run

rad server

systemd

For Linux setup, see deploy/systemd/README.md.

launchd (macOS)

For macOS setup, see deploy/launchd/README.md.

Configure Editor

Neovim(rustaceanvim)

An example configuration of rustaceanvim is shown below.

vim.g.rustaceanvim = {
    server = {
        cmd = function()
            return {
                vim.fn.exepath("rad"),
                "client",
            }
        end
    },
    -- other configurations
}

VSCode

VSCode's Rust Analyzer extension calls --version (-V) on the configured server binary during startup. Since rad client is a proxy command, use a wrapper script to forward version queries to the real rust-analyzer.

  1. Create a wrapper script, for example ~/.local/bin/rad-ra:
#!/bin/bash

if [[ "$1" == "--version" || "$1" == "-V" ]]; then
    exec rust-analyzer --version
fi

exec rad client "$@"
  1. Make it executable:
chmod +x ~/.local/bin/rad-ra
  1. Configure VSCode (settings.json):
{
  "rust-analyzer.server.path": "{path}/rad-ra"
}

rad status

Show all running LSP instances:

rad status

Example output:

workspace: file:///home/user/greptimedb
  pid:      12345
  clients:  2
  idle:     1m 15s
  healthy:  yes

workspace: file:///home/user/rad
  pid:      67890
  clients:  0
  idle:     5m 30s
  healthy:  yes

rad clean

Remove idle instances (no attached clients):

rad clean

Remove all instances, regardless of client count:

rad clean -f

Example output:

file:///home/user/rad (pid: 67890)

About

rad (rust-analyzer daemon) decouples rust-analyzer from the editor, allowing a single persistent instance to be shared across editors in the same workspace.

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors