Skip to content

Commit efc3194

Browse files
committed
Merge pull request #30 from kaiiserni/cmp_update
feature update: use cmp built in types and cursor; add pro tip to readme
1 parent 1aec6fc commit efc3194

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ cmp.setup {
122122
}
123123
```
124124

125+
125126
### Programmatically checking and accepting suggestions
126127

127128
Alternatively, you can also check if there is an active suggestion and accept it programmatically.

lua/supermaven-nvim/cmp.lua

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ local loop = u.uv
55

66
local source = { executions = {} }
77

8-
local label_text = function(text, lines)
9-
if lines > 1 then
10-
text = text .. " ~"
11-
end
12-
8+
local label_text = function(text)
139
local shorten = function(str)
1410
local short_prefix = string.sub(str, 0, 20)
1511
local short_suffix = string.sub(str, string.len(str) - 15, string.len(str))
@@ -58,35 +54,39 @@ function source.complete(self, params, callback)
5854
return
5955
end
6056

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
6371

6472
local range = {
6573
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)
6976
},
7077
["end"] = {
71-
line = cursor[1] - 1,
72-
character = vim.fn.col("$"),
73-
},
78+
line = cursor.line,
79+
character = vim.fn.col("$")
80+
}
7481
}
7582

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-
8483
local items = {
8584
{
8685
label = label,
8786
kind = 1,
8887
score = 100,
8988
filterText = nil,
89+
insertTextFormat = insertTextFormat,
9090
cmp = {
9191
kind_hl_group = "CmpItemKindSupermaven",
9292
kind_text = "Supermaven",

0 commit comments

Comments
 (0)