-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathmarkdown.lua
More file actions
46 lines (40 loc) · 1.16 KB
/
markdown.lua
File metadata and controls
46 lines (40 loc) · 1.16 KB
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
local M = {}
local helpers = require "null-ls.helpers"
local methods = require "null-ls.methods"
local hover = methods.internal.HOVER
M.dictionary = helpers.make_builtin {
name = "dictionary",
method = hover,
filetypes = { "text", "markdown" },
generator = {
fn = function(_, done)
local cword = vim.fn.expand "<cword>"
local send_definition = function(def)
done { cword .. ": " .. def }
end
-- If this is a BibTeX citation, don't look it up:
if string.find(cword, "@", 1, true) then
done()
return
end
require("plenary.curl").request {
url = "https://api.dictionaryapi.dev/api/v2/entries/en/" .. cword,
method = "get",
callback = vim.schedule_wrap(function(data)
if not (data and data.body) then
done()
return
end
local ok, decoded = pcall(vim.fn.json_decode, data.body)
if not ok or not (decoded and decoded[1]) then
done()
return
end
send_definition(decoded[1].meanings[1].definitions[1].definition)
end),
}
end,
async = true,
},
}
return M