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: add tree-sitter parsers to the runtimepath asap #562

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Comment on lines +170 to +172
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion for another issue:
Perhaps we don't actually need this.
It could potentially lead to the subtle issues, because the packadd is delayed (it's async). Neovim only searches for colorschemes in pack/*/opt, but not autoload scripts or tree-sitter parsers, which is why I had added this.

But perhaps it's better for now not to support autoload scripts as dependencies. It's not really common in the lua ecosystem anyway.

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
Loading