Skip to content

Commit

Permalink
fix(preview): pass valid buffer so that ftdetect works for ts files. …
Browse files Browse the repository at this point in the history
…See #435
  • Loading branch information
folke committed May 30, 2024
1 parent a665272 commit 65f2430
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lua/trouble/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function M.add_id(items, fields)
end

---@return string?
function M:get_ft()
function M:get_ft(buf)
if self.buf and vim.api.nvim_buf_is_loaded(self.buf) then
return vim.bo[self.buf].filetype
end
Expand All @@ -69,7 +69,7 @@ function M:get_ft()
end
local ft = Cache.ft[self.filename]
if ft == nil then
ft = vim.filetype.match({ filename = self.filename })
ft = vim.filetype.match({ filename = self.filename, buf = buf })
Cache.ft[self.filename] = ft or false -- cache misses too
end
return ft
Expand Down
2 changes: 1 addition & 1 deletion lua/trouble/view/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function M.create(item)
return
end
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
local ft = item:get_ft()
local ft = item:get_ft(buf)
if ft then
local lang = vim.treesitter.language.get_lang(ft)
if not pcall(vim.treesitter.start, buf, lang) then
Expand Down

0 comments on commit 65f2430

Please sign in to comment.