virchau13 / tree-sitter-astro

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

Query @attribute not working #19

Closed devgioele closed 1 year ago

devgioele commented 1 year ago

Thank you for the work done to integrate astro!

I tried to make the selection of attributes inside the html part of an astro file work, but couldn't. I expect daa to delete the attribute under the cursor. It works in tsx and html files, but not in astro files. This is the config I have:

  require('nvim-treesitter.configs').setup {
    -- Add languages to be installed here that you want installed for treesitter
    ensure_installed = { "vim", "vimdoc", "bash", "c", "lua", "vim", "vimdoc", "query", "javascript", "typescript",
      "html", "css", "go",
      "astro", "svelte", "tsx", "astro" },
    sync_install = false,
    auto_install = true,
    highlight = {
      enable = true,
      disable = function(lang, buf)
        local max_filesize = 100 * 1024 -- 100 KB
        local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
        if ok and stats and stats.size > max_filesize then
          return true
        end
      end,
    },
    indent = { enable = true },
    context_commentstring = {
      enable = true,
    },
    textobjects = {
      select = {
        enable = true,
        lookahead = true,
        keymaps = {
          ['if'] = '@function.inner',
          ['af'] = '@function.outer',
          ['ia'] = '@attribute.inner',
          ['aa'] = '@attribute.outer',  -- this enables the feature for `tsx` and `html` files, why doesn't it work for `astro` files?
          ['ic'] = '@class.inner',
          ['ac'] = '@class.outer',
        },
      }
    }
  }

A verified the health of nvim-treesitter and checked the filetype to be correct

virchau13 commented 1 year ago

It doesn't work because Astro's queries weren't specified in the nvim-treesitter-textobjects repository (which I didn't even know existed until today; this looks pretty cool.) The above PR adds the queries for Astro's textobjects, which fixes this issue.

devgioele commented 1 year ago

Awesome

virchau13 commented 1 year ago

Fixed by the linked PR.