virchau13 / tree-sitter-astro

Tree-sitter grammar for the Astro web framework
MIT License
98 stars 9 forks source link

neovim freezes when writing an opening curly brace #29

Closed ThomasGysemans closed 7 months ago

ThomasGysemans commented 7 months ago

Describe the Bug

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)
virchau13 commented 7 months ago

I can't reproduce the issue. However, this sounds very similar to an issue I have already fixed in commit https://github.com/virchau13/tree-sitter-astro/commit/1da287da32e6a433e952793e4b91786165257e94.

Maybe your nvim-treesitter plugin is out of date? Try running :PackerUpdate and then run :TSUpdate.

ThomasGysemans commented 7 months ago

Well strangely enough I've just tried on an other computer and I cannot reproduce the issue either. I guess I must have messed up somewhere in the configuration of my previous computer. If someday I get the problem again I will tell you so but as of now I fear there is nothing more to be said on this subject. I'm sorry for the inconvenience.

virchau13 commented 7 months ago

No problem. Fixing bugs by doing nothing is always nice :)