| 1 |
-- MIT license, see LICENSE for more details. |
| 2 |
-- Extension for avante.nvim |
| 3 |
|
| 4 |
local M = {} |
| 5 |
|
| 6 |
local function ft_info() |
| 7 |
local ft = vim.opt_local.filetype:get() |
| 8 |
if ft == 'Avante' then |
| 9 |
return 'Output' |
| 10 |
elseif ft == 'AvanteInput' then |
| 11 |
return require('lualine.utils.mode').get_mode() |
| 12 |
elseif ft == 'AvanteSelectedCode' then |
| 13 |
local max_shown = vim.api.nvim_win_get_height(0) |
| 14 |
local avante_ok, avante_config = pcall(require, 'avante.config') |
| 15 |
if avante_ok and avante_config.windows.sidebar_header.enabled then |
| 16 |
max_shown = max_shown - 1 |
| 17 |
end |
| 18 |
local num_lines = vim.api.nvim_buf_line_count(0) |
| 19 |
return string.format('Code Fragment: %s%d lines', max_shown < num_lines and (max_shown .. '/') or '', num_lines) |
| 20 |
elseif ft == 'AvanteSelectedFiles' then |
| 21 |
return 'Total Files: ' .. vim.api.nvim_buf_line_count(0) |
| 22 |
elseif ft == 'AvanteTodos' then |
| 23 |
local todos = vim.api.nvim_buf_get_lines(0, 0, -1, false) |
| 24 |
local completed = vim.iter(todos):fold(0, function(counter, todo) |
| 25 |
if todo:sub(1, 3) == '[x]' then |
| 26 |
counter = counter + 1 |
| 27 |
end |
| 28 |
return counter |
| 29 |
end) |
| 30 |
return string.format('Todos: %d/%d', completed, #todos) |
| 31 |
end |
| 32 |
end |
| 33 |
|
| 34 |
M.sections = { lualine_a = { ft_info } } |
| 35 |
|
| 36 |
M.filetypes = { 'Avante', 'AvanteInput', 'AvanteSelectedCode', 'AvanteSelectedFiles', 'AvanteTodos' } |
| 37 |
|
| 38 |
return M |