mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(treesitter): do not error on empty filetype
Ignore instead
This commit is contained in:
parent
4f75960660
commit
adfa9de8eb
@ -60,16 +60,6 @@ function M.add(lang, opts)
|
|||||||
filetype = { filetype, { 'string', 'table' }, true },
|
filetype = { filetype, { 'string', 'table' }, true },
|
||||||
})
|
})
|
||||||
|
|
||||||
if filetype == '' then
|
|
||||||
error(string.format("'%s' is not a valid filetype", filetype))
|
|
||||||
elseif type(filetype) == 'table' then
|
|
||||||
for _, f in ipairs(filetype) do
|
|
||||||
if f == '' then
|
|
||||||
error(string.format("'%s' is not a valid filetype", filetype))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
M.register(lang, filetype or lang)
|
M.register(lang, filetype or lang)
|
||||||
|
|
||||||
if vim._ts_has_language(lang) then
|
if vim._ts_has_language(lang) then
|
||||||
@ -109,7 +99,9 @@ function M.register(lang, filetype)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for _, f in ipairs(filetypes) do
|
for _, f in ipairs(filetypes) do
|
||||||
ft_to_lang[f] = lang
|
if f ~= '' then
|
||||||
|
ft_to_lang[f] = lang
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -36,11 +36,6 @@ describe('treesitter language API', function()
|
|||||||
pcall_err(exec_lua, 'vim.treesitter.add("/foo/")'))
|
pcall_err(exec_lua, 'vim.treesitter.add("/foo/")'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('shows error for invalid filetype', function()
|
|
||||||
eq('.../language.lua:0: \'\' is not a valid filetype',
|
|
||||||
pcall_err(exec_lua, [[vim.treesitter.add('foo', { filetype = '' })]]))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('inspects language', function()
|
it('inspects language', function()
|
||||||
local keys, fields, symbols = unpack(exec_lua([[
|
local keys, fields, symbols = unpack(exec_lua([[
|
||||||
local lang = vim.treesitter.inspect_language('c')
|
local lang = vim.treesitter.inspect_language('c')
|
||||||
|
Loading…
Reference in New Issue
Block a user