Skip to content

Commit

Permalink
fix(staging): syntax highlighting for ambiguous, not loaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Aug 21, 2024
1 parent b20f1ca commit f0d105d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lua/tinygit/commands/staging/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ local function getFiletype(absPath)
local ft = vim.filetype.match { filename = vim.fs.basename(absPath) }
if ft then return ft end

-- In some cases, the filename alone is not unambiguous(like `.ts` files for
-- In some cases, the filename alone is not unambiguous (like `.ts` files for
-- typescript), so we need the actual buffer to determine the filetype.
local bufnr = vim.iter(vim.api.nvim_list_bufs())
:find(function(buf) return vim.api.nvim_buf_get_name(buf) == absPath end)
if not bufnr then return nil end
if bufnr then return vim.filetype.match { buf = bufnr } end

-- If there are changes in files that are not loaded as buffer, we have to
-- add file to a buffer to be able to determine the filetype from it.
bufnr = vim.fn.bufadd(absPath)
return vim.filetype.match { buf = bufnr }
end

Expand Down

0 comments on commit f0d105d

Please sign in to comment.