|
| 1 | +local h = require("null-ls.helpers") |
1 | 2 | local methods = require("null-ls.methods")
|
2 |
| -local helpers = require("null-ls.helpers") |
3 | 3 |
|
4 | 4 | local DIAGNOSTICS = methods.internal.DIAGNOSTICS
|
5 | 5 |
|
6 | 6 | local M = {}
|
7 | 7 |
|
8 |
| -M.write_good = { |
| 8 | +M.write_good = h.make_builtin({ |
9 | 9 | method = DIAGNOSTICS,
|
10 | 10 | filetypes = {"markdown"},
|
11 |
| - generator = helpers.generator_factory( |
12 |
| - { |
13 |
| - command = "write-good", |
14 |
| - args = {"--text=$TEXT", "--parse"}, |
15 |
| - format = "line", |
16 |
| - check_exit_code = function(code) |
17 |
| - return code == 0 or code == 255 |
18 |
| - end, |
19 |
| - on_output = function(line, params) |
20 |
| - local pos = vim.split(string.match(line, "%d+:%d+"), ":") |
21 |
| - local row = pos[1] |
| 11 | + generator_opts = { |
| 12 | + command = "write-good", |
| 13 | + args = {"--text=$TEXT", "--parse"}, |
| 14 | + format = "line", |
| 15 | + check_exit_code = function(code) return code == 0 or code == 255 end, |
| 16 | + on_output = function(line, params) |
| 17 | + local pos = vim.split(string.match(line, "%d+:%d+"), ":") |
| 18 | + local row = pos[1] |
22 | 19 |
|
23 |
| - local message = string.match(line, ":([^:]+)$") |
| 20 | + local message = string.match(line, ":([^:]+)$") |
24 | 21 |
|
25 |
| - local col, end_col |
26 |
| - local issue = string.match(line, "%b\"\"") |
27 |
| - local issue_line = params.content[tonumber(row)] |
28 |
| - if issue and issue_line then |
29 |
| - local issue_start, issue_end = |
30 |
| - string.find(issue_line, string.match(issue, "([^\"]+)")) |
31 |
| - if issue_start and issue_end then |
32 |
| - col = tonumber(issue_start) - 1 |
33 |
| - end_col = issue_end |
34 |
| - end |
| 22 | + local col, end_col |
| 23 | + local issue = string.match(line, "%b\"\"") |
| 24 | + local issue_line = params.content[tonumber(row)] |
| 25 | + if issue and issue_line then |
| 26 | + local issue_start, issue_end = |
| 27 | + string.find(issue_line, string.match(issue, "([^\"]+)")) |
| 28 | + if issue_start and issue_end then |
| 29 | + col = tonumber(issue_start) - 1 |
| 30 | + end_col = issue_end |
35 | 31 | end
|
36 |
| - |
37 |
| - return { |
38 |
| - row = row, |
39 |
| - col = col, |
40 |
| - end_col = end_col, |
41 |
| - message = message, |
42 |
| - severity = 1, |
43 |
| - source = "write-good" |
44 |
| - } |
45 | 32 | end
|
46 |
| - }) |
47 |
| -} |
48 | 33 |
|
49 |
| -M.markdownlint = { |
| 34 | + return { |
| 35 | + row = row, |
| 36 | + col = col, |
| 37 | + end_col = end_col, |
| 38 | + message = message, |
| 39 | + severity = 1, |
| 40 | + source = "write-good" |
| 41 | + } |
| 42 | + end |
| 43 | + }, |
| 44 | + factory = h.generator_factory |
| 45 | +}) |
| 46 | + |
| 47 | +M.markdownlint = h.make_builtin({ |
50 | 48 | method = DIAGNOSTICS,
|
51 | 49 | filetypes = {"markdown"},
|
52 |
| - generator = helpers.generator_factory( |
53 |
| - { |
54 |
| - command = "markdownlint", |
55 |
| - args = {"--stdin"}, |
56 |
| - to_stdin = true, |
57 |
| - to_stderr = true, |
58 |
| - format = "line", |
59 |
| - check_exit_code = function(code) return code <= 1 end, |
60 |
| - on_output = function(line, params) |
61 |
| - local split = vim.split(line, " ") |
62 |
| - local rule = split[2] |
63 |
| - local _, rule_end = string.find(line, rule, nil, true) |
64 |
| - local message = string.sub(line, rule_end + 2) |
| 50 | + generator_opts = { |
| 51 | + command = "markdownlint", |
| 52 | + args = {"--stdin"}, |
| 53 | + to_stdin = true, |
| 54 | + to_stderr = true, |
| 55 | + format = "line", |
| 56 | + check_exit_code = function(code) return code <= 1 end, |
| 57 | + on_output = function(line, params) |
| 58 | + local split = vim.split(line, " ") |
| 59 | + local rule = split[2] |
| 60 | + local _, rule_end = string.find(line, rule, nil, true) |
| 61 | + local message = string.sub(line, rule_end + 2) |
65 | 62 |
|
66 |
| - local pos = vim.split(split[1], ":") |
67 |
| - local row = pos[2] |
68 |
| - local col = pos[3] |
| 63 | + local pos = vim.split(split[1], ":") |
| 64 | + local row = pos[2] |
| 65 | + local col = pos[3] |
69 | 66 |
|
70 |
| - local end_col |
71 |
| - local issue = string.match(line, "%b[]") |
72 |
| - if issue then |
73 |
| - issue = string.sub(issue, 2, #issue - 1) |
74 |
| - local issue_line = params.content[tonumber(row)] |
75 |
| - _, end_col = string.find(issue_line, issue, nil, true) |
76 |
| - end |
77 |
| - |
78 |
| - return { |
79 |
| - row = row, |
80 |
| - col = col and col - 1, |
81 |
| - end_col = end_col, |
82 |
| - message = message, |
83 |
| - severity = 1, |
84 |
| - source = "markdownlint" |
85 |
| - } |
| 67 | + local end_col |
| 68 | + local issue = string.match(line, "%b[]") |
| 69 | + if issue then |
| 70 | + issue = string.sub(issue, 2, #issue - 1) |
| 71 | + local issue_line = params.content[tonumber(row)] |
| 72 | + _, end_col = string.find(issue_line, issue, nil, true) |
86 | 73 | end
|
87 |
| - }) |
88 |
| -} |
| 74 | + |
| 75 | + return { |
| 76 | + row = row, |
| 77 | + col = col and col - 1, |
| 78 | + end_col = end_col, |
| 79 | + message = message, |
| 80 | + severity = 1, |
| 81 | + source = "markdownlint" |
| 82 | + } |
| 83 | + end |
| 84 | + }, |
| 85 | + factory = h.generator_factory |
| 86 | +}) |
89 | 87 |
|
90 | 88 | return M
|
0 commit comments