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

Understand treesitter filetypes #1174

Closed
LnLcFlx opened this issue May 16, 2024 · 5 comments
Closed

Understand treesitter filetypes #1174

LnLcFlx opened this issue May 16, 2024 · 5 comments

Comments

@LnLcFlx
Copy link

LnLcFlx commented May 16, 2024

Treesitter uses latex as the filetype name instead of tex like native vim.
In #823 similarly one had to ls.filetype_extend("markdown_inline", {"markdown"}) in order to make

ft_func = require("luasnip.extras.filetype_functions").from_cursor_pos

work.
Is it possible/useful to make Luasnip understand the treesitter names such that I don't manually need to filetype_extend all treesitter names to native ones?

@leiserfg
Copy link
Contributor

The fts of a parser are available on vim.treesitter.language.get_filetypes(), that should do it.

@leiserfg
Copy link
Contributor

Can you try with this pr ?
#1175

@LnLcFlx
Copy link
Author

LnLcFlx commented May 17, 2024

Works!

@LnLcFlx
Copy link
Author

LnLcFlx commented May 17, 2024

Now it does not work anymore!
I pulled the latest master and when I do

ft_func = require('luasnip.extras.filetype_functions').from_pos_or_filetype

I get

Error detected while processing TextChangedI Autocommands for "*":
Error executing lua callback: ...m/lazy/LuaSnip/lua/luasnip/extras/filetype_functions.lua:8: attempt to call field 'list_contains' (a nil value)
stack traceback:
        ...m/lazy/LuaSnip/lua/luasnip/extras/filetype_functions.lua:8: in function 'from_cursor_pos'
        ...m/lazy/LuaSnip/lua/luasnip/extras/filetype_functions.lua:42: in function 'ft_func'
        ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/util.lua:364: in function 'get_snippet_filetypes'
        ...cal/share/nvim/lazy/cmp_luasnip/lua/cmp_luasnip/init.lua:67: in function 'complete'
        ...lcflx/.local/share/nvim/lazy/nvim-cmp/lua/cmp/source.lua:326: in function 'complete'
        ...lnlcflx/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:299: in function 'complete'
        ...lnlcflx/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:169: in function 'callback'
        ...lnlcflx/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:229: in function 'autoindent'
        ...lnlcflx/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:161: in function 'on_change'
        ...lnlcflx/.local/share/nvim/lazy/nvim-cmp/lua/cmp/init.lua:340: in function 'callback'
        ...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/autocmd.lua:49: in function 'emit'
        ...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/autocmd.lua:23: in function <...local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/autocmd.lua:22>

every time I try to expand a snippet.

EDIT: from_cursor_pos instead of from_pos_or_filetype still works.

@L3MON4D3
Copy link
Owner

Dang, I'm surprised that 1. vim.list_contains was not available before 0.10, and 2. that from_pos_or_filetype does not throw the error, it just calls from_cursor_pos.
Anyway, the fix should be up now, thanks for pointing it out so quick :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants