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

Error during the lazy initialization, when it is triggered by pressing hotkeys

Open k0l350v opened this issue 10 months ago • 1 comments

Bug description Hello! Thank you for the great plugin. I encountered a problem when lazy initializing the plugin with keys. Here's the error log

 Failed to run `config` for cmake-tools.nvim

...pro/plugins/cmake-tools.nvim/lua/cmake-tools/scratch.lua:9: Failed to save undo information

# stacktrace:
  - /cmake-tools.nvim/lua/cmake-tools/scratch.lua:9 _in_ **create**
  - /cmake-tools.nvim/lua/cmake-tools/init.lua:1625 _in_ **register_scratch_buffer**
  - /cmake-tools.nvim/lua/cmake-tools/init.lua:83 _in_ **setup**_

if I call lazy initialization through cmd by calling any available function, no error occurs (like :CMakeSettings from Minimal configuration)

Minimal configuration

local root = vim.fn.fnamemodify("./.repro", ":p")

for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	"nvim-lua/plenary.nvim",
	{
		"Civitasv/cmake-tools.nvim",
		lazy = true,
		cmd = {
			"CMakeSettings"
		},
		keys = {
			{ "cs", "<cmd>CMakeSettings<cr>", desc = "Cmake Settings" },
		},
		opts = {},
	},

}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")

Steps to reproduce with minimal configuration

  1. run nvim -u <Minimal configuration> (you also need empty CMakeLists.txt)
  2. press cs

Environment

NVIM v0.9.5 Build type: Release LuaJIT 2.1.1710088188

k0l350v avatar Apr 23 '24 18:04 k0l350v

LazyVim uses this init function and it seems to fix the issue:

init = function()
    local loaded = false
    local function check()
        local cwd = vim.uv.cwd()
        if vim.fn.filereadable(cwd .. "/CMakeLists.txt") == 1 then
            require("lazy").load({ plugins = { "cmake-tools.nvim" } })
            loaded = true
        end
    end
    check()
    vim.api.nvim_create_autocmd("DirChanged", {
        callback = function()
            if not loaded then
                check()
            end
        end,
    })
    end,

it might help with fixing the underlying issue or just be added to a readme

khris190 avatar Apr 26 '24 22:04 khris190

Use the latest commit, I've fixed it.

Civitasv avatar May 03 '24 07:05 Civitasv

It seems that the behavior has now changed, when the plugin is initialized, the *cmake-tools* buffer appears. It looks like the current fix broke the commit https://github.com/Civitasv/cmake-tools.nvim/commit/a4cd0b3a2c8a166a54b36bc00579954426748959

k0l350v avatar May 03 '24 08:05 k0l350v

Yes, do you know how to find the buffer whose buflisted is false?

Civitasv avatar May 03 '24 08:05 Civitasv

It should disappear now.

Civitasv avatar May 03 '24 08:05 Civitasv

I updated to the latest commit, the buffer no longer displays in bufferline but the original problem with lazy still remains

k0l350v avatar May 03 '24 08:05 k0l350v

Weird, are you sure that you have updated to the latest commit? Cause I previously had this problem, but now it disappears.

Civitasv avatar May 03 '24 08:05 Civitasv

Yes, it doesn't reproduce on the attached repro, but it still reproduces on my configuration, I'll check now

k0l350v avatar May 03 '24 08:05 k0l350v

It seems that the problem now occurs not during initialization but when trying to write something into it. Attaching the error log

CMakeBuild Error executing Lua callback: .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: Vim:Error executing Lua callback: ...e/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/scratch.lua:17: Expected Lua number
stack traceback:
	[C]: in function 'nvim_buf_set_lines'
	...e/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/scratch.lua:17: in function 'append'
	...are/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/utils.lua:237: in function <...are/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/utils.lua:220>
	[C]: in function 'cmd'
	.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>
stack traceback:
	[C]: in function 'cmd'
	.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>

k0l350v avatar May 03 '24 08:05 k0l350v

Check the latest commit.

Civitasv avatar May 03 '24 09:05 Civitasv

The issue has been resolved and is no longer occurring. Thank you very much!

k0l350v avatar May 03 '24 09:05 k0l350v