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