Skip to content

Commit 20448f4

Browse files
committed
fix: stay compatible with old nvim-versions.
they don't have vim.list_contains.
1 parent 03c607c commit 20448f4

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lua/luasnip/extras/filetype_functions.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ local function fts_from_ts_lang(lang)
44
if vim.treesitter.language and vim.treesitter.language.get_filetypes then
55
fts = vim.treesitter.language.get_filetypes(lang)
66
end
7-
-- Keep lang as part of the result, for backward compatibility
8-
if not vim.list_contains(fts, lang) then
9-
table.insert(fts, lang)
10-
end
7+
-- Keep lang as part of the result, for backward compatibility.
8+
-- If lang is already part of fts, one entry will be removed by deduplicate
9+
-- in get_snippet_filetypes().
10+
table.insert(fts, lang)
1111
return fts
1212
end
1313

tests/integration/snippet_basics_spec.lua

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("snippets_basic", function()
88

99
before_each(function()
1010
ls_helpers.clear()
11-
ls_helpers.session_setup_luasnip()
11+
ls_helpers.session_setup_luasnip({setup_parsers=true})
1212

1313
screen = Screen.new(50, 3)
1414
screen:attach()
@@ -1597,4 +1597,29 @@ describe("snippets_basic", function()
15971597
assert.are.same(true, exec_lua("return enter_snode_m1"))
15981598
assert.are.same(true, exec_lua("return enter_snode_via_parent"))
15991599
end)
1600+
1601+
it("Correct filetype is recognized via treesitter.", function()
1602+
exec_lua([=[
1603+
ls.setup({
1604+
ft_func = require("luasnip.extras.filetype_functions").from_cursor_pos
1605+
})
1606+
ls.add_snippets("lua", {
1607+
s("asdf", t[[print("qwer")]])
1608+
})
1609+
]=])
1610+
exec("set ft=lua")
1611+
feed([[ilocal function a() end<Esc>hhhi]])
1612+
screen:expect({
1613+
grid = [[
1614+
local function a() ^ end |
1615+
{0:~ }|
1616+
{2:-- INSERT --} |]]})
1617+
feed([[asdf]])
1618+
exec_lua("ls.expand()")
1619+
screen:expect({
1620+
grid = [[
1621+
local function a() print("qwer")^ end |
1622+
{0:~ }|
1623+
{2:-- INSERT --} |]]})
1624+
end)
16001625
end)

0 commit comments

Comments
 (0)