11local formatter = {}
22
3+ local close_chars = { [' )' ] = true , [' ]' ] = true , [' }' ] = true }
34local shorten = function (str )
45 local short_prefix = string.sub (str , 0 , 20 )
56 local short_suffix = string.sub (str , string.len (str )- 15 , string.len (str ))
@@ -44,14 +45,25 @@ local check_exists = function (text_list)
4445end
4546
4647local format_insert_text = function (deindented , ctx )
48+ -- if ctx.cursor_after_line[1]
49+
4750 local indent_string = get_indent_string (ctx )
51+
4852 local text_list = str_to_list (deindented )
53+
54+ -- do this before check_exists so that we end after existing
55+ local fmt_info = {
56+ startl = ctx .cursor .row ,
57+ endl = # text_list + ctx .cursor .row - 1 ,
58+ n_lines = # text_list ,
59+ }
4960 -- this is necessary because first line starts at cursor pos
5061 for line_idx = 2 , # text_list do
5162 text_list [line_idx ] = indent_string .. text_list [line_idx ]
5263 end
5364 text_list = check_exists (text_list )
54- return table.concat (text_list , ' \n ' )
65+ local fmt_string = table.concat (text_list , ' \n ' )
66+ return fmt_string , fmt_info
5567end
5668
5769local format_label_text = function (item )
@@ -61,12 +73,18 @@ local format_label_text = function (item)
6173end
6274
6375local format_item = function (item , params )
76+ -- local after_without_ws = params.context.cursor_after_line:match("^%s*(.-)%s*$")
77+ -- if #after_without_ws > 0 and close_chars[after_without_ws] then
78+ -- item.text = item.text .. after_without_ws .. '\n'
79+ -- end
6480 local deindented = formatter .deindent (item .text )
65- local insert_text = format_insert_text (deindented , params .context )
81+ local insert_text , fmt_info = format_insert_text (deindented , params .context )
6682 local label_text = format_label_text (item )
83+
6784 return {
6885 copilot = true , -- for comparator, only availiable in panel, not cycling
6986 score = item .score or nil ,
87+ fmt_info = fmt_info ,
7088 label = label_text ,
7189 filterText = label_text :sub (0 , label_text :len ()- 1 ),
7290 kind = 1 ,
0 commit comments