Neovim and Language Server Protocol (LSP)
Language Server Protocol (LSP) helps computer programmers working on editors and get information about the languages they are working on. The LSP is an interface between editors (files, codes, cursor, state of code) and language server(s) running on the computer and the language server provides information on the state of the code.
Rust Setup for Neovim
Section titled “Rust Setup for Neovim”Source: Rust Setup For Neovim (ft BashBunni) #bash2basics - YouTube with TJ DeVries
Installing rust
Section titled “Installing rust”- Use rustup.rs
- rustc, cargo
- Get Rust LSP: rust-analyzer
New rust project, look at rust files
Section titled “New rust project, look at rust files”# Install rust LSPrustup component add rust-analyzer
# Create new projectcargo new projectname
# run project1cd projectnamecargo run
Can prefer cargo run to check for errors
Getting lspconfig setup
Section titled “Getting lspconfig setup”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
Testing out Rust basics
Section titled “Testing out Rust basics”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); }}
Writing rust tests, cargo-watch
Section titled “Writing rust tests, cargo-watch”cargo test
# Install tool to monitor for file changes and then do testscargo install cargo-watch# Tell cargo watch to run tests on source changescargo watch -x test# During later changes to source code, tests will automatically be run