Skip to content

Commit b8c2315

Browse files
authored
feat(exteionsion): recognize avante "todo" and "code" sections (#1448)
In addition to input, output, and "selected files" windows Avante may be using a window for "todos" and a window to show a snippet of code selected by the user. Recognize them.
1 parent 58eccf5 commit b8c2315

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lua/lualine/extensions/avante.lua

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
-- MIT license, see LICENSE for more details.
22
-- Extension for avante.nvim
3+
4+
local avante_ok, avante_config = pcall(require, 'avante.config')
5+
36
local M = {}
47

58
local function ft_info()
@@ -8,13 +11,30 @@ local function ft_info()
811
return 'Output'
912
elseif ft == 'AvanteInput' then
1013
return require('lualine.utils.mode').get_mode()
14+
elseif ft == 'AvanteSelectedCode' then
15+
local max_shown = vim.api.nvim_win_get_height(0)
16+
if avante_config.windows.sidebar_header.enabled then
17+
max_shown = max_shown - 1
18+
end
19+
local num_lines = vim.api.nvim_buf_line_count(0)
20+
return string.format('Code Fragment: %s%d lines', max_shown < num_lines and (max_shown .. '/') or '', num_lines)
1121
elseif ft == 'AvanteSelectedFiles' then
1222
return 'Total Files: ' .. vim.api.nvim_buf_line_count(0)
23+
elseif ft == 'AvanteTodos' then
24+
local todos = vim.api.nvim_buf_get_lines(0, 0, -1, false)
25+
local completed = vim.iter(todos):fold(0, function(counter, todo)
26+
if todo:sub(1, 3) == '[x]' then
27+
counter = counter + 1
28+
end
29+
return counter
30+
end)
31+
return string.format('Todos: %d/%d', completed, #todos)
1332
end
1433
end
1534

1635
M.sections = { lualine_a = { ft_info } }
1736

18-
M.filetypes = { 'Avante', 'AvanteInput', 'AvanteSelectedFiles' }
37+
M.filetypes = avante_ok and { 'Avante', 'AvanteInput', 'AvanteSelectedCode', 'AvanteSelectedFiles', 'AvanteTodos' }
38+
or {}
1939

2040
return M

0 commit comments

Comments
 (0)