Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
tigion opened this issue Aug 8, 2024 · 5 comments
Closed
4 tasks done

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

tigion opened this issue Aug 8, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@tigion
Copy link
Contributor

tigion commented Aug 8, 2024

Did you check docs and existing issues?

  • I have read all the lazy.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of lazy.nvim
  • I have searched the existing issues of plugins related to this issue

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 tigion added the bug Something isn't working label Aug 8, 2024
@tigion
Copy link
Contributor Author

tigion commented Aug 9, 2024

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
Copy link
Contributor

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
Copy link
Contributor Author

tigion commented Aug 9, 2024

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

I think I found it:

  • If dev.path is a string, Lazy.nvim itself appends the plugin name to the path.
  • If dev.path is a function, Lazy.nvim don't add the plugin name to the path and so the path is invalid.
---@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
Copy link
Contributor

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
Copy link
Contributor Author

tigion commented Aug 9, 2024

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.

@tigion tigion closed this as completed Aug 9, 2024
folke pushed a commit that referenced this issue Aug 31, 2024
## Description

In the issue (#1707) I was confused by the description of `dev.path`. I
thought functions must also return the general directory for local
plugins, but it must be the plugin directory.

## Related Issue(s)

#1707
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants