mrcjkb / rustaceanvim

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

dap.autoload_configurations causes errors when opening files outside of workspace #182

Closed eero-lehtinen closed 5 months ago

eero-lehtinen commented 5 months ago

Neovim version (nvim -v)

v0.10.0 (latest nightly)

Operating system/version

EndeavourOS

Output of :checkhealth rustaceanvim

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

Checking external dependencies ~
- OK rust-analyzer: found rust-analyzer 0.3.1815-standalone
- OK Cargo: found cargo 1.75.0 (1d8b05cdd 2023-11-20)
- OK rustc: found rustc 1.75.0 (82e1608df 2023-12-21)
- OK debug adapter: found codelldb 

Checking config ~
- OK No errors found in config.

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

How to reproduce the issue

mkdir -p /tmp/minimal/
NVIM_DATA_MINIMAL="/tmp/minimal" NVIM_APP_NAME="nvim-minimal" nvim -u minimal.lua

Open file:

fn main() {
    println!("Hello, world!");
}

Use vim.lsp.buf.definition on `println!`.

Expected behaviour

No errors.

Actual behaviour

Shows error

Error executing luv callback:                                                                                                                                              
vim/fs.lua:0: invalid value (nil) at index 1 in table for 'concat'                                                                                                         
stack traceback:                                                                                                                                                           
        [C]: in function 'concat'                                                                                                                                          
        vim/fs.lua: in function 'joinpath'                                                                                                                                 
        /tmp/minimal/rustaceanvim/lua/rustaceanvim/dap.lua:197: in function 'on_exit'                                                                                      
        ...nt_nvim3WUxQh/usr/share/nvim/runtime/lua/vim/_system.lua:297: in function <...nt_nvim3WUxQh/usr/share/nvim/runtime/lua/vim/_system.lua:267>

Doesn't actually break anything and happens only the first time, but the message popping up is annoying. The error doesn't show up if dap.autoload_configurations is false.

The minimal config used to reproduce this issue.

-- Minimal nvim config with lazy
-- Assumes a directory in $NVIM_DATA_MINIMAL
-- Start with
--
-- export NVIM_DATA_MINIMAL=$(mktemp -d)
-- export NVIM_APP_NAME="nvim-ht-minimal"
-- nvim -u minimal.lua
--
-- Then exit out of neovim and start again.

-- Ignore default config
local config_path = vim.fn.stdpath("config")
vim.opt.rtp:remove(config_path)

-- Ignore default plugins
local data_path = vim.fn.stdpath("data")
local pack_path = data_path .. "/site"
vim.opt.packpath:remove(pack_path)

-- bootstrap lazy.nvim
data_path = assert(os.getenv("NVIM_DATA_MINIMAL"), "$NVIM_DATA_MINIMAL environment variable not set!")
local lazypath = data_path .. "/lazy/lazy.nvim"
local uv = vim.uv
    ---@diagnostic disable-next-line: deprecated
    or vim.loop
if not uv.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "git@github.com:folke/lazy.nvim.git",
        "--branch=stable",
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

local lazy = require("lazy")

lazy.setup({
    {
        "mrcjkb/rustaceanvim",
        version = "^3",
        init = function()
            vim.g.rustaceanvim = {}

            vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "LSP: Go to definition" })
        end,
        ft = { "rust" },
    },
    { "williamboman/mason.nvim", config = true },
    {
        "mfussenegger/nvim-dap",
        dependencies = {
            "williamboman/mason.nvim",
            "jay-babu/mason-nvim-dap.nvim",
        },
        event = "VeryLazy",
        config = function()
            require("mason-nvim-dap").setup({
                automatic_installation = false,
                ensure_installed = {
                    "codelldb",
                },
            })

            local dap = require("dap")
            vim.keymap.set("n", "<F5>", dap.continue, { desc = "Debug: Start/Continue" })
            vim.keymap.set("n", "<space>b", dap.toggle_breakpoint, { desc = "Debug: Toggle Breakpoint" })
        end,
    },
    -- Add any other plugins needed to reproduce the issue.
    -- see https://github.com/folke/lazy.nvim#-lazynvim for details.
}, { root = data_path, state = data_path .. "/lazy-state.json", lockfile = data_path .. "/lazy-lock.json" })
mrcjkb commented 5 months ago

Hey :wave:

Thanks for reporting. Should be an easy fix :smile: