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

fix: prioritize user config for theme-loader on windows (#1213) #1214

Merged
merged 1 commit into from
Mar 21, 2024

Conversation

daephx
Copy link
Contributor

@daephx daephx commented Mar 19, 2024

No description provided.

@shadmansaleh shadmansaleh merged commit b5e8bb6 into nvim-lualine:master Mar 21, 2024
5 checks passed
@daephx
Copy link
Contributor Author

daephx commented Mar 21, 2024

@shadmansaleh Man I even referenced the commit in my issue and didn't notice lualine_require just duplicates the same logic... Should I patch that one too? I've never used the custom require function so I idk in what circumstances it will have the same problem.

Edit2:
At first I was uncertain but after some testing it seems this very well should be fixed, as it blocks the ability to load some user extensions.

table.sort(paths, function(a, b)
return vim.startswith(a, user_config_path) or not vim.startswith(b, user_config_path)
end)

Edit:
I don't know if it even matters for this function.
The code around it uses vim.api.nvim_get_runtime_file(pattern_path, false) and checks if the number of paths in the table is greater than 0. But the all=false parameter would only return the first match anyway. So either I'm misunderstanding the docs or it seems there's just never anything to sort! 😆

function vim.api.nvim_get_runtime_file(name: string, all: boolean) -> string[]
...
Parameters: ~
  • {name}  pattern of files to search for
  • {all}   whether to return all matches or only the first

pattern_path = table.concat { 'lua/', module:gsub('%.', '/'), '.lua' }
local paths = vim.api.nvim_get_runtime_file(pattern_path, false)
if #paths <= 0 then
pattern_path = table.concat { 'lua/', module:gsub('%.', '/'), '/init.lua' }
paths = vim.api.nvim_get_runtime_file(pattern_path, false)
end
if #paths > 0 then
-- put entries from user config path in front
local user_config_path = vim.fn.stdpath('config')
table.sort(paths, function(a, b)
return vim.startswith(a, user_config_path) or not vim.startswith(b, user_config_path)
end)
local mod_result = dofile(paths[1])
package.loaded[module] = mod_result
return mod_result
end
return require(module)

daephx added a commit to daephx/lualine.nvim that referenced this pull request Mar 21, 2024
Fixes the second part of: nvim-lualine#1213

The same logic fixed in (nvim-lualine#1214) is duplicated in the lualine_require
module, which appears to be used internally for loading things like
extensions.

On windows, user defined extensions that overwrite the builtin similarly
cannot be loaded due to the same string matching issue. In addition, the
number of queried runtime files is always less-than or equal to 1 due to
the `all` parameter for `nvim_get_runtime_file` being set to false.
Making it impossible to sort the list of files and prioritize ones
within the users config path `vim.fn.stdpath("config")`.
shadmansaleh pushed a commit that referenced this pull request Aug 12, 2024
Fixes the second part of: #1213

The same logic fixed in (#1214) is duplicated in the lualine_require
module, which appears to be used internally for loading things like
extensions.

On windows, user defined extensions that overwrite the builtin similarly
cannot be loaded due to the same string matching issue. In addition, the
number of queried runtime files is always less-than or equal to 1 due to
the `all` parameter for `nvim_get_runtime_file` being set to false.
Making it impossible to sort the list of files and prioritize ones
within the users config path `vim.fn.stdpath("config")`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants