-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Update core/init.lua, Putting .../mason/bin/ at the beginning of vim.env.PATH #2031
Conversation
Putting `.../mason/bin/` in the beginning of `vim.env.PATH`
@siduck @TirtharajPramanik how do I prevent this from happening? The best I can do is get it to both prepend and append the path, but I cannot for the life of me figure out how to keep it from prepending it. The issue is that when I'm working with a virtual environment, I want the binaries from that virtual environment to take precedence, but it seems like this ensures that mason trumps them every time. |
@adamrp just delete the ones downloaded from mason? 🤔 |
@adamrp You could write a script that moves specified plugins from mason/bin to a backup location and brings them back Delete these lines in local config -- ~/.config/nvim/lua/core/init.lua
59| -- add binaries installed by mason.nvim to path
60| local is_windows = vim.loop.os_uname().sysname == "Windows_NT"
61| vim.env.PATH = vim.fn.stdpath "data" .. "/mason/bin" .. (is_windows and ";" or ":") .. vim.env.PATH Add mason/bin at the start of path in shell config file # ~/.bashrc
export PATH="$HOME/.local/share/nvim/mason/bin/:$PATH" I have tested this |
Please forgive me if my question is naive (I've used vim for a long time, but am new to neovim and nvchad), but why is this line in Having this line seems to break the "normal" flow where settings (including settings for plugins) sort of "cascade":
In this case, the Again, I'm kinda new 😅 Intuitively, I would think that So my suggestion for
For your use case @TirtharajPramanik, you could use a local plugins = {
{
"williamboman/mason.nvim",
opts = {
PATH="prepend", -- In my use case, I would use "append" here
ensure_installed = {
"rust-analyzer",
},
},
},
}
return plugins and combine it with a ---@type ChadrcConfig
local M = {}
M.plugins = "custom.plugins"
return M |
@adamrp Thanks for this great analysis. My configs-- ~/.config/nvim/lua/core/init.lua
61| vim.env.PATH = vim.env.PATH .. (is_windows and ";" or ":") .. vim.fn.stdpath "data" .. "/mason/bin" -- ~/.config/nvim/lua/custom/plugins.lua
local plugins = {
{
"williamboman/mason.nvim",
opts = { PATH = "prepend" }
}
}
return plugins Resulting Package locationsDeleting this line 61| vim.env.PATH = vim.env.PATH .. (is_windows and ";" or ":") .. vim.fn.stdpath "data" .. "/mason/bin" |
This -- mason.nvim/lua/mason/init.lua
function M.setup(config)
...
if settings.current.PATH == "prepend" then
vim.env.PATH = path.bin_prefix() .. platform.path_sep .. vim.env.PATH
elseif settings.current.PATH == "append" then
vim.env.PATH = vim.env.PATH .. platform.path_sep .. path.bin_prefix()
end
end This -- NvChad/lua/plugins/init.lua
default_plugins = {
{
"williamboman/mason.nvim",
config = function(_, opts)
...
require("mason").setup(opts)
end,
},
}
...
require("lazy").setup(default_plugins, config.lazy_nvim) According to config is executed when the plugin loads. thus, logic for conditional path positioning not set when nvim first opens.
@adamrp @siduck Is this behaviour desirable? Or should EditAs this doc suggests Lazy-loaded plugins are automatically loaded when their Lua modules are required calling
|
First of all, thank you @TirtharajPramanik for your attention, I appreciate your help! 🏅 I just got this working the way I want it to, so I'll share what I did here. FYI I also am using a fork of NvChad (relevant branch here), so I pushed the working version there (relevant commit here). In Summary:
-- add binaries installed by mason.nvim to path
local is_windows = vim.loop.os_uname().sysname == "Windows_NT"
vim.env.PATH = vim.fn.stdpath "data" .. "/mason/bin" .. (is_windows and ";" or ":") .. vim.env.PATH
{
"williamboman/mason.nvim",
lazy=false,
opts = {
PATH="append",
ensure_installed = {
"pyright",
"lua-language-server",
"mypy",
"flake8",
"cfn-lint",
"isort",
"black",
},
},
},
With this setup, the virtual environment's binaries will be preferred, but the mason binaries are used as a fallback. E.g.: When I'm editing a python file that's not part of a virtual environment:
Versus when I am in a virtual environment:
The key was to load mason "eagerly" (i.e., |
@adamrp please dont remove anything from default config, your nvchad will stop updating now. Just add whatever you want in the /custom/init.lua |
@siduck can you clarify --
I'm trying to understand if it makes sense to get that change into |
@adamrp nvchad updates wont work properly if you make changes outside custom dir. Does removing the mason stuff in custom init.lua work? |
@siduck I can test that out at some point today, but can you respond to if/why the specific PATH manipulation is needed in |
FWIW I do see #2162 which (I think) would also solve my problem, but doesn't satisfy my curiosity about why the PATH manipulation is a requirement 😆 |
because almost 99% of nvchad users download lsps from mason so obviously its download folder should be on path. I want you to check if you can fix this issue i.e append at the end of the path with custom/init.lua itself so we dont need that PR |
@siduck I will do that experiment, I'm just trying to understand if/why it doesn't work to change nvchad's default |
@TirtharajPramanik very true -- is it acceptable to eager-load it? See my draft PR here #2163 |
for you concern of having two config options for the same functionality, I have noticed when both options in i.e --- custom/chadrc.lua | --- plugins/configs/mason.lua
M.mason_path = "prepend" | PATH = "append" PATH = ...mason/bin : $PATH : ...mason/bin When any of them are |
@TirtharajPramanik interesting -- I can't speak to the behavior when it's in |
|
I think taking the PATH manipulation out of core/init.lua -- and instead relying on FWIW I think one issue with doing this sort of thing in chadrc is that it is (by default in core/init.lua) reloaded every time a buffer is written, so doing path manipulations there sounds tricky at best, and I think it makes more sense to do this path manipulation exactly once (when Is there something fundamentally wrong with what's in the draft PR #2163? Maybe eager-loading |
@siduck it's not that different except that we (if I may include myself) are doing a string manipulation on PATH in |
just edit the path in custom/init.lua then |
Although I'm perplexed by the decision to deliberately ignore the user's plugin settings, I got the behavior I wanted by doing the following: -- custom/plugins.lua
local plugins = {
{
"williamboman/mason.nvim",
lazy=false,
opts = {
PATH="append",
ensure_installed = {
"pyright",
"lua-language-server",
"mypy",
"flake8",
"cfn-lint",
"isort",
"black",
},
},
},
} -- custom/chadrc.lua
local M = {}
M.plugins = "custom.plugins"
return M -- custom/init.lua
-- remove all occurrences of mason/bin from the path (it will be loaded by the plugin's setup function)
vim.env.PATH = string.gsub(vim.env.PATH, ".-/mason/bin:?", "") Thank you both sincerely for your time and attention @siduck @TirtharajPramanik |
@TirtharajPramanik i think the above solution should work and we dont need a separate option for this. @adamrp i havent read the whole convos here, but why are you trying to remove mason paths from your env? 🤔 |
Thank you for considering the feedback. To ensure a thorough evaluation before proceeding, I will keep this pull request open for one more day. During this time, I will conduct additional research to check for any existing occurrences of similar problems or alternative solutions online. |
@siduck I use
So on a practical level, that's why I needed to make the change. On a philosophical level, a few points:
|
Putting
.../mason/bin/
in the beginning ofvim.env.PATH
There is an issue with
rust_analyzer
, a mason plugin, not loading properly on macos ventura, neovim setup with NvChad default configs..../mason/bin/
is added at end ofvim.env.PATH
, causing a brokenrust-analyzer
from ~/.cargo/bin being loaded first.I propose this change to search mason/bin first for plugins