saecki / crates.nvim

A neovim plugin that helps managing crates.io dependencies
MIT License
867 stars 30 forks source link

Occasional Table Overflow #128

Closed dsully closed 5 months ago

dsully commented 5 months ago

Description

Occasionally I'll have a Cargo.toml buffer hang. I'm not exactly sure how to trigger it.

Neovim version

0.10

Health check

crates: require("crates.health").check() Checking plugins ~ - null-ls.nvim not found Checking external dependencies ~ - OK curl installed - OK open installed

Operating system and version

macOS 14.5

Expected behavior

The buffer doesn't hang.

Actual behavior

Eventually the buffer will unfreeze and I'll get this notification:

stack traceback:
    [C]: in function 'insert'
    ...ly/.local/share/nvim/lazy/crates.nvim/lua/crates/api.lua:615: in function 'add_search_callback'
    ...ly/.local/share/nvim/lazy/crates.nvim/lua/crates/api.lua:626: in function 'data'
    .../.local/share/nvim/lazy/crates.nvim/lua/crates/async.lua:13: in function 'c'
    ...ly/.local/share/nvim/lazy/crates.nvim/lua/crates/api.lua:272: in function 'on_exit'
    ...ly/.local/share/nvim/lazy/crates.nvim/lua/crates/api.lua:126: in function <...ly/.local/share/nvim/lazy/crates.nvim/lua/crates/api.lua:124>

Minimal config

-- comment out, and add the things that are _necessary_ for reproducing the ISSUE
for name, url in pairs({
    crates = "https://github.com/saecki/crates.nvim",
    plenary = "https://github.com/nvim-lua/plenary.nvim",
    cmp = "https://github.com/hrsh7th/nvim-cmp",
}) do
    local install_path = vim.fn.fnamemodify("crates_issue/" .. name, ":p")
    if vim.fn.isdirectory(install_path) == 0 then
        vim.notify("cloning " .. url .. " into " .. install_path)
        vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
    end
    vim.opt.runtimepath:append(install_path)
end

require("crates").setup({

            completion = {
                crates = {
                    enabled = true,
                    max_results = 8,
                    min_chars = 3,
                },
            },
            lsp = {
                actions = true,
                completion = true,
                enabled = true,
                hover = true,
            },
            on_attach = function()
                require("cmp").setup.buffer({
                    sources = {
                        { name = "async_path" },
                        { name = "buffer" },
                        { name = "nvim_lsp" },
                    },
                })
            end,
            popup = {
                autofocus = true,
                border = vim.g.border,
            },

})

require("cmp").setup({
    sources = { { name = "crates" } },
})

Cargo.toml

Any Cargo.toml

Steps to reproduce

  1. nvim --clean -u minimal.lua
  2. ...
dsully commented 5 months ago

Ok - I think having a dependency with path = "/some/path" for a crate that has features triggers the hang.

saecki commented 5 months ago

I can't reproduce the issue. The config also seems to be a bit off. You haven't enabled the cmp source in crates.nvim with the completions.cmp.enabled key, but are using the "crates" source in the nvim-cmp setup, which isn't needed when using the language server.

Even with both of them enabled:

require("crates").setup({
    lsp = {
        actions = true,
        completion = true,
        enabled = true,
        hover = true,
    },
    completion = {
        crates = {
            enabled = true,
            max_results = 8,
            min_chars = 3,
        },
        cmp = {
            enabled = true,
        },
    },
    ...
})

I can't reproduce any freezes.

I'm guessing that "async_path" is this plugin? That seems to be archived, have you checked if that might be the culprit?

dsully commented 5 months ago

Yes, that's the plugin. I just updated my config to use hrsh7th/cmp-path and the changes you suggested.

I'll see if that fixes it.

dsully commented 5 months ago

Ok, it's not path / async-path. If I disable crates completion:

completion = {
                crates = {
                    enabled = false,
                    max_results = 8,
                    min_chars = 3,
                },
                cmp = {
                    enabled = true,
                },
            },

That does not trigger the issue.

saecki commented 5 months ago

Since I can't reproduce the freezes, this is only a guess. Can you try out if the linked PR fixes your issues?

dsully commented 5 months ago

Yes, I'll try it today.

dsully commented 5 months ago

This appears to be working.. Thanks!