From 7557d90c05b2566b43dd65819a0467fd29832622 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Fri, 1 Apr 2022 21:07:51 -0700 Subject: [PATCH] wrap 'filetype detect' in pcall to prevent TS errors (#377) --- lua/fzf-lua/previewer/builtin.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/fzf-lua/previewer/builtin.lua b/lua/fzf-lua/previewer/builtin.lua index 2e89fc5..e3e518c 100644 --- a/lua/fzf-lua/previewer/builtin.lua +++ b/lua/fzf-lua/previewer/builtin.lua @@ -542,9 +542,14 @@ function Previewer.buffer_or_file:do_syntax(entry) pcall(api.nvim_buf_set_name, bufnr, tempname) end -- nvim_buf_call has less side-effects than window switch - api.nvim_buf_call(bufnr, function() + local ok, _ = pcall(api.nvim_buf_call, bufnr, function() vim.cmd('filetype detect') end) + if not ok then + utils.warn(("syntax highlighting failed for filetype '%s', ") + :format(entry.path and path.extension(entry.path) or "") .. + "open the file and run ':filetype detect' for more info.") + end end end end