Skip to main content

cargo_nvim/
lib.rs

1// src/lib.rs
2//! Neovim plugin for Cargo command integration.
3//!
4//! Bridges Neovim and Cargo: Lua starts a Cargo job through the exported API and
5//! streams its output by polling. See [`job`] for the execution model.
6
7mod job;
8mod lua_exports;
9
10/// Module entry point loaded by Neovim via `require("cargo_nvim")`.
11#[mlua::lua_module]
12fn cargo_nvim(lua: &mlua::Lua) -> mlua::Result<mlua::Table> {
13    lua_exports::register_commands(lua)
14}
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19    use mlua::Lua;
20
21    #[test]
22    fn test_module_registration() {
23        let lua = Lua::new();
24        assert!(cargo_nvim(&lua).is_ok());
25    }
26
27    #[test]
28    fn test_exported_functions() {
29        let lua = Lua::new();
30        let table = cargo_nvim(&lua).unwrap();
31        assert!(table.get::<mlua::Function>("start").is_ok());
32        assert!(table.get::<mlua::Function>("poll").is_ok());
33        assert!(table.get::<mlua::Function>("send_input").is_ok());
34        assert!(table.get::<mlua::Function>("interrupt").is_ok());
35    }
36}