mrcjkb / rustaceanvim

Supercharge your Rust experience in Neovim! A heavily modified fork of rust-tools.nvim
GNU General Public License v2.0
1.3k stars 47 forks source link

Error messages being printed when using both rustaceannvim and mfussenegger/nvim-lint #440

Closed jfclavette closed 2 weeks ago

jfclavette commented 2 weeks ago

Have you read the docs and searched existing issues?

Neovim version (nvim -v)

v0.10.0

Operating system/version

Up-to-date Arch Linux

Output of :checkhealth rustaceanvim

==============================================================================
rustaceanvim: require("rustaceanvim.health").check()

Checking for Lua dependencies ~
- OK [mfussenegger/nvim-dap](https://github.com/mfussenegger/nvim-dap) installed.

Checking external dependencies ~
- OK rust-analyzer: found rust-analyzer 1.81.0-nightly (4bc39f0 2024-06-26)
- OK Cargo: found cargo 1.81.0-nightly (4ed7bee47 2024-06-25)
- OK rustc: found rustc 1.81.0-nightly (4bc39f028 2024-06-26)
- OK debug adapter: found codelldb 

Checking config ~
- OK No errors found in config.

Checking for conflicting plugins ~
- OK No conflicting plugins detected.

Checking for tree-sitter parser ~
- OK tree-sitter parser for Rust detected.

How to reproduce the issue

cargo new bug
nvim bug/src/main.rs

Below the println add:

let b = HashMap::<usize, usize>::new();

Save file.
Put cursor on HashMap.
:RustLsp codeAction
Highlight import if it isn't already.
Press Enter

Expected behaviour

No error message is printed.

Actual behaviour

The code action succeeds, but error messages are printed.

E5108: Error executing lua: ...aceanvim/lua/rustaceanvim/commands/code_action_group.lua:90: BufEnter Autocommands for "": Vim(append):Error running markdownlint: ENOENT: no such file or directory
stack traceback:
[C]: in function 'nvim_set_current_win'
...aceanvim/lua/rustaceanvim/commands/code_action_group.lua:90: in function <...aceanvim/lua/rustaceanvim/commands/code_action_group.lua:88>
E5108: Error executing lua: ...cal/share/nvim/lazy/rustaceanvim/lua/rustaceanvim/ui.lua:13: BufEnter Autocommands for "
": Vim(append):Error running markdownlint: ENOENT: no such file or directory
stack traceback:
[C]: in function 'nvim_win_close'
...cal/share/nvim/lazy/rustaceanvim/lua/rustaceanvim/ui.lua:13: in function 'close_win'
...aceanvim/lua/rustaceanvim/commands/code_action_group.lua:262: in function <...aceanvim/lua/rustaceanvim/commands/code_action_group.lua:254>
E492: Not an editor command: messagse

The minimal config used to reproduce this issue.

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        {
            "mrcjkb/rustaceanvim",
            version = "^4",
            init = function()
                -- Configure rustaceanvim here
                vim.g.rustaceanvim = {}
            end,
            lazy = false,
        },
        {
            "mfussenegger/nvim-lint",
            event = { "BufReadPre", "BufNewFile" },
            config = function()
                local lint = require("lint")

                local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
                vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
                    group = lint_augroup,
                    callback = function()
                        require("lint").try_lint()
                    end,
                })
            end,
        },
    },
})
jfclavette commented 2 weeks ago

Handling of BufReadPre event seems to be the culprit.

mrcjkb commented 2 weeks ago

Hey 👋

This isn't a rustaceanvim bug.

The issue is that you're running require("lint").try_lint() on a markdown buffer (the code action group selector) that's not a file on the filesystem; which can often be the case in Neovim (another example is fugitive blob buffers).

The function should probably check if the file exists on the filesystem before trying to run the linter (although some linter configurations may be capable of passing the buffer content).

Or, you could work around it by checking if the file is readonly in your callback.

Example for Linux:

if not vim.bo[0].readonly then
  require("lint").try_lint()
end