tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
411 stars 52 forks source link

How to install, verify extension in neovim ? #120

Closed aca closed 10 months ago

aca commented 11 months ago

Hi, I'm trying to install extension with neovim.

export EXTENSION_WIKI_LINK=1
export EXTENSION_TAGS=1
nvim -c 'TSInstallSync! markdown'

I don't see anything related to tags/wiki_link. Anyone successful with neovim?

MDeiml commented 11 months ago

I think this should work if you also do

nvim -c 'TSInstallSync! markdown_inline'

but I haven't tested that.

I'm sorry that the extension system in place right now is not super compatible with neovim. Some solutions are currently being discussed in https://github.com/nvim-treesitter/nvim-treesitter/issues/3076.

ALizarazoTellez commented 10 months ago

Hello, first of all, thank you for the effort you have put into this project.

I have executed the following commands, and still have no syntax highlighting in the tags:

export EXTENSION_WIKI_LINK=1
export EXTENSION_TAGS=1
export ALL_EXTENSIONS=1

nvim -c 'TSUninstall markdown markdown_inline'
nvim -c 'TSInstallSync! markdown markdown_inline'

If I put the cursor at the next position (of a tag):

#anytag
  ^

And execute:

:lua print(vim.inspect(vim.treesitter.get_captures_at_cursor(0)))

I get this:

{ "spell" }
MDeiml commented 10 months ago

The output you get is actually correct I think. This is because there is two different concepts in tree-sitter: nodes and captures.

The parser is responsible for generating the syntax tree consisting of nodes. You can then specify queries like in the highlights.scm file to extract interesting information from the synatx tree. The output of these queries are called captures (similar to captures in regexes if you are familiar). In the default configuration there are no queries referencing tags or wikilinks.

Try running :lua print(vim.inspect(vim.treesitter.get_node({ignore_injections = false}))) which gives you the node (not captures) under the cursor.

If you want tags or wiki links to be highlighted somehow then you need to add corresponding queries to the highlights.scm file for the markdown_inline grammar.

bliuchak commented 7 months ago

Hey there! I've tried to install both tags and wiki_link extensions via nvim commands provided (from this post).. but with no success. It's really sad that it so hard to enable these highly interesting features :(

MDeiml commented 7 months ago

Hi @bliuchak sorry you are having trouble with this. Sadly to the best of my knowledge there is still no good way to make configurable tree sitter parsers.

For me the most consistent way to compile with the extensions is the following. You could try to clone the repository and in its root folder run

ALL_EXTENSIONS=1 npm run build
npm test

All tests should pass if the extensions were complied successfully. You could then use these local versions with nvim-treesitter.