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

toggle_view treesitter error #128

Closed
yujinyuz opened this issue Aug 13, 2024 · 6 comments · Fixed by #130
Closed

toggle_view treesitter error #128

yujinyuz opened this issue Aug 13, 2024 · 6 comments · Fixed by #130
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@yujinyuz
Copy link
Contributor

yujinyuz commented Aug 13, 2024

I'm getting this error when running toggle_view()

This happens when switching from Body to Header view

Error executing vim.schedule lua callback: ...table/share/nvim/runtime/lua/vim/treesitter/language.lua:107: no parser for 'pl
aintext' language, see :help treesitter-parsers
stack traceback:
        [C]: in function 'error'
        ...table/share/nvim/runtime/lua/vim/treesitter/language.lua:107: in function 'add'
        ...e/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:111: in function 'new'
        .../neovim/stable/share/nvim/runtime/lua/vim/treesitter.lua:41: in function '_create_parser'
        .../neovim/stable/share/nvim/runtime/lua/vim/treesitter.lua:108: in function 'get_parser'
        ...m/stable/share/nvim/runtime/lua/vim/treesitter/_fold.lua:117: in function 'compute_folds_levels'
        ...m/stable/share/nvim/runtime/lua/vim/treesitter/_fold.lua:380: in function 'fn'
        ...m/stable/share/nvim/runtime/lua/vim/treesitter/_fold.lua:293: in function <...m/stable/share/nvim/runtime/lua/vim/
treesitter/_fold.lua:289>

Here's my config if it helps

    'mistweaverco/kulala.nvim',
    ft = 'http',
    opts = {
      default_view = 'headers_body',
      winbar = true,
      contenttypes = {
        ['text/plain'] = {
          formatter = function(body)
            return body
          end,
        },
      },
    },
    keys = {
      {
        '<CR>',
        function()
          require('kulala').run()
        end,
        ft = 'http',
      },
      {
        '<leader>r',
        function()
          require('kulala').run()
        end,
        ft = 'http',
      },
      {
        '<leader>v',
        function()
          require('kulala').toggle_view()
        end,
        ft = 'http',
      },
    },
@yujinyuz
Copy link
Contributor Author

It was a bug in my config..

@yujinyuz yujinyuz reopened this Aug 13, 2024
@yujinyuz
Copy link
Contributor Author

My config contains

vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()'

Removing that resolves this error.

@gorillamoe gorillamoe self-assigned this Aug 13, 2024
@gorillamoe gorillamoe added bug Something isn't working question Further information is requested labels Aug 13, 2024
@gorillamoe
Copy link
Member

gorillamoe commented Aug 13, 2024

Can you look if this fixes your issue? https://github.com/neovim/neovim/issues/23964#issuecomment-1584411926\

/edit:

Tried that, didn't work, even if it's supposed to work 🙈

gorillamoe added a commit that referenced this issue Aug 14, 2024
closes: #128.

This also sets the ft to the correct "text" one,
as fallback value for when we don't know the ft.
gorillamoe added a commit that referenced this issue Aug 14, 2024
closes: #128.

This also sets the ft to the correct "text" one,
as fallback value for when we don't know the ft.
@gorillamoe
Copy link
Member

Okay, you should change your config part to something like this:

local function enable_foldexpr()
  vim.opt_local.foldexpr = "v:lua.vim.treesitter.foldexpr()"
  vim.opt_local.foldmethod = "expr"
end

vim.api.nvim_create_autocmd("FileType", {
  callback = function(ev)
    local has_treesitter = pcall(function()
      vim.treesitter.get_parser(ev.buf)
    end)
    if has_treesitter then
      enable_foldexpr()
    end
  end,
})

This makes sure, that only on buffers with a treesitter parser attached to it your config will get applied.

Then v3.0.1 should work for you :)

@yujinyuz
Copy link
Contributor Author

yujinyuz commented Aug 14, 2024

Thanks @gorillamoe works for me

EDIT:

I don't think that the method you provided is necessary since the foldmethod and foldexpr is local to the window. So if there are 2 buffers in the window 1 supports TS while the other one does not, it would still set the foldexpr and foldmethod.

But the v3.0.1 works just fine so everything is good

@wenjinnn
Copy link
Contributor

wenjinnn commented Sep 29, 2024

Still have some issue here. the fold level of the result buffer view didn't calculate correctly. so zc zo not work here.

update:
opened a PR to fix that, tested on my machine.

wenjinnn added a commit to wenjinnn/kulala.nvim that referenced this issue Sep 29, 2024
When setup
``` lua
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
```
the fold level per lines not getting correct result, this means that
`zc` `zo` will not work in result buffer. this commit fix it.
Related mistweaverco#128
gorillamoe pushed a commit that referenced this issue Sep 29, 2024
When setup
``` lua
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
```
the fold level per lines not getting correct result, this means that
`zc` `zo` will not work in result buffer. this commit fix it.
Related #128
gorillamoe pushed a commit to rcasia/kulala.nvim that referenced this issue Oct 7, 2024
When setup
``` lua
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
```
the fold level per lines not getting correct result, this means that
`zc` `zo` will not work in result buffer. this commit fix it.
Related mistweaverco#128
iamxiaojianzheng pushed a commit to iamxiaojianzheng/kulala.nvim that referenced this issue Oct 24, 2024
When setup
``` lua
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
```
the fold level per lines not getting correct result, this means that
`zc` `zo` will not work in result buffer. this commit fix it.
Related mistweaverco#128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants