Skip to content

Commit

Permalink
fix(format): always pass a valid buffer to ftdetect even just the cur…
Browse files Browse the repository at this point in the history
…rent onw
  • Loading branch information
folke committed May 30, 2024
1 parent a6ddc71 commit b01b11e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lua/trouble/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ function M:get_ft(buf)
end
local ft = Cache.ft[self.filename]
if ft == nil then
ft = vim.filetype.match({ filename = self.filename, buf = buf })
-- HACK: make sure we always pass a valid buf,
-- otherwise some detectors will fail hard (like ts)
ft = vim.filetype.match({ filename = self.filename, buf = buf or 0 })
Cache.ft[self.filename] = ft or false -- cache misses too
end
return ft
end

function M:get_lang()
local ft = self:get_ft()
function M:get_lang(buf)
local ft = self:get_ft(buf)
return ft and ft ~= "" and vim.treesitter.language.get_lang(ft) or nil
end

Expand Down

0 comments on commit b01b11e

Please sign in to comment.