-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathon_result_diagnostics_quickfix.lua
78 lines (75 loc) · 2.21 KB
/
on_result_diagnostics_quickfix.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
69
70
71
72
73
74
75
76
77
78
-- Looks for a result value of 'diagnostics' that is a list of quickfix items
---@type overseer.ComponentFileDefinition
local comp = {
desc = "If task result contains diagnostics, add them to the quickfix",
params = {
use_loclist = {
desc = "If true, use the loclist instead of quickfix",
type = "boolean",
default = false,
},
close = {
desc = "If true, close the quickfix when there are no diagnostics",
type = "boolean",
default = false,
},
open = {
desc = "If true, open the quickfix when there are diagnostics",
type = "boolean",
default = false,
},
set_empty_results = {
desc = "If true, overwrite the current quickfix even if there are no diagnostics",
type = "boolean",
default = false,
},
},
constructor = function(params)
return {
on_result = function(self, task, result)
local diagnostics = result.diagnostics or {}
local is_empty = vim.tbl_isempty(diagnostics)
local conf
local prev_context
if params.use_loclist then
prev_context = vim.fn.getloclist(0, { context = 1 }).context
conf = {
open_cmd = "lopen",
close_cmd = "lclose",
}
else
prev_context = vim.fn.getqflist({ context = 1 }).context
conf = {
open_cmd = "botright copen",
close_cmd = "cclose",
}
end
local what = {
title = task.name,
context = task.name,
items = diagnostics,
}
local replace = prev_context == task.name
local action = replace and "r" or " "
if not replace and is_empty and not params.set_empty_results then
return
end
if params.use_loclist then
vim.fn.setloclist(0, {}, action, what)
else
vim.fn.setqflist({}, action, what)
end
if is_empty then
if params.close then
vim.cmd(conf.close_cmd)
end
elseif params.open then
local winid = vim.api.nvim_get_current_win()
vim.cmd(conf.open_cmd)
vim.api.nvim_set_current_win(winid)
end
end,
}
end,
}
return comp