This repository was archived by the owner on Aug 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 748
Expand file tree
/
Copy pathltrs.lua
More file actions
60 lines (52 loc) · 1.79 KB
/
ltrs.lua
File metadata and controls
60 lines (52 loc) · 1.79 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local h = require("null-ls.helpers")
local methods = require("null-ls.methods")
local DIAGNOSTICS = methods.internal.DIAGNOSTICS
local handle_ltrs_output = function(params)
local file = params.output
if file and file.matches then
local parser = h.diagnostics.from_json({
severities = {
ERROR = h.diagnostics.severities.error,
},
})
local offenses = {}
for _, m in ipairs(file.matches) do
local tip = table.concat(
vim.tbl_map(function(r)
return "“" .. r.value .. "”"
end, m.replacements),
", "
)
table.insert(offenses, {
message = m.message .. " Try: " .. tip,
ruleId = m.rule.id,
level = "ERROR",
line = m.moreContext.line_number,
column = m.moreContext.line_offset + 1,
endLine = m.moreContext.line_number,
endColumn = m.moreContext.line_offset + m.length + 1,
})
end
return parser({ output = offenses })
end
return {}
end
return h.make_builtin({
name = "ltrs",
meta = {
url = "https://github.com/jeertmans/languagetool-rust",
description = "LanguageTool-Rust (LTRS) is both an executable and a Rust library that aims to provide correct and safe bindings for the LanguageTool API.",
},
method = DIAGNOSTICS,
filetypes = { "text", "markdown", "markdown" },
generator_opts = {
command = "ltrs",
args = { "check", "-m", "-r", "--text", "$TEXT" },
format = "json",
check_exit_code = function(c)
return c <= 1
end,
on_output = handle_ltrs_output,
},
factory = h.generator_factory,
})