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

nvim installation instructions? #37

Closed
hjwp opened this issue Feb 12, 2025 · 4 comments
Closed

nvim installation instructions? #37

hjwp opened this issue Feb 12, 2025 · 4 comments

Comments

@hjwp
Copy link

hjwp commented Feb 12, 2025

Hi! Thanks very much for sharing your hard work!

I'm keen to try this out in my nvim. I saw your (closed) PR trying to get this added to nvim-treesitter, so i tried to figure out what to do from that, and i've also looked up the treesitter docs on adding parsers and i'm hacking about trying to add your grammar to my nvim.

here's what i've got, in my init.lua:

    {
        "nvim-treesitter/nvim-treesitter",
        config = function()
            require("nvim-treesitter.configs").setup {
              -- my normal treesitter config here...
            }
            -- manually register 3rd-party asciidoc parser
            require("nvim-treesitter.parsers").get_parser_configs().asciidoc = {
                install_info = {
                    url = "https://github.com/cathaysia/tree-sitter-asciidoc",
                    files = {
                        "src/parser.c",
                        "src/scanner.c"
                    },
                    location = "tree-sitter-asciidoc",
                    branch = "master",
                    generate_requires_npm = false,
                    requires_generate_from_grammar = false,
                },
                maintainers = { "@cathaysia" }
            }
        end
    },

And then I had to run :TSInstall asciidoc, iirc.

Questions:

  1. does that look right to you?
  2. is putting this in the main treesitter config block a good idea? (i'm using Lazy.nvim)
  3. what about tree-sitter-asciidoc_inline, as opposed to tree-sitter-asciidoc (in the location= bit) - is that a separate parser of some kind? what is it for? do i need to configure it as well / separately?

And maybe the most important question:

  • how do i check whether it worked??

thanks once againnnnnn

@cathaysia
Copy link
Owner

How using this parser

Add the following lines in your nvim config:

local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
parser_config.asciidoc = {
    install_info = {
        url = 'https://github.com/cathaysia/tree-sitter-asciidoc.git',
        files = { 'tree-sitter-asciidoc/src/parser.c', 'tree-sitter-asciidoc/src/scanner.c' },
        branch = 'master',
        generate_requires_npm = false,
        requires_generate_from_grammar = false,
    },
}
parser_config.asciidoc_inline = {
    install_info = {
        url = 'https://github.com/cathaysia/tree-sitter-asciidoc.git',
        files = { 'tree-sitter-asciidoc_inline/src/parser.c', 'tree-sitter-asciidoc_inline/src/scanner.c' },
        branch = 'master',
        generate_requires_npm = false,
        requires_generate_from_grammar = false,
    },
}

    

Add the following line in your lazy.nvim config:

{
      'cathaysia/tree-sitter-asciidoc'
},

effect

install with adoc and adoc_inline and query:

Image

only install adoc:

Image

don't install adoc:

Image

how do i check whether it worked??

  1. check the parser is installed:

open nvim and run :InspectTree, then you will see:

Image

  1. check the highlight if works:

the color between only install adoc and don't install adoc is difference.

@cathaysia cathaysia pinned this issue Feb 13, 2025
@hjwp
Copy link
Author

hjwp commented Feb 18, 2025

IT WORKS IT WORKS!!!

oh wow it's beeeeauuuutiful, thank you 😍

@bonusnunc
Copy link
Contributor

Important info (I think): it seems that you have to reinstall the parser after treesitter is updated by Lazy.nvim; at least I had to do so. Doing so manually can be frustrating, but you can modify the build section from the treesitter config (using the project's suggested config file for Lazy.nvim) can do so automatically. It could be modified to look like this:

build = ":TSUpdate | TSInstall asciidoc asciidoc_inline query",

The | TSInstall asciidoc asciidoc_inline query part only adds the parser installation to the updating process, so it will do it for you. I executed this command from nvim's prompt and it seems to work, but if there's any problem next time treesitter updates (which it seems to do every 20 minutes) I'll remove this comment.

@hjwp hjwp mentioned this issue Feb 21, 2025
@bonusnunc
Copy link
Contributor

I just updated nvim-treesitter from within Lazy and the modification works; it (re)installed both asciidoc and asciidoc_inline automatically. It seems that there's no need to keep query in the command, as after the update the build trigger didn't try to install it. So the line would be:

build = ":TSUpdate | TSInstall asciidoc asciidoc_inline",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants