Skip to content

Commit

Permalink
Prevent tree-sitter error on buffers that don't yet have a filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
dansalvato authored and theHamsta committed Mar 3, 2024
1 parent d4542ac commit 6dc308b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lua/nvim-dap-virtual-text/virtual_text.lua
Expand Up @@ -88,9 +88,16 @@ function M.set_virtual_text(stackframe, options, clear)
local buf = vim.uri_to_bufnr(vim.uri_from_fname(stackframe.source.path))
local parser
local lang
local ft = vim.bo[buf].ft
if ft == '' then
ft = vim.filetype.match { buf = buf }
if ft == '' then
return
end
end
if vim.treesitter.get_parser and vim.treesitter.language and vim.treesitter.language.get_lang then
lang = vim.treesitter.language.get_lang(vim.bo[buf].ft)
parser = vim.treesitter.get_parser(buf)
lang = vim.treesitter.language.get_lang(ft)
parser = vim.treesitter.get_parser(buf, lang)
else
local require_ok, parsers = pcall(require, 'nvim-treesitter.parsers')
if not require_ok then
Expand Down

0 comments on commit 6dc308b

Please sign in to comment.