351351
352352--- @param line string
353353--- @param lnum (integer | string )?
354- function M .append (line , lnum )
354+ --- @param opts ? { newline : boolean }
355+ function M .append (line , lnum , opts )
356+ opts = opts or {}
355357 local buf = repl ._init_buf ()
356358 if api .nvim_get_current_win () == repl .win and lnum == ' $' then
357359 lnum = nil
@@ -360,12 +362,17 @@ function M.append(line, lnum)
360362 line = line :gsub (' \r\n ' , ' \n ' )
361363 end
362364 local lines = vim .split (line , ' \n ' )
363- if # lines > 1 and lines [# lines ] == ' ' then
364- table.remove (lines )
365- end
366365 if lnum == ' $' or not lnum then
367366 lnum = api .nvim_buf_line_count (buf ) - 1
368- api .nvim_buf_set_lines (buf , - 1 , - 1 , true , lines )
367+ if opts .newline == false then
368+ local last_line = api .nvim_buf_get_lines (buf , - 2 , - 1 , true )[1 ]
369+ if vim .startswith (last_line , ' dap> ' ) then
370+ table.insert (lines , 1 , ' ' )
371+ end
372+ api .nvim_buf_set_text (buf , lnum , # last_line , lnum , # last_line , lines )
373+ else
374+ api .nvim_buf_set_lines (buf , - 1 , - 1 , true , lines )
375+ end
369376 else
370377 api .nvim_buf_set_lines (buf , lnum , lnum , true , lines )
371378 end
438445 return {}
439446 end
440447 end
448+ assert (session , ' Session must exist if supportsCompletionsRequest is true' )
441449 session :request (' completions' , {
442450 frameId = (session .current_frame or {}).id ;
443451 text = line_to_cursor ;
0 commit comments