roniker 0.2.0

Create custom LSPs for RON configurations at compile time.
Documentation

roniker

This is a library that builds custom LSPs for applications configured with RON. Good LSP support can make configuring your application significantly easier.

Step 0: Create your configuration structs

Chances are, your application already has these:

// config.rs

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Configuration {
  /// Run without a database.
  ephemeral: bool,
}

Step 1: build script

The build script reads your config structs and turns them into LSP state that can be serialized and embedded into your application:

let mut analyzer = roniker::RustAnalyzer::new("crate::config::Configuration");
analyzer.add_file(PathBuf::from("src/config.rs"));

let json = serde_json::to_string(&analyzer)?;
let dest = PathBuf::from(std::env::var("OUT_DIR")?).join("rust_analyzer.json");
std::fs::write(&dest, json)?;

println!("cargo:rerun-if-changed=src/config.rs");

Step 2: serve LSP

Now you just need to dedicate a subcommand of your application to running the LSP:

#[derive(Subcommand, Debug, Clone)]
pub enum Commands {
  Lsp,
}

pub async fn run_lsp() -> Result<()> {

    let rust_analyzer: RustAnalyzer = serde_json::from_str(include_str!(concat!(
        env!("OUT_DIR"),
        "/rust_analyzer.json"
    )))?;

    roniker::serve(rust_analyzer).await;
    Ok(())
}

Now you should be able to run <app> lsp and it will start reading stdin and writing LSP messages to stdout.

Step 3: configure editor

Lastly you need to configure your editor to use the lsp subcommand above. There should be a clear pattern that selects the files you want the custom LSP to run on.

Helix

[language-server]
custom-lsp = { command = "custom", args = ["lsp"] }

[[language]]
name = "ron"
auto-format = true
scope = "source.ron"
injection-regex = "ron"
file-types = ["ron", { glob = "custom.ron" }]
comment-token = "//"
block-comment-tokens = { start = "/*", end = "*/" }
indent = { tab-width = 4, unit = "    " }
roots = ["Cargo.toml"]
language-servers = ["custom-lsp"]

Now open a file