ahmedkhalf / project.nvim

The superior project management solution for neovim.
Apache License 2.0
1.29k stars 119 forks source link

Projects won't show up when being lazily loaded #123

Open glyh opened 1 year ago

glyh commented 1 year ago

If I run project.nvim lazily, it won't show any projects registered the first time.

  { 'ahmedkhalf/project.nvim',
    -- lazy = false,
    config = function()
      require("project_nvim").setup{
        patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json", "project.clj" },
      }
    end
  },

It's clear that it can be bring up by telescope. ![Uploading image.png…]()

towry commented 12 months ago

Before run vim.cmd('Telescope projects'), run vim.cmd('Lazy load project_nvim') first.

Or:

 require('lazy').load({ plugins = {  'project_nvim' } })
 vim.schedule(function() 
   vim.cmd('Telescope projects')
 end)
glyh commented 12 months ago

Before run vim.cmd('Telescope projects'), run vim.cmd('Lazy load project_nvim') first.

Or:

 require('lazy').load({ plugins = {  'project_nvim' } })
 vim.schedule(function() 
   vim.cmd('Telescope projects')
 end)

I still run into the same issue.

towry commented 12 months ago

Paste your code.

0x0013 commented 11 months ago

I have the same issue. I tried different lazy loading functions. Most would always open an empty telescope window on first load, without any projects, but would work every time after that. When wrapping it in vim.schedule(), it sometimes shows projects on first try, sometimes not. Seems to be more likely to load the first time if I am slower with my keypresses, but that might be a coincidence. The line require('lazy').load({ plugins = { 'project_nvim' } }) doesn't seem to make a difference for me.

  {
    "ahmedkhalf/project.nvim",
    keys = {
      { '<leader>hp',
        function()
          require('lazy').load({ plugins = { 'project_nvim' } })
          vim.schedule(function()
            vim.cmd('Telescope projects')
          end)
        end
      }
    },
    config = function()
      require("project_nvim").setup {}
      require('telescope').load_extension('projects')
    end,
    dependencies = {
      'nvim-telescope/telescope.nvim'
    }
  },

Could it be due to this (from readme):

Asynchronous file io so it will not slow down vim when reading the history file on startup.

pbnj commented 9 months ago

Here is a minimal, working Lazy config for Telescope + Project.nvim:

{
  "https://github.com/nvim-telescope/telescope.nvim",
  branch = "0.1.x",
  dependencies = {
    "https://github.com/nvim-lua/plenary.nvim",
    {
      "https://github.com/ahmedkhalf/project.nvim",
      config = function()
        require("project_nvim").setup({})
      end,
    },
    {
      "https://github.com/nvim-telescope/telescope-fzf-native.nvim",
      build = "make",
      cond = function()
        return vim.fn.executable("make") == 1
      end,
    },
  },
  config = function()
    pcall(require("telescope").load_extension, "fzf")
    pcall(require("telescope").load_extension, "projects")

    vim.keymap.set(
      "n",
      "<leader>fp",
      function() vim.cmd([[Telescope projects]]) end,
      { noremap = true }
    )

}
9mm commented 9 months ago

@pbnj its easy to get it working, the problem is lazy loading it. I also have the same problem, its a blank window the first time, and only works every time after.

Here is project.nvim:

return {
  'ahmedkhalf/project.nvim',
  dependencies = {
    'nvim-telescope/telescope.nvim',
  },
  config = function()
    require('project_nvim').setup({
      detection_methods = { 'pattern' },
      patterns = { '.git' },
    })
    require('telescope').load_extension('projects')
  end,
  keys = {
    {
      '<Leader>p',
      function() require('telescope').extensions.projects.projects() end,
      desc = 'Switch project',
    }
  },
}

here is the relevant part of telescope plugin:

return {
  'nvim-telescope/telescope.nvim',
  dependencies = {
    'nvim-lua/plenary.nvim',
    'nvim-telescope/telescope-ui-select.nvim',
  },
  config = function()
...
  end,
  cmd = {
    'Telescope',
  },

So lazy.nvim is triggered when the Telescope command is called, and for some reason vim.cmd('Telescope projects') as well as require('telescope').extensions.projects.projects() still cause the same issues

9mm commented 9 months ago

Note that adding event = 'VeryLazy' added after the 'ahmedkhalf/project.nvim', does work, but then that loads the entire telescope and all associated code there which is hefty code to load at boot when every single telescope plugin is triggered from a hotkey

NotNullBool commented 9 months ago

I'm also having the same issue sadly

lesad commented 8 months ago

The same also happens to me.

konosubakonoakua commented 8 months ago

not fixed yet, project.nvim keeps showing nothing

Song-Tianxiang commented 7 months ago

hello, you guys. I found this work for me

        keys = {
            {
                "<leader>fp",
                vim.schedule_wrap(function()
                    require("telescope").extensions.projects.projects({})
                end),
            },
        },

so project.nvim with trigger on keys.

Quitlox commented 5 months ago

The problem is that the plugin reads the file containing the history asynchronously when it's setup is ran. So when the plugin is lazy loaded, the Telescope picker opens before the history is read.

I haven't been able to dive in long enough to find a solution.

Do we require the asynchronous file reading? I can't imagine reading the history file takes a noticeable amount of time. It'd be simpler to read the history synchronous upon opening the picker.

alexgorbatchev commented 3 days ago

Using vim.schedule_wrap solved the problem for me