rust-tools.nvim
rust-tools.nvim copied to clipboard
Extend `rust.vim`'s `Cargo` command with `add`
I did some experimenting and came up with this:
Cargo reloadreloads the cargo for lspCargo addruns add and afterwards reloads cargoCargo *will behave likerust.vim'sCargocommand.
Not sure if this fits in here, maybe in a stripped down version, as this depends on rust.vim for the non add or reload commands.
Put it in .config/nvim/after/ftplugin/rust.lua
vim.api.nvim_buf_add_user_command(0, "Cargo", function(env)
local cmd = env.args:match("^(%S+)")
io.stdout:setvbuf 'no'
if cmd == "add" then
local file = assert(io.popen('cargo ' .. env.args .. ' 2>&1', 'r'))
file:flush() -- > important to prevent receiving partial output
local output = file:read('*all')
print(output)
require'lspconfig'["rust_analyzer"].commands["CargoReload"][1]()
elseif cmd == "reload" then
require'lspconfig'["rust_analyzer"].commands["CargoReload"][1]()
else
vim.cmd('call cargo#cmd("' .. env.args .. '")')
end
end, {nargs = "+", force = true});
Yeah not sure if it's in the scope of this plugin, atleast wouldn't wanna depend on some other plugin
Yeah, just a general Idea, as a lot of people use cargo edit to manage their dependencies, and running cargo add does not reload rust-analyzer.