@@ -35,6 +35,10 @@ local panel = {
3535 was_insert = nil ,
3636 auto_refreshing = nil ,
3737 },
38+ layout = {
39+ position = " bottom" ,
40+ ratio = 0.4
41+ },
3842
3943 auto_refresh = false ,
4044 keymap = {},
@@ -303,10 +307,33 @@ function panel:ensure_winid()
303307 return
304308 end
305309
306- local height = math.floor (vim .api .nvim_win_get_height (0 ) * 0.4 )
310+ local position = self .layout .position
311+ local ratio = self .layout .ratio
312+
313+ local get_width = vim .api .nvim_win_get_width
314+ local get_height = vim .api .nvim_win_get_height
315+
316+ local split_map = {
317+ top = { cmd_prefix = " topleft " , winsize_fn = get_height },
318+ right = { cmd_prefix = " vertical botright " , winsize_fn = get_width },
319+ bottom = { cmd_prefix = " botright " , winsize_fn = get_height },
320+ left = { cmd_prefix = " vertical topleft " , winsize_fn = get_width },
321+ }
322+
323+ local split_info = split_map [position ]
324+ if not split_info then
325+ print (' Error: ' .. position .. ' is not a valid position' )
326+ return
327+ end
328+
329+ local function resolve_splitcmd ()
330+ local size = math.floor (split_info .winsize_fn (0 ) * ratio )
331+ local cmd_prefix = split_info .cmd_prefix
332+ return " silent noswapfile " .. cmd_prefix .. tostring (size ) .. ' split'
333+ end
307334
308335 self .winid = vim .api .nvim_win_call (0 , function ()
309- vim .cmd (" silent noswapfile " .. tostring ( height ) .. " split " )
336+ vim .cmd (resolve_splitcmd () )
310337 return vim .api .nvim_get_current_win ()
311338 end )
312339
@@ -483,14 +510,18 @@ function mod.refresh()
483510 end )
484511end
485512
486- function mod .open ()
513+ --- @param layout { position : string , ratio : number }
514+ --- position: (optional) 'bottom' | 'top' | 'left' | 'right'
515+ --- ratio: (optional) between 0 and 1
516+ function mod .open (layout )
487517 local client = c .get ()
488518 if not client then
489519 print (" Error, copilot not running" )
490520 return
491521 end
492522
493523 panel .client = client
524+ panel .layout = vim .tbl_deep_extend (" force" , panel .layout , layout or {})
494525
495526 panel :init ()
496527end
@@ -505,6 +536,7 @@ function mod.setup(config)
505536 panel .auto_refresh = config .auto_refresh or false
506537
507538 panel .keymap = config .keymap or {}
539+ panel .layout = vim .tbl_deep_extend (' force' , panel .layout , config .layout or {})
508540
509541 if panel .keymap .open then
510542 vim .keymap .set (" i" , panel .keymap .open , mod .open , {
0 commit comments