1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Fix firenvim and LeaderF build issues

In lazy.nvim, the `build` parameter accept value in different format.
If the value is
1. a string and starts with `:`, it will be treated as vim command
2. a string and starts without `:`, it will be treated as shell command
3. a function. Lazy.nvim will run this function

I compared closely between case 1 and case 3. In case 1, when lazy.nvim
runs the viml command, the runtimepath is already populated with the
current plugin we are trying to build.
However in case 3, the runtimepath is not populated with the plugin
path, which means that any command you run by this plugin is not
available.

So I did it in a hacky way to add the plugin path to runtimepath
manually, and source it manually using `:runtime` command. The `:
runtime` command is needed because in the init process, adding the
plugin path to runtimepath does not ensure that the script under this
plugin is sourced immediately. So if we want to use the command/function
immediately, we need to source it manually, see also https://github.com/neovim/neovim/issues/29957.
This commit is contained in:
jdhao 2024-08-02 17:28:28 +02:00
parent bbb8545403
commit beec97c086

View File

@ -1,6 +1,7 @@
local utils = require("utils")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
local plugin_dir = vim.fn.stdpath("data") .. "/lazy"
local lazypath = plugin_dir .. "/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
vim.fn.system {
@ -15,12 +16,6 @@ end
vim.opt.rtp:prepend(lazypath)
-- check if firenvim is active
-- macOS will reset the PATH when firenvim starts a nvim process, causing the PATH variable to change unexpectedly.
-- Here we are trying to get the correct PATH and use it for firenvim.
-- See also https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md#make-sure-firenvims-path-is-the-same-as-neovims
local path_env = vim.env.PATH
local prologue = string.format('export PATH="%s"', path_env)
local firenvim_not_active = function()
return not vim.g.started_by_firenvim
end
@ -114,8 +109,12 @@ local plugin_specs = {
"Yggdroot/LeaderF",
cmd = "Leaderf",
build = function()
local leaderf_path = plugin_dir .. "/LeaderF"
vim.opt.runtimepath:append(leaderf_path)
vim.cmd("runtime! plugin/leaderf.vim")
if not vim.g.is_win then
vim.cmd(":LeaderfInstallCExtension")
vim.cmd("LeaderfInstallCExtension")
end
end,
},
@ -430,7 +429,20 @@ local plugin_specs = {
end,
-- it seems that we can only call the firenvim function directly.
-- Using vim.fn or vim.cmd to call this function will fail.
build = string.format(":call firenvim#install(0, '%s')", prologue),
build = function()
local firenvim_path = plugin_dir .. "/firenvim"
vim.opt.runtimepath:append(firenvim_path)
vim.cmd("runtime! firenvim.vim")
-- macOS will reset the PATH when firenvim starts a nvim process, causing the PATH variable to change unexpectedly.
-- Here we are trying to get the correct PATH and use it for firenvim.
-- See also https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md#make-sure-firenvims-path-is-the-same-as-neovims
local path_env = vim.env.PATH
local prologue = string.format('export PATH="%s"', path_env)
-- local prologue = "echo"
local cmd_str = string.format(":call firenvim#install(0, '%s')", prologue)
vim.cmd(cmd_str)
end
},
-- Debugger plugin
{