withastro / language-tools

Language tools for Astro
MIT License
267 stars 52 forks source link

🐛 BUG: The Astro syntax parser freezes Neovim when writing an opening curly brace #855

Closed ThomasGysemans closed 5 months ago

ThomasGysemans commented 5 months ago

Describe the Bug

Hello, I'm not sure if I'm in the right place since this bug is very weird and very specific. Basically, I'm using Neovim to write Astro and when writing an opening curly brace at a very specific position in the file, then Neovim freezes and I have no other choice but to force quit.

Here is an example of when the freeze happens in a file named "SomeComponent.astro":

---
// If I write an opening curly brace in here, it's totally fine:

const name = { name: "Thomas" };
--- 

<!-- If I write an opening curly brace here, as the very first character of this line,
then Neovim freezes. -->

<!-- However, if written before a closing HTML tag, it works fine. -->
<h1>Hello {name.name}</h1>

I disabled the astro_language_server (the LSP) from Mason and it didn't change anything. My assumption is that the problem is caused by the Tree sitter specifically in an .astro file. Probably an infinite loop in the parsing process. Unfortunately I do not know how to give you more information.

Steps to Reproduce

  1. Create an empty Astro project and open it with Neovim while having the treesitter plugin.
  2. Open a file ending with .astro and go to the first line after the --- part:
---

---

<!-- Here -->

<h1>Hello</h1>

Try writing an opening curly brace where it is said "Here" in the above example, without the comment. For me, it freezes neovim.

Notes:

Here is some of my Neovim plugins that may be relevant (with Packer):

vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function(use)
    use 'wbthomason/packer.nvim'
    use {
        'nvim-telescope/telescope.nvim', tag = '0.1.6',
        requires = { { 'nvim-lua/plenary.nvim' } }
    }

    use('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' })
    use('nvim-treesitter/playground')

    use {
        'VonHeikemen/lsp-zero.nvim',
        branch = 'v3.x',
        requires = {
            { 'williamboman/mason.nvim' },
            { 'williamboman/mason-lspconfig.nvim' },

            -- LSP Support
            { 'neovim/nvim-lspconfig' },
            -- Autocompletion
            { 'hrsh7th/nvim-cmp' },
            { 'hrsh7th/cmp-buffer' },
            { 'hrsh7th/cmp-path' },
            { 'saadparwaiz1/cmp_luasnip' },
            { 'hrsh7th/cmp-nvim-lsp' },
            { 'hrsh7th/cmp-nvim-lua' },

            -- Snippets
            { 'rafamadriz/friendly-snippets' },
            { 'L3MON4D3/LuaSnip' },
        }
    }

    use('jose-elias-alvarez/null-ls.nvim')
    use('MunifTanjim/prettier.nvim')

    use('nvim-lua/plenary.nvim')
end)
Princesseuh commented 5 months ago

We do not maintain the tree sitter parser. I would suggest reporting your issue there.

https://github.com/virchau13/tree-sitter-astro