Skip to content

Commit de9f7b0

Browse files
committed
feat: allow remote use of quickfix mode (nvim -q)
fixes #94
1 parent 9dcacee commit de9f7b0

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

lua/flatten/core.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function M.edit_files(opts)
136136
local focus_first = config.window.focus == "first"
137137
local open = config.window.open
138138
local data = opts.data
139+
local quickfix = opts.quickfix
139140

140141
local nfiles = #files
141142
local stdin_lines = #stdin
@@ -148,6 +149,7 @@ function M.edit_files(opts)
148149
and stdin_lines == 0
149150
and #pre_cmds == 0
150151
and #post_cmds == 0
152+
and #quickfix == 0
151153
then
152154
-- If there are no new bufs and no commands, don't open anything
153155
-- and tell the guest not to block
@@ -201,6 +203,10 @@ function M.edit_files(opts)
201203
}
202204
end
203205

206+
if quickfix then
207+
vim.fn.setqflist(quickfix, "r")
208+
end
209+
204210
---@type Flatten.WindowId
205211
local winnr
206212
---@type Flatten.BufferId

lua/flatten/guest.lua

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ function M.maybe_block(block)
3737
end
3838
end
3939

40-
function M.send_files(files, stdin)
41-
if #files < 1 and #stdin < 1 then
40+
function M.send_files(files, stdin, quickfix)
41+
if #files < 1 and #stdin < 1 and #quickfix < 1 then
4242
return
4343
end
4444

@@ -57,6 +57,7 @@ function M.send_files(files, stdin)
5757
response_pipe = server,
5858
guest_cwd = cwd,
5959
stdin = stdin,
60+
quickfix = quickfix,
6061
argv = vim.v.argv,
6162
force_block = force_block,
6263
}
@@ -146,9 +147,13 @@ function M.init(host_pipe)
146147
:totable()
147148
nfiles = #files
148149

150+
local quickfix = vim.iter(vim.api.nvim_list_bufs()):find(function(buf)
151+
return vim.bo[buf].filetype == "quickfix"
152+
end)
153+
149154
-- No arguments, user is probably opening a nested session intentionally
150155
-- Or only piping input from stdin
151-
if nfiles < 1 then
156+
if nfiles < 1 and not quickfix then
152157
local should_nest, should_block = config.nest_if_no_args, false
153158

154159
if config.callbacks.no_files then
@@ -176,7 +181,28 @@ function M.init(host_pipe)
176181
M.maybe_block(should_block)
177182
end
178183

179-
M.send_files(files, {})
184+
quickfix = vim
185+
.iter(vim.fn.getqflist())
186+
:map(function(old)
187+
return {
188+
filename = vim.api.nvim_buf_get_name(old.bufnr),
189+
module = old.module,
190+
lnum = old.lnum,
191+
end_lnum = old.end_lnum,
192+
col = old.col,
193+
end_col = old.end_col,
194+
vcol = old.vcol,
195+
nr = old.nr,
196+
text = old.text,
197+
pattern = old.pattern,
198+
type = old.type,
199+
valid = old.valid,
200+
user_data = old.user_data,
201+
}
202+
end)
203+
:totable()
204+
205+
M.send_files(files, {}, quickfix)
180206
end,
181207
})
182208
end

lua/flatten/init.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ local Flatten = {}
2121
---@field nest_if_no_args Flatten.NestIfNoArgs?
2222

2323
---@class Flatten.EditFilesOptions
24-
---@field files table list of files passed into nested instance
25-
---@field response_pipe string guest default socket
26-
---@field guest_cwd string guest global cwd
27-
---@field argv table full list of options passed to the nested instance, see v:argv
28-
---@field stdin table stdin lines or {}
29-
---@field force_block boolean enable blocking
30-
---@field data any? arbitrary data passed to the host
24+
---@field files table list of files passed into nested instance
25+
---@field response_pipe string guest default socket
26+
---@field guest_cwd string guest global cwd
27+
---@field argv string[] full list of options passed to the nested instance, see v:argv
28+
---@field stdin string[] stdin lines or {}
29+
---@field quickfix vim.quickfix.entry[] quickfix list or {}
30+
---@field force_block boolean enable blocking
31+
---@field data any? arbitrary data passed to the host
3132

3233
---Specify blocking by filetype
3334
---@alias Flatten.BlockFor table<string, boolean>

0 commit comments

Comments
 (0)