Skip to content

Commit

Permalink
fix: avoid cmd len limit on windows (issue: #192)
Browse files Browse the repository at this point in the history
storing payloads on disk and using curl -d@file
  • Loading branch information
Robitx committed Aug 9, 2024
1 parent 7cc3599 commit a2df34c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lua/gp/dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local default_config = require("gp.config")
local D = {
config = {},
providers = {},
query_dir = vim.fn.stdpath("cache") .. "/gp/query",
}

---@param opts table # user config
Expand Down Expand Up @@ -49,6 +50,19 @@ D.setup = function(opts)
provider.secret = nil
end

D.query_dir = helpers.prepare_dir(D.query_dir, "query store")

local files = vim.fn.glob(D.query_dir .. "/*.json", false, true)
if #files > 200 then
logger.debug("too many query files, truncating cache")
table.sort(files, function(a, b)
return a > b
end)
for i = 100, #files do
helpers.delete_file(files[i])
end
end

logger.debug("dispatcher setup finished\n" .. vim.inspect(D))
end

Expand Down Expand Up @@ -348,6 +362,9 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
}
end

local temp_file = D.query_dir .. "/" .. logger.now() .. "." .. string.format("%x", math.random(0, 0xFFFFFF)) .. ".json"
helpers.table_to_file(payload, temp_file)

local curl_params = vim.deepcopy(D.config.curl_params or {})
local args = {
"--no-buffer",
Expand All @@ -356,8 +373,7 @@ local query = function(buf, provider, payload, handler, on_exit, callback)
"-H",
"Content-Type: application/json",
"-d",
vim.json.encode(payload),
--[[ "--doesnt_exist" ]]
"@" .. temp_file,
}

for _, arg in ipairs(args) do
Expand Down

0 comments on commit a2df34c

Please sign in to comment.