ldelossa / nvim-ide

A full featured IDE layer for Neovim. Heavily inspired by VSCode.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Commands aren't registered properly when lazy loading with packer.nvim

mrjones2014 opened this issue · comments

commented

The only lazy-loading mechanism that works for nvim-ide is event = 'VimEnter' which sorta defeats the purpose of lazy-loading.

Here's my current config:

return {
  -- localplugin just returns the local path to the cloned repo
  -- if it exists on disk
  localplugin('ldelossa/nvim-ide'),
  event = 'VimEnter',
  config = function()
    local explorer = require('ide.components.explorer')
    local outline = require('ide.components.outline')
    local bufferlist = require('ide.components.bufferlist')
    local changes = require('ide.components.changes')
    local commits = require('ide.components.commits')
    require('ide').setup({
      components = {
        [explorer.Name] = {
          list_directories_first = true,
          show_file_permissions = false,
          keymaps = {
            hide = '<NOP>',
          },
        },
        [outline.Name] = {
          keymaps = {
            hide = '<NOP>',
          },
        },
      },
      panel_groups = {
        explorer = { bufferlist.Name, explorer.Name, outline.Name },
        git = { changes.Name, commits.Name },
      },
      workspaces = {
        auto_close = false,
      },
    })
  end,
}

However if I change event = 'VimEnter' to cmd = 'Workspace', the command doesn't get registered properly and I'm unable to open the panels.

commented

If I add vim.notify('this ran!') to the config function, I do get the notification when I run :Workspace, so the config definitely is running. It's just not properly setting up the commands.

commented

I tracked it down to here, I think the workspace is not being initialized before the command is run for some reason:

    local function ws_handler(args)
        local log = logger.new("workspaces", "WorkspaceController.ws_handler")
        log.info("handling Workspace command")

        local cur_tab = vim.api.nvim_get_current_tabpage()
        local ws = workspace_registry.get_workspace(cur_tab)
        if ws == nil then
            return
        end

Instead of returning, can we just initialize a new workspace?

commented

Hmm, that doesn't seem to be the root problem. If I load it on event = 'User DashboardLeave' which I fire when I leave my dashboard buffer, that doesn't work either.

It seems like it's just not being initialized properly when lazy-loaded.

commented

Interestingly, if I then run lua require('ide.logger.logger').open_log(), it then does have a workspace assigned to the new tab that gets created.

commented

Here's the culprit, I think. We need to check if we've already seen VimEnter by checking vim.v.vim_did_enter

        init_autocmd =  vim.api.nvim_create_autocmd({ "VimEnter" }, {
            callback = function()
                -- do not assign if we are git tool.
                local buf_name = vim.api.nvim_buf_get_name(0)
                if vim.fn.match(buf_name, ".git/*") >= 0 then
                    return
                end
                -- do not assign if we are a man reader.
                if vim.fn.match(buf_name, "man://*") >= 0 then
                    return
                end

                for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
                    assign_ws(tab)
                end
                restore()
                vim.api.nvim_del_autocmd(init_autocmd)
            end
        })