@@ -136,11 +136,27 @@ return {
136136 -- default contexts
137137 contexts = {
138138 buffer = {
139- description = ' Includes only the current buffer in chat context. Supports input.' ,
139+ description = ' Includes specified buffer in chat context (default current) . Supports input.' ,
140140 input = function (callback )
141- vim .ui .select (vim .api .nvim_list_bufs (), {
142- prompt = ' Select a buffer> ' ,
143- }, callback )
141+ vim .ui .select (
142+ vim .tbl_map (
143+ function (buf )
144+ return { id = buf , name = vim .api .nvim_buf_get_name (buf ) }
145+ end ,
146+ vim .tbl_filter (function (buf )
147+ return vim .api .nvim_buf_is_loaded (buf ) and vim .fn .buflisted (buf ) == 1
148+ end , vim .api .nvim_list_bufs ())
149+ ),
150+ {
151+ prompt = ' Select a buffer> ' ,
152+ format_item = function (item )
153+ return item .name
154+ end ,
155+ },
156+ function (choice )
157+ callback (choice and choice .id )
158+ end
159+ )
144160 end ,
145161 resolve = function (input , source )
146162 return {
@@ -149,12 +165,20 @@ return {
149165 end ,
150166 },
151167 buffers = {
152- description = ' Includes all open buffers in chat context.' ,
153- resolve = function ()
168+ description = ' Includes all buffers in chat context (default listed). Supports input.' ,
169+ input = function (callback )
170+ vim .ui .select ({ ' listed' , ' visible' }, {
171+ prompt = ' Select buffer scope> ' ,
172+ }, callback )
173+ end ,
174+ resolve = function (input )
175+ input = input or ' listed'
154176 return vim .tbl_map (
155177 context .outline ,
156178 vim .tbl_filter (function (b )
157- return vim .api .nvim_buf_is_loaded (b ) and vim .fn .buflisted (b ) == 1
179+ return vim .api .nvim_buf_is_loaded (b )
180+ and vim .fn .buflisted (b ) == 1
181+ and (input == ' listed' or # vim .fn .win_findbuf (b ) > 0 )
158182 end , vim .api .nvim_list_bufs ())
159183 )
160184 end ,
@@ -189,7 +213,7 @@ return {
189213 end ,
190214 },
191215 git = {
192- description = ' Includes current git diff in chat context. Supports input.' ,
216+ description = ' Includes current git diff in chat context (default unstaged) . Supports input.' ,
193217 input = function (callback )
194218 vim .ui .select ({ ' unstaged' , ' staged' }, {
195219 prompt = ' Select diff type> ' ,
0 commit comments