Skip to content

Neovim and Language Server Protocol (LSP)

Source: Rust Setup For Neovim (ft BashBunni) #bash2basics - YouTube with TJ DeVries

  • Use rustup.rs
    • rustc, cargo
  • Get Rust LSP: rust-analyzer
Terminal window
# Install rust LSP
rustup component add rust-analyzer
# Create new project
cargo new projectname
# run project1
cd projectname
cargo run

Can prefer cargo run to check for errors

What is an LSP?

  • Language Server Protocol (LSP)
    • Just a program
  • Helps your editor figure syntax of language, helps navigate

Example lsp.lua

lspconfig.rust_analyzer.setup {
capabilities = capabilities,
on_attach = on_attach,
-- so it can find rust-analyzer
cmd = {
"rustup", "run", "stable", "rust-analyzer"
}
}
  • Restart nvim
  • Find help at lspconfig site or the LSP server site for the language on how to integrate

main.rs

fn main() {
println!("{} world", "hello");
}
fn truthy() -> bool {
return false;
}
#[cfg(test)]
mod test {
use super::truthy;
#[test]
fn test_something() {
assert_eq!(truthy(), true);
}
}
Terminal window
cargo test
# Install tool to monitor for file changes and then do tests
cargo install cargo-watch
# Tell cargo watch to run tests on source changes
cargo watch -x test
# During later changes to source code, tests will automatically be run