1
1
local source = require (' render-markdown.integ.source' )
2
2
3
- local M = {}
4
-
5
- --- @class coq.Args
6
- --- @field pos { [1] : integer , [2] : integer }
7
- --- @field line string
8
-
9
- --- @class coq.CallbackArgs
10
- --- @field isIncomplete boolean
11
- --- @field items vim.lsp.CompletionResult
12
-
13
- --- @class coq.Source
14
- --- @field name string
15
- --- @field fn fun ( args : coq.Args , callback : fun ( args ?: coq.CallbackArgs )): fun ()| nil
16
-
17
- --- @alias coq.Sources table<integer , coq.Source>
18
-
19
- --- @param map coq.Sources
3
+ --- @param map table<integer , table>
4
+ --- @return integer
20
5
local function new_uid (map )
21
- local key --- @type integer | nil
6
+ --- @type integer | nil
7
+ local key = nil
22
8
while true do
23
9
if not key or map [key ] then
24
10
key = math.floor (math.random () * 10000 )
@@ -28,39 +14,36 @@ local function new_uid(map)
28
14
end
29
15
end
30
16
17
+ --- @param args { line : string , pos : { [1] : integer , [2] : integer } }
18
+ --- @param callback fun ( response ?: lsp.CompletionItem[] )
31
19
local function complete (args , callback )
32
- if not source .enabled () then
33
- callback (nil )
34
- return
35
- end
36
-
37
- local last_char = args .line :sub (# args .line , # args .line )
38
- if not vim .list_contains (source :trigger_characters (), last_char ) then
39
- callback (nil )
40
- return
41
- end
42
-
43
- local row , col = unpack (args .pos ) --- @type integer , integer
44
-
45
- local items = source .items (0 , row , col )
46
-
47
- if items == nil then
48
- callback (nil )
49
- return
20
+ --- @return lsp.CompletionItem[] ?
21
+ local function get_items ()
22
+ if not source .enabled () then
23
+ return nil
24
+ end
25
+ local character = args .line :sub (# args .line , # args .line )
26
+ if not vim .tbl_contains (source .trigger_characters (), character ) then
27
+ return nil
28
+ end
29
+ return source .items (0 , args .pos [1 ], args .pos [2 ])
50
30
end
51
-
52
- callback (items )
31
+ callback (get_items ())
53
32
end
54
33
34
+ --- @class render.md.cmp.Coq
35
+ local M = {}
36
+
55
37
--- Should only be called by a user to enable the integration
56
38
function M .setup ()
57
39
local has_coq = pcall (require , ' coq' )
58
40
if not has_coq then
59
41
return
60
42
end
61
- COQsources = COQsources or {} --- @type coq.Sources
43
+ --- @type table<integer , table>
44
+ COQsources = COQsources or {}
62
45
COQsources [new_uid (COQsources )] = {
63
- name = ' rMD ' ,
46
+ name = ' markdown ' ,
64
47
fn = complete ,
65
48
}
66
49
end
0 commit comments