Skip to content

Commit

Permalink
fix: add tree-sitter parsers to the runtimepath asap (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Oct 17, 2024
1 parent f62638c commit 752cecf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lua/rocks/adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,28 @@ function adapter.init_site_symlink_sync(rock)
end

--- Loop over the installed rocks and create symlinks in site/pack/luarocks/opt,
--- so that rtp paths like 'autoload' and 'color' are available before rocks.nvim
--- so that colorschemes are available before rocks.nvim
--- has initialised.
local function init_site_symlinks_async()
local state = require("rocks.state")
for _, rock in pairs(state.installed_rocks()) do
init_site_symlink_async(rock)
-- Since we're invoking this in the :h load-plugins phase of the startup sequence,
-- this packadd! call won't result in any scripts being sourced.
nio.scheduler()
local ok, err = pcall(vim.cmd.packadd, { rock.name, bang = true })
if not ok then
log.error(err)
end
end
vim
.iter(state.installed_rocks())
---@param rock Rock
:filter(function(_, rock)
return not vim.startswith(rock.name, "tree-sitter-")
end)
---@param rock Rock
:each(function(_, rock)
init_site_symlink_async(rock)
-- Make autoload scripts available
-- Since we're invoking this in the :h load-plugins phase of the startup sequence,
-- this packadd! call won't result in any scripts being sourced.
nio.scheduler()
local ok, err = pcall(vim.cmd.packadd, { rock.name, bang = true })
if not ok then
log.error(err)
end
end)
end

--- Initialise/validate runtimepath symlinks for tree-sitter parsers and health checks
Expand Down
4 changes: 4 additions & 0 deletions plugin/rocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ nio.run(function()
adapter.init()
end)

-- Make sure all tree-sitter parsers are on the rtp as soon as possible
local rocks_tree = vim.fs.joinpath(config.rocks_path, "lib", "luarocks", "rocks-5.1")
vim.opt.runtimepath:append(vim.fs.joinpath(rocks_tree, "tree-sitter-*", "*"))

--- We don't want to run this async, to ensure proper initialisation order
local user_rocks = require("rocks.api.hooks").run_preload_hooks(config.get_user_rocks())
require("rocks.runtime").source_start_plugins(user_rocks)
Expand Down

0 comments on commit 752cecf

Please sign in to comment.