Skip to content

Commit a3661c7

Browse files
jonathan-elizeJonathan Elize
andauthored
feat: add option to auto close quickfix list when no errors are found (dmmulroy#24)
* feat: add option to auto close quickfix list when no errors are found * docs: add new option auto_close_qflist to README.md --------- Co-authored-by: Jonathan Elize <j-elize@ti.com>
1 parent 502f44d commit a3661c7

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ By default, the plugin uses the default `tsc` command with the `--noEmit` flag t
7676
```lua
7777
{
7878
auto_open_qflist = true,
79+
auto_close_qflist = false,
7980
enable_progress_notifications = true,
8081
flags = {
8182
noEmit = true,

lua/tsc/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ end
1111

1212
local DEFAULT_CONFIG = {
1313
auto_open_qflist = true,
14+
auto_close_qflist = false,
1415
enable_progress_notifications = true,
1516
flags = {
1617
noEmit = true,
@@ -113,7 +114,7 @@ M.run = function()
113114
errors = result.errors
114115
files_with_errors = result.files
115116

116-
utils.set_qflist(errors, config.auto_open_qflist)
117+
utils.set_qflist(errors, { auto_open = config.auto_open_qflist, auto_close = config.auto_close_qflist })
117118
end
118119

119120
local on_exit = function()

lua/tsc/utils.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ M.parse_tsc_output = function(output)
8888
return { errors = errors, files = files }
8989
end
9090

91-
M.set_qflist = function(errors, auto_open)
92-
if auto_open == nil then
93-
auto_open = true
94-
end
91+
M.set_qflist = function(errors, opts)
92+
local DEFAULT_OPTS = { auto_open = true, auto_close = false }
93+
local final_opts = vim.tbl_extend("force", DEFAULT_OPTS, opts or {})
9594

9695
vim.fn.setqflist({}, "r", { title = "TSC", items = errors })
9796

98-
if #errors > 0 and auto_open then
97+
if #errors > 0 and final_opts.auto_open then
9998
vim.cmd("copen")
99+
elseif #errors == 0 and final_opts.auto_close then
100+
vim.cmd("cclose")
100101
end
101102
end
102103

0 commit comments

Comments
 (0)