simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 159 forks source link

Watch for cargo.toml changes #376

Open ModProg opened 1 year ago

ModProg commented 1 year ago

I could imagine using something like https://github.com/rktjmp/fwatch.nvim (the code is very short, so probably makes sense to just copy it instead of creating a dependency).

This would ensure changes with e.g. cargo add are also registered.

IMO, this could also be something ra does itself, but apparently they want the editor to do it (https://github.com/rust-lang/rust-analyzer/issues/9546)

ModProg commented 1 year ago

POC:

function string:endswith(suffix)
    return self:sub(- #suffix) == suffix
end

local fwatch = require 'fwatch'
fwatch.watch(".", {
    on_event = function(filename)
        if filename:endswith("Cargo.toml") then
            vim.schedule(function()
                require 'lspconfig'["rust_analyzer"].commands["CargoReload"][1]()
            end)
        end
    end
})
ModProg commented 1 year ago

I created a new issue with the specific request for ra to listen for changes on its own: https://github.com/rust-lang/rust-analyzer/issues/14669.