@@ -5,11 +5,7 @@ local loop = u.uv
5
5
6
6
local source = { executions = {} }
7
7
8
- local label_text = function (text , lines )
9
- if lines > 1 then
10
- text = text .. " ~"
11
- end
12
-
8
+ local label_text = function (text )
13
9
local shorten = function (str )
14
10
local short_prefix = string.sub (str , 0 , 20 )
15
11
local short_suffix = string.sub (str , string.len (str ) - 15 , string.len (str ))
@@ -58,35 +54,39 @@ function source.complete(self, params, callback)
58
54
return
59
55
end
60
56
61
- -- local context = params.context
62
- local cursor = vim .api .nvim_win_get_cursor (0 )
57
+
58
+ local context = params .context
59
+ local cursor = context .cursor
60
+
61
+ local completion_text = (inlay_instance .line_before_cursor ) .. inlay_instance .completion_text
62
+ local preview_text = completion_text
63
+ local split = vim .split (completion_text , " \n " , { plain = true })
64
+ local label = label_text (split [1 ])
65
+
66
+ local insertTextFormat = 1 -- cmp.lsp.InsertTextFormat.PlainText
67
+
68
+ if # split > 1 then
69
+ insertTextFormat = 2 -- cmp.lsp.InsertTextFormat.Snippet
70
+ end
63
71
64
72
local range = {
65
73
start = {
66
- line = cursor [1 ] - 1 ,
67
- -- character = math.max(cursor[2] - inlay_instance.prior_delete, 0),
68
- character = vim .fn .col (" 0" ),
74
+ line = cursor .line ,
75
+ character = math.max (cursor .col - inlay_instance .prior_delete - # inlay_instance .line_before_cursor - 1 , 0 )
69
76
},
70
77
[" end" ] = {
71
- line = cursor [ 1 ] - 1 ,
72
- character = vim .fn .col (" $" ),
73
- },
78
+ line = cursor . line ,
79
+ character = vim .fn .col (" $" )
80
+ }
74
81
}
75
82
76
- local completion_text = inlay_instance .line_before_cursor .. inlay_instance .completion_text
77
- local preview_text = completion_text
78
- local split = vim .split (completion_text , " \n " , { plain = true })
79
- local label = label_text (split [1 ], # split )
80
- -- local label = u.trim_start(vim.split(completion_text, "\n", { plain = true })[1])
81
-
82
- -- print("Completion label:", label)
83
-
84
83
local items = {
85
84
{
86
85
label = label ,
87
86
kind = 1 ,
88
87
score = 100 ,
89
88
filterText = nil ,
89
+ insertTextFormat = insertTextFormat ,
90
90
cmp = {
91
91
kind_hl_group = " CmpItemKindSupermaven" ,
92
92
kind_text = " Supermaven" ,
0 commit comments