Replies: 3 comments
-
| 
         Doing more testing, I noticed there's an additional wrinkle: before  vim.api.nvim_create_autocmd({ 'Filetype' }, {
  callback = function(event)
    local ignored_fts = {
      'snacks_dashboard',
      'snacks_input',
      'prompt', -- bt: snacks_picker_input
    }
    if vim.bo[event.buf].bt == 'nofile' then return end
    if vim.tbl_contains(ignored_fts, event.match) then return end
    local ok, result = pcall(vim.treesitter.start, event.buf)
    vim.notify('ok: ' .. vim.inspect(ok) .. ' result: ' .. vim.inspect(result))
    local nvim_treesitter = require('nvim-treesitter')
    ok, result = pcall(vim.treesitter.start, event.buf)
    vim.notify('nvim-treesitter: ok: ' .. vim.inspect(ok) .. ' result: ' .. vim.inspect(result))
  end,
})For a ft that's not installed (i was testing with  13:52   INFO ok: false result: '.../neovim/0.11.3/share/nvim/runtime/lua/vim/treesitter.lua:431:
              Parser could not be created for buffer 1 and language "sshconfig"'
13:52   INFO nvim-treesitter: ok: true result: nilSo how can I tell if a parser is actually installed or not? Or maybe I should just always be calling install?  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         After a bit more noodling, this is what I have and it seems to work vim.api.nvim_create_autocmd({ 'Filetype' }, {
  callback = function(event)
    local ignored_fts = {
      'snacks_dashboard',
      'snacks_input',
      'prompt', -- bt: snacks_picker_input
    }
    if vim.tbl_contains(ignored_fts, event.match) then return end
    -- make sure nvim-treesitter is loaded
    local nvim_treesitter = require('nvim-treesitter')
    local ft = vim.bo[event.buf].ft
    local lang = vim.treesitter.language.get_lang(ft)
    nvim_treesitter.install({ lang }):await(function(err)
      if err then
        vim.notify('Treesitter install error for ft: ' .. ft .. ' err: ' .. err)
        return
      end
      pcall(vim.treesitter.start, event.buf)
      vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
      vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
    end)
  end,
})
If there's a better way to see if a parser is installed vs just always calling install, please let me know  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         Whoops, just noticed I posted this in textobjects  | 
  
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've transitioned from master to main and I'm trying to restore the auto-start/auto-install behavior from master. I have this autocmd:
It works except that the file isn't reparsed when parser is installed (doing
:eor re-setting the filetype will trigger reparsing). It seems like the call to install starts the tasks asynchronously and returns before they're complete. Is there a way to tell when install is done (e.g. maybe a way to pass in a callback or a way to wait for the task to complete)?Beta Was this translation helpful? Give feedback.
All reactions