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: User runtime path doesn't have priority on Windows #1213

Open
2 tasks done
daephx opened this issue Mar 19, 2024 · 0 comments
Open
2 tasks done

Bug: User runtime path doesn't have priority on Windows #1213

daephx opened this issue Mar 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@daephx
Copy link
Contributor

daephx commented Mar 19, 2024

Self Checks

  • I'm using the latest lualine.
  • I didn't find the issue in existing issues or PRs.

Describe the issue

I adding a custom module to my user config lua/lualine/themes/<theme>.lua to modifying the colors used by lualine and my preferred theme. The changes worked without issue on my Linux host, but these settings where not applied to my Windows host after pulling over the changes.

It seems the logic added in this commit afb8bfb for prioritizing the users config directory when loading themes has some side effects with Neovim's default path structure on Windows.

-- put entries from user config path in front
local user_config_path = vim.fn.stdpath('config')
table.sort(files, function(a, b)
return vim.startswith(a, user_config_path) or not vim.startswith(b, user_config_path)
end)

I believe the culprit is the use of vim.startswith method to compare the path strings.
On Linux, this makes perfect sense as the paths are quite different:

Config: /home/<user>/.config/nvim
Data: /home/<user>/.local/share/nvim

But on Windows the default locations are as follows:

Config: C:\Users\<user>\AppData\Local\nvim
Data: C:\Users\<user>\AppData\Local\nvim-data

If it's not apparent as to why vim.startswith would see these directories as equivalent.
The function will only match up to a portion of the data path:

C:\Users\<user>\AppData\Local\nvim
C:\Users\<user>\AppData\Local\nvim-data

Resulting in the match being true for basically any plugin, not allowing the user config directory to take priority!

I replaced this with a simple string.match that leveraging the [sep]erator variable provided by the lualine_require module to ensure that the path string is matched to the appropriate directory, and I have not exerienced any issues with this change.

local lualine_require = require('lualine_require')
local sep = lualine_require.sep
-- ...
local user_config_path = vim.fn.stdpath('config')
table.sort(files, function(a, b)
  local pattern = table.concat { user_config_path, sep }
  return string.match(a, pattern) or not string.match(b, pattern)
end)

How to reproduce the problem

  1. Be on Windows
  2. Set your colorscheme to one that is compatible with lualine themes
  3. Create a module in the user config directory with the same folder namespace
    Example: /lua/lualine/themes/tokyonight.lua
  4. Take notice that none of your changes are applied when you reload your colorscheme.
    Despite the fact that using the require function on the new module will return a table with your custom settings.
@daephx daephx added the bug Something isn't working label Mar 19, 2024
daephx added a commit to daephx/lualine.nvim that referenced this issue Mar 19, 2024
daephx added a commit to daephx/lualine.nvim that referenced this issue Mar 19, 2024
daephx added a commit to daephx/lualine.nvim that referenced this issue 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")`.
@daephx daephx changed the title Bug: User runtime path doesn't have priority for themes on Windows Bug: User runtime path doesn't have priority on Windows Mar 21, 2024
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

1 participant