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

Orgmode fails to install tree-sitter grammar with rocks.nvim #804

Closed
bodby opened this issue Aug 25, 2024 · 4 comments
Closed

Orgmode fails to install tree-sitter grammar with rocks.nvim #804

bodby opened this issue Aug 25, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@bodby
Copy link

bodby commented Aug 25, 2024

Describe the bug

Orgmode logs installing tree-sitter grammar before returning an error:
orgmode-log.log
Everything works just fine too; Tree-sitter still works, and shows the right highlights with :Inspect. The only problem is the fact that this plugin shouldn't need to install the TS parser if it's already there.

Steps to reproduce

  1. Open Nvim using rocks.nvim with the dev version of nvim-orgmode from luarocks.
  2. Nvim freezes for a few seconds before returning the error.
  3. The plugin works normally.

Expected behavior

Either it installs properly or doesn't even need to install in the first place; I assume installing the orgmode TS parser from luarocks would work the same way, and it does seem to do so.

Emacs functionality

No response

Minimal init.lua

-- Using rocks-config.nvim in /lua/bodby/plugins/orgmode.lua
require("orgmode").setup()

Screenshots and recordings

No response

OS / Distro

Gentoo Linux

Neovim version/commit

v0.10.1

Additional context

No response

@bodby bodby added the bug Something isn't working label Aug 25, 2024
@kristijanhusak
Copy link
Member

There's probably a race condition in there.
Could you provide a minimal init that I could just use as init.lua? I'm not sure how rocks-config.nvim works.

Also, when you open up neovim with org loaded, what does this command return:

:lua= vim.api.nvim_get_runtime_file('parser/org.so', true)

I'm curious if it installed the rocks dependency first or not.

@bodby
Copy link
Author

bodby commented Aug 26, 2024

I'm outside right now so I can't check the command output, but here's the init.lua from the rocks.nvim page:

do
    -- Specifies where to install/use rocks.nvim
    local install_location = vim.fs.joinpath(vim.fn.stdpath("data"), "rocks")

    -- Set up configuration options related to rocks.nvim (recommended to leave as default)
    local rocks_config = {
        rocks_path = vim.fs.normalize(install_location),
    }

    vim.g.rocks_nvim = rocks_config

    -- Configure the package path (so that plugin code can be found)
    local luarocks_path = {
        vim.fs.joinpath(rocks_config.rocks_path, "share", "lua", "5.1", "?.lua"),
        vim.fs.joinpath(rocks_config.rocks_path, "share", "lua", "5.1", "?", "init.lua"),
    }
    package.path = package.path .. ";" .. table.concat(luarocks_path, ";")

    -- Configure the C path (so that e.g. tree-sitter parsers can be found)
    local luarocks_cpath = {
        vim.fs.joinpath(rocks_config.rocks_path, "lib", "lua", "5.1", "?.so"),
        vim.fs.joinpath(rocks_config.rocks_path, "lib64", "lua", "5.1", "?.so"),
    }
    package.cpath = package.cpath .. ";" .. table.concat(luarocks_cpath, ";")

    -- Load all installed plugins, including rocks.nvim itself
    vim.opt.runtimepath:append(vim.fs.joinpath(rocks_config.rocks_path, "lib", "luarocks", "rocks-5.1", "rocks.nvim", "*"))
end

-- If rocks.nvim is not installed then install it!
if not pcall(require, "rocks") then
    local rocks_location = vim.fs.joinpath(vim.fn.stdpath("cache"), "rocks.nvim")

    if not vim.uv.fs_stat(rocks_location) then
        -- Pull down rocks.nvim
        vim.fn.system({
            "git",
            "clone",
            "--filter=blob:none",
            "https://github.com/nvim-neorocks/rocks.nvim",
            rocks_location,
        })
    end

    -- If the clone was successful then source the bootstrapping script
    assert(vim.v.shell_error == 0, "rocks.nvim installation failed. Try exiting and re-entering Neovim!")

    vim.cmd.source(vim.fs.joinpath(rocks_location, "bootstrap.lua"))

    vim.fn.delete(rocks_location, "rf")
end

There is another file you have to modify to install orgmode though. It's in the same directory as the init file (.config/nvim/Rocks.toml)

# ...
[plugins]
orgmode = "scm" # or "dev"
"rocks-config.nvim" = "2.2.0"

[config]
auto_setup = true
# ...

@bodby
Copy link
Author

bodby commented Aug 26, 2024

This is the output of :lua= vim.api.nvim_get_runtime_file('parser/org.so', true):

{ "/home/bodby/.local/share/nvim/site/pack/luarocks/opt/tree-sitter-orgmode/parser/org.so" }

@bodby
Copy link
Author

bodby commented Aug 29, 2024

So after some messing around it turns out that the org parser initially doesn't get detected which is why orgmode tries to install it. Running vim.treesitter.language.add("org") doesn't return an error but if I add it to any file called at startup it does. Seems to be an issue with rocks.nvim and not orgmode.

Fixed by adding vim.opt.runtimepath:append(vim.fs.joinpath(vim.fn.stdpath("data"), "rocks", "lib", "luarocks", "rocks-5.1", "tree-sitter-*", "*")) in init.lua

@bodby bodby closed this as completed Aug 29, 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

2 participants