Skip to content

Commit a2df34c

Browse files
committed
fix: avoid cmd len limit on windows (issue: #192)
storing payloads on disk and using curl -d@file
1 parent 7cc3599 commit a2df34c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lua/gp/dispatcher.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ local default_config = require("gp.config")
1313
local D = {
1414
config = {},
1515
providers = {},
16+
query_dir = vim.fn.stdpath("cache") .. "/gp/query",
1617
}
1718

1819
---@param opts table # user config
@@ -49,6 +50,19 @@ D.setup = function(opts)
4950
provider.secret = nil
5051
end
5152

53+
D.query_dir = helpers.prepare_dir(D.query_dir, "query store")
54+
55+
local files = vim.fn.glob(D.query_dir .. "/*.json", false, true)
56+
if #files > 200 then
57+
logger.debug("too many query files, truncating cache")
58+
table.sort(files, function(a, b)
59+
return a > b
60+
end)
61+
for i = 100, #files do
62+
helpers.delete_file(files[i])
63+
end
64+
end
65+
5266
logger.debug("dispatcher setup finished\n" .. vim.inspect(D))
5367
end
5468

@@ -348,6 +362,9 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
348362
}
349363
end
350364

365+
local temp_file = D.query_dir .. "/" .. logger.now() .. "." .. string.format("%x", math.random(0, 0xFFFFFF)) .. ".json"
366+
helpers.table_to_file(payload, temp_file)
367+
351368
local curl_params = vim.deepcopy(D.config.curl_params or {})
352369
local args = {
353370
"--no-buffer",
@@ -356,8 +373,7 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
356373
"-H",
357374
"Content-Type: application/json",
358375
"-d",
359-
vim.json.encode(payload),
360-
--[[ "--doesnt_exist" ]]
376+
"@" .. temp_file,
361377
}
362378

363379
for _, arg in ipairs(args) do

0 commit comments

Comments
 (0)