hhamud / tree-sitter-noir

Treesitter grammer and parser for the Noir Language
https://docs.rs/tree-sitter-noir/latest/tree_sitter_noir/
GNU General Public License v3.0
6 stars 1 forks source link

Highlighting doesn't work out of the box #3

Open Philogy opened 10 months ago

Philogy commented 10 months ago

Hey, I've opened an issue previously which you've kindly resolved with #2, the tree-sitter parser is now installed with no problems, however, there's two follow-up issues:

  1. .nr files aren't detected as "noir" files by neovim out-of-the-box, I'd recommend adding the tip "add vim.filetype.add({ extension = { nr = 'noir' } }) in your config to have noir detected
  2. More importantly I can't seem to get the highlighting to actually work, when I open up a .nr file it doesn't show any highlighting on its own, am I missing something (after I got Neovim to recognize .nr files as noir)? Here's my treesitter config file:
local status, ts = pcall(require, 'nvim-treesitter.configs')
if (not status) then print('no tree') return end

local parser_config = require 'nvim-treesitter.parsers'.get_parser_configs()

parser_config.noir = {
  install_info = {
    url = "https://github.com/hhamud/tree-sitter-noir", -- the url for this tree-sitter grammar
    files = { "src/parser.c", "src/scanner.c" },
    branch = "main",
  },
  filetype = "noir",
}

ts.setup {
  highlight = {
    enable = true
  },
  indent = {
    enable = true,
    disable = { "python" }
  },
  ensure_installed = {
    'javascript',
    'tsx',
    'json',
    'css',
    'toml',
    'solidity',
    'python',
    'beancount',
    'rust',
    'noir'
  }
}

Thanks again! 🙏

hhamud commented 10 months ago

I ended up missing this part. I assumed that nvim-treesitter would have been able to detect the queries from the package itself but turns out you would need to copy it over.

Thanks for the find on the filetype as well.

Note that neither :TSInstall nor :TSInstallFromGrammar copy query files from the grammar repository. If you want your installed grammar to be useful, you must manually add query files to your local nvim-treesitter installation. Note also that module functionality is only triggered if your language's filetype is correctly identified. If Neovim does not detect your language's filetype by default, you can use [Neovim's vim.filetype.add()](https://neovim.io/doc/user/lua.html#vim.filetype.add()) to add a custom detection rule.

If you use a git repository for your parser and want to use a specific version, you can set the revision key in the install_info table for you parser config.

Could you try copying over the queries from queries/highlights.scm in the tree-sitter-noir package and seeing what it outputs.