rmagatti / auto-session

A small automated session manager for Neovim
MIT License
1.33k stars 46 forks source link

[BUG] when I run checkhealth -> attempt to call field 'debug' (a nil value) #383

Closed 1Jo1 closed 2 months ago

1Jo1 commented 2 months ago

Description

According to the README, I used the following configuration:

use {
  'rmagatti/auto-session',
  config = function()
    require("auto-session").setup {
      suppressed_dirs = { "~/", "~/Projects", "~/Downloads", "/"},
    }
  end
}

when I run :checkhealth I'm getting this error

auto-session: require("auto-session.health").check()

vim options ~
- OK vim.o.sessionoptions

Lazy.nvim settings ~
- Lazy.nvim not loaded

Config ~
- OK 
  {}

General Info ~
- ERROR Failed to run healthcheck for "auto-session" plugin. Exception:
  ...pack/packer/start/auto-session/lua/auto-session/init.lua:333: attempt to call field 'debug' (a nil value)

Expected Behavior I expect :checkhealth to pass without any issues.

Checkhealth Output See the section above.

Environment Details

Additional Context Even after setting root_dir, which should not be nil, it still returns a nil value.

cameronr commented 2 months ago

Hmm, that is quite strange. Looking at the code, I'm struggling to see how root_dir is ending up nil. I just tested a default packer install and it works as expected (init.lua):

local ensure_packer = function()
  local fn = vim.fn
  local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
  if fn.empty(fn.glob(install_path)) > 0 then
    fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
    vim.cmd([[packadd packer.nvim]])
    return true
  end
  return false
end

local packer_bootstrap = ensure_packer()

return require("packer").startup(function(use)
  use("wbthomason/packer.nvim")
  -- My plugins here
  -- use 'foo1/bar1.nvim'
  -- use 'foo2/bar2.nvim'

  use({
    "rmagatti/auto-session",
    config = function()
      require("auto-session").setup({
        suppressed_dirs = { "~/", "~/Projects", "~/Downloads", "/" },
      })
    end,
  })

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require("packer").sync()
  end
end)

Can you share more of your packer config to see if there's something else going on?

cameronr commented 2 months ago

I looked at it a bit more closely and I can reproduce the behavior you're seeing if auto-session's setup function is never called (that results in Lib never being initialized which is the error you're seeing in init.lua:333).

So there must be something going on with your packer config where it's not actually calling the config function you have in your auto-session use block. I don't know packer very well but if you share your packer config, I'm happy to take a look.

1Jo1 commented 2 months ago

thats my packer.lua file

vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function(use)
    -- Packer can manage itself
    use 'wbthomason/packer.nvim'

    use({ 'rose-pine/neovim', as = 'rose-pine' })

    use {
        'nvim-telescope/telescope.nvim', branch = '0.1.x',
        requires = { { 'nvim-lua/plenary.nvim' } }
    }

    use('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' })
    use "ThePrimeagen/harpoon"
    use "mbbill/undotree"
    use "tpope/vim-fugitive"

    use {
        'VonHeikemen/lsp-zero.nvim',
        branch = 'v3.x',
        requires = {
            --- Uncomment these if you want to manage LSP servers from neovim
            -- {'williamboman/mason.nvim'},
            -- {'williamboman/mason-lspconfig.nvim'},

            -- LSP Support
            { 'neovim/nvim-lspconfig' },
            -- Autocompletion
            { 'hrsh7th/nvim-cmp' },
            { 'hrsh7th/cmp-nvim-lsp' },
            { 'L3MON4D3/LuaSnip' },
        }
    }

    use {
        'rmagatti/auto-session',
        config = function()
            require("auto-session").setup {
                suppressed_dirs = { "~/", "~/Projects", "~/Downloads", "/" },
            }
        end
    }

    use "numToStr/FTerm.nvim"
    use {
        "williamboman/mason.nvim",
        "williamboman/mason-lspconfig.nvim",
        "neovim/nvim-lspconfig",
    }

    use {
        'j-hui/fidget.nvim',
        tag = 'legacy',
        config = function()
            require("fidget").setup {
                -- options
            }
        end,
    }

    use {
        "nvim-telescope/telescope-live-grep-args.nvim"
    }

    use({
        "epwalsh/obsidian.nvim",
        tag = "*", -- recommended, use latest release instead of latest commit
        requires = {
            -- Required.
            "nvim-lua/plenary.nvim",

            -- see below for full list of optional dependencies 👇
        },
        config = function()
            require("obsidian").setup({
                workspaces = {
                    {
                        name = "jo",
                        path = "~/dev/notes/jo",
                    },
                },
                log_level = vim.log.levels.INFO,
                -- see below for full list of options 👇
            })
        end,
    })

    use "mfussenegger/nvim-jdtls"
    use "folke/tokyonight.nvim"
    use "nvim-lualine/lualine.nvim"
    use('MunifTanjim/prettier.nvim')
    use "lambdalisue/suda.vim"
    use "numToStr/Comment.nvim"

    use 'rhysd/git-messenger.vim'

    use {
        'nvim-tree/nvim-tree.lua',
        requires = {
            'nvim-tree/nvim-web-devicons', -- optional, for file icons
        },
    }
    use 'yamatsum/nvim-cursorline'
    use({
        "folke/trouble.nvim",
        config = function()
            require("trouble").setup {
                icons = false,
                -- your configuration comes here
                -- or leave it empty to use the default settings
                -- refer to the configuration section below
            }
        end
    })

    use 'navarasu/onedark.nvim'

    use 'rhysd/git-messenger.vim'

    use 'tpope/vim-fugitive'

    use 'sainnhe/edge'

    use "mfussenegger/nvim-dap"

    use "rcarriga/nvim-dap-ui"
    use { "catppuccin/nvim", as = "catppuccin" }
    use({
        "iamcco/markdown-preview.nvim",
        run = "cd app && npm install",
        setup = function()
            vim.g.mkdp_filetypes = {
                "markdown" }
        end,
        ft = { "markdown" },
    })
end)

not really familiar with packer plugin, maybe I messed up my packer config...I'm gonna try to call setup function in the init

1Jo1 commented 2 months ago

I looked at it a bit more closely and I can reproduce the behavior you're seeing if auto-session's setup function is never called (that results in Lib never being initialized which is the error you're seeing in init.lua:333).

So there must be something going on with your packer config where it's not actually calling the config function you have in your auto-session use block. I don't know packer very well but if you share your packer config, I'm happy to take a look.

I ended up putting the setup function in init.lua, and it works perfectly. You were right—it’s an issue with Packer. For some reason, Packer isn’t calling the config function. Maybe it’s a sign to switch to lazy loading, haha

1Jo1 commented 2 months ago

I just switched to lazy package manager haha so much fast hehe, auto session it works perfectly :)