rust-tools.nvim icon indicating copy to clipboard operation
rust-tools.nvim copied to clipboard

Watch for cargo.toml changes

Open ModProg opened this issue 2 years ago • 2 comments

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 avatar Apr 27 '23 08:04 ModProg

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 avatar Apr 27 '23 09:04 ModProg

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.

ModProg avatar Apr 27 '23 09:04 ModProg