folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.32k stars 344 forks source link

bug: The option dev.path no longer works with a function #1707

Closed tigion closed 1 month ago

tigion commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.1

Operating system/version

macOS 14.6.1

Describe the bug

The option for the path to local plugins no longer works with a function.

A simple example:

  dev = {
    -- path = get_local_dev_path, -- Don't work
    -- path = function() return '~/projects/neovim' end, -- Don't work
    path = '~/projects/neovim', -- Works
  },

I have a function that searches in different directories and returns the first hit, but this no longer works:

---Returns the first path from a set of paths in which
---the local dev version of the plugin is located.
---@param plugin LazyPlugin
---@return string
local function get_local_dev_path(plugin)
  local search_paths = {
    '~/projects/neovim', -- default path, if not found in other paths
    '~/projects/neovim/fork',
    '~/projects/private/neovim',
    '~/projects/private/neovim/fork',
  }
  for _, path in ipairs(search_paths) do
    if vim.fn.isdirectory(vim.fn.expand(path) .. '/' .. plugin.name) == 1 then return path end
  end
  return search_paths[1]
end
tigion commented 1 month ago

I did some more testing. If I use the function directly, it works:

...

---@param plugin LazyPlugin
---@return string
local function get_path1(plugin)
  return '~/projects/neovim'
end

---@return string
local function get_path2()
  return '~/projects/neovim'
end

---@type LazyConfig
local opts = {
  dev = {
    path = get_path1, -- Don't work (path get a function)
    path = get_path2(), -- Works (path get a string)
    path = '~/projects/neovim', -- Works (path get a string)
  },
}

require('lazy').setup(spec, opts)
max397574 commented 1 month ago

well the get_path2() isn't actually a function but a string. The function gets evaluated when setting the value and lazy doesn't even know nor care where it came from

tigion commented 1 month ago

Yes, it was a step in my debugging process. :)

I think I found it:

---@param plugin LazyPlugin
---@return string
local function get_path(plugin)
  return '~/projects/neovim/' .. plugin.name -- <-- I now must add the plugin name here
end

---@type LazyConfig
local opts = {
  dev = {
    path = get_path, -- Now works (path get a function)
    path = '~/projects/neovim', -- Works (path get a string)
  },
}
max397574 commented 1 month ago

are you sure this worked in the past? because by looking at the commit history it seems like this didn't change recently

perhaps you could open a pull request to clarify the docs on this and close this issue

tigion commented 1 month ago

are you sure this worked in the past?

That's a good question. I should have asked myself that earlier. 🫣

After researching the history of the repositories, I think it has always been like this and the description is simply misleading.

A pull request to clarify the docs is a good Idea.