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

Treesitter issue in neovim with Lazy #31

Open
ishaanparlikar opened this issue Aug 2, 2024 · 16 comments
Open

Treesitter issue in neovim with Lazy #31

ishaanparlikar opened this issue Aug 2, 2024 · 16 comments

Comments

@ishaanparlikar
Copy link

          Hi @virchau13 @mrs4ndman 

Is it working on the latest neovim and treesitter builds? Unfortunatly I was unable to get it to work. I am using Kickstart Neovim

My TS Config

*:TSConfigInfo*

{
  auto_install = true,
  ensure_installed = { "bash", "astro", "c", "html", "lua", "markdown", "vim", "vimdoc" },
  ignore_install = {},
  modules = {
    auto_install = true,
    highlight = {
      additional_vim_regex_highlighting = { "ruby" },
      custom_captures = {},
      disable = {},
      enable = true,
      loaded = true,
      module_path = "nvim-treesitter.highlight"
    },
    incremental_selection = {
      disable = {},
      enable = false,
      keymaps = {
        init_selection = "gnn",
        node_decremental = "grm",
        node_incremental = "grn",
        scope_incremental = "grc"
      },
      module_path = "nvim-treesitter.incremental_selection"
    },
    indent = {
      disable = { "ruby" },
      enable = true,
      loaded = true,
      module_path = "nvim-treesitter.indent"
    }
  },
  sync_install = false
}

Originally posted by @ishaanparlikar in #16 (comment)

@zachbharris
Copy link

I am experiencing the same issue. My config is based off of Kickstart.nvim and my treesitter config looks like the following

  { -- Highlight, edit, and navigate code
    'nvim-treesitter/nvim-treesitter',
    build = ':TSUpdate',
    main = 'nvim-treesitter.configs', -- Sets main module to use for opts
    -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
    opts = {
      ensure_installed = {
        'bash',
        'c',
        'diff',
        'html',
        'lua',
        'luadoc',
        'markdown',
        'markdown_inline',
        'query',
        'vim',
        'vimdoc',
        'javascript',
        'astro',
      },
      -- Autoinstall languages that are not installed
      auto_install = true,
      highlight = {
        enable = true,
        -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
        --  If you are experiencing weird indenting issues, add the language to
        --  the list of additional_vim_regex_highlighting and disabled languages for indent.
        additional_vim_regex_highlighting = { 'ruby', 'astro' },
      },
      indent = { enable = true, disable = { 'ruby' } },
    },
    -- There are additional nvim-treesitter modules that you can use to interact
    -- with nvim-treesitter. You should go explore a few and see what interests you:
    --
    --    - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
    --    - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
    --    - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
  },

I've tried everything, including converting the implementation into a separate require, but I can not get the syntax highlighting to work. If I manually invoke :TSBufEnable highlight in an .astro file it works like I expect.

@zachbharris
Copy link

Turns out it was an issue on my end. A trailing comma in my tsconfig.json was the culprit...

@ishaanparlikar
Copy link
Author

@zachbharris how did you debug this?
I have to try with my config now.

@zachbharris
Copy link

neo-tree was actually proving an error dump that I used gpt to disect that lead me to a trailing comma error. It originally was pointing at astro.vim but I found a few posts around tsconfig having a trailing error causing an error with astro.

@ishaanparlikar
Copy link
Author

I bashed my head for so long. I gave up using neovim for astro projects.

@zachbharris
Copy link

I'm right there with you. I almost gave up and was going to use Cursor for my astro project, but found the needle in the haystack issue.

@justynhunter
Copy link

Turns out it was an issue on my end. A trailing comma in my tsconfig.json was the culprit...

Thank you, I was beating my head on the wall. Everything was working in one project, but not in another and this was the problem.

@Dovias
Copy link

Dovias commented Oct 2, 2024

Turns out it was an issue on my end. A trailing comma in my tsconfig.json was the culprit...

Can confirm, weirdly for me this fixes it also. Too bad it tries to point to some kind of hard to decipher error in this case. Thank you for investigating this!

@dca123
Copy link

dca123 commented Oct 14, 2024

Phew this fixed my config issue too, I'm kinda new to using treesitter, is there a way I could have debugged this than just lucking out on the solution ?

@frixaco
Copy link

frixaco commented Oct 27, 2024

@zachbharris THANK YOU, man. I almost gave up on using Neovim for Astro.
(based pfp btw)

@danielelegbe
Copy link

@zachbharris Thank you!! I was almost going to switch to back to VSCode for Astro

@AmeerArsala
Copy link

For anyone else who may be having this issue, I also fixed it by removing the comments in the tsconfig.json. So I guess the extension uses a very basic json parser

@virchau13
Copy link
Owner

virchau13 commented Dec 9, 2024

Sorry for leaving this issue unaddressed for so long, I've been busy recently.

This is incredibly confusing because this Tree-sitter parser doesn't parse tsconfig.json at all. (Tree-sitter is entirely self-contained; it does not look at any files except the buffer you're currently editing.) So it seems to me that this issue is probably caused by something else, but I can't think of what that would be. (I certainly can't reproduce the issue).

For anyone who has this issue, can you try the following in an environment with an invalid tsconfig.json?

  1. Open an Astro file with the issue.
  2. Check the filetype by :set ft?. It should output filetype=astro. (If it doesn't, then you need to configure neovim to automatically assign the astro filetype to .astro files).
  3. Check in :checkhealth that the astro entry under nvim-treesitter has five ticks: it should look something like astro ✓ ✓ ✓ ✓ ✓. (If it doesn't, then you need to reinstall the parser and/or your nvim-treesitter install is broken.)
  4. Run :lua vim.treesitter.inspect_tree() and check that a window appears with syntax tree information about the Astro file. (If instead you get an error, e.g. "No parser available for the given buffer", then you need to reconfigure nvim-treesitter.)

(The only thing I can think of here is that this might be LSP syntax highlighting breaking instead of Tree-sitter highlighting breaking, which would imply it isn't a tree-sitter-astro issue, and is fixable by configuring nvim-treesitter to use tree-sitter-astro.)

@kyubums
Copy link

kyubums commented Jan 9, 2025

  • filetype set and recognized correctly
  • health check ok image
  • inspect tree image

I don't know much about treesitter, but frontmatter_js_block might means It catches javascript syntax but not highlighted?

@kyubums
Copy link

kyubums commented Jan 12, 2025

I solved this issue with install typescript treesitter grammer.

:TSInstall typescript might the solution. kickstart-nvim does not ensure install for typescript.

@virchau13
Copy link
Owner

Yep, that's part of the troubleshooting guide in the README. Can anyone reproduce the issue even after following the troubleshooting guide?

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

10 participants