Repository: nvim-lua/plenary.nvim
Pull request #556 (2024-02-13 12:48:48)

feat: option to use custom curl bin
ref: https://github.com/kawre/leetcode.nvim/issues/44

TLDR: if you use `msys` curl on windows, and use -d with a path to a payload file, `msys` will not make the command execute unless you wrap the payload with `'`. I guess the simplest solution to this is to have an option to specify custom curl bin path, so if the user still wishes to use `msys` as the default curl, they still have an option to specify for example `cygwin` as the curl that `plenary.nvim` will use.


Patch:
diff --git a/lua/plenary/curl.lua b/lua/plenary/curl.lua
index 0086dca..82a1e41 100644
--- a/lua/plenary/curl.lua
+++ b/lua/plenary/curl.lua
@@ -13,6 +13,8 @@ all curl methods accepts
   output       = "where to download something." (filepath)
   timeout      = "request timeout in mseconds" (number)
   http_version = "HTTP version to use: 'HTTP/0.9', 'HTTP/1.0', 'HTTP/1.1', 'HTTP/2', or 'HTTP/3'" (string)
+  proxy        = "[protocol://]host[:port] Use this proxy" (string)
+  insecure     = "Allow insecure server connections" (boolean)
 
 and returns table:
 
@@ -218,6 +220,12 @@ parse.request = function(opts)
     end
   end
 
+  if opts.insecure then
+    table.insert(result, "--insecure")
+  end
+  if opts.proxy then
+    table.insert(result, { "--proxy", opts.proxy })
+  end
   if opts.compressed then
     table.insert(result, "--compressed")
   end
@@ -269,33 +277,34 @@ local request = function(specs)
   end
 
   local job_opts = {
-    command = "curl",
+    command = vim.g.plenary_curl_bin_path or "curl",
     args = args,
   }
+
   if opts.stream then
     job_opts.on_stdout = opts.stream
-  else
-    job_opts.on_exit = function(j, code)
-      if code ~= 0 then
-        local stderr = vim.inspect(j:stderr_result())
-        local message = string.format("%s %s - curl error exit_code=%s stderr=%s", opts.method, opts.url, code, stderr)
-        if opts.on_error then
-          return opts.on_error {
-            message = message,
-            stderr = stderr,
-            exit = code,
-          }
-        else
-          error(message)
-        end
-      end
-      local output = parse.response(j:result(), opts.dump[2], code)
-      if opts.callback then
-        return opts.callback(output)
+  end
+
+  job_opts.on_exit = function(j, code)
+    if code ~= 0 then
+      local stderr = vim.inspect(j:stderr_result())
+      local message = string.format("%s %s - curl error exit_code=%s stderr=%s", opts.method, opts.url, code, stderr)
+      if opts.on_error then
+        return opts.on_error {
+          message = message,
+          stderr = stderr,
+          exit = code,
+        }
       else
-        response = output
+        error(message)
       end
     end
+    local output = parse.response(j:result(), opts.dump[2], code)
+    if opts.callback then
+      return opts.callback(output)
+    else
+      response = output
+    end
   end
   local job = J:new(job_opts)
 
diff --git a/lua/plenary/log.lua b/lua/plenary/log.lua
index 7ef0941..1bf091b 100644
--- a/lua/plenary/log.lua
+++ b/lua/plenary/log.lua
@@ -97,6 +97,9 @@ log.new = function(config, standalone)
   end
 
   local round = function(x, increment)
+    if x == 0 then
+      return x
+    end
     increment = increment or 1
     x = x / increment
     return (x > 0 and math.floor(x + 0.5) or math.ceil(x - 0.5)) * increment
diff --git a/lua/plenary/path.lua b/lua/plenary/path.lua
index 049c2b0..51229f1 100644
--- a/lua/plenary/path.lua
+++ b/lua/plenary/path.lua
@@ -78,7 +78,7 @@ end
 
 local is_absolute = function(filename, sep)
   if sep == "\\" then
-    return string.match(filename, "^[%a]:\\.*$") ~= nil
+    return string.match(filename, "^[%a]:[\\/].*$") ~= nil
   end
   return string.sub(filename, 1, 1) == sep
 end
@@ -929,7 +929,9 @@ end
 
 function Path:find_upwards(filename)
   local folder = Path:new(self)
-  while self:absolute() ~= path.root do
+  local root = path.root(folder)
+
+  while folder:absolute() ~= root do
     local p = folder:joinpath(filename)
     if p:exists() then
       return p
diff --git a/lua/plenary/popup/init.lua b/lua/plenary/popup/init.lua
index 0afcbd1..90a8a30 100644
--- a/lua/plenary/popup/init.lua
+++ b/lua/plenary/popup/init.lua
@@ -123,6 +123,9 @@ function popup.create(what, vim_options)
     assert(bufnr, "Failed to create buffer")
 
     vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe")
+    if vim.o.modifiable == false then
+      vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
+    end
 
     -- TODO: Handle list of lines
     if type(what) == "string" then


Test patch:
diff --git a/tests/plenary/popup_spec.lua b/tests/plenary/popup_spec.lua
index a02453d..250ba0e 100644
--- a/tests/plenary/popup_spec.lua
+++ b/tests/plenary/popup_spec.lua
@@ -22,6 +22,19 @@ describe("plenary.popup", function()
     eq(20, win_config.width)
   end)
 
+  it("can create a very simple window after 'set nomodifiable'", function()
+    vim.o.modifiable = false
+    local win_id = popup.create("hello there", {
+      line = 1,
+      col = 1,
+      width = 20,
+    })
+
+    local win_config = vim.api.nvim_win_get_config(win_id)
+    eq(20, win_config.width)
+    vim.o.modifiable = true
+  end)
+
   it("can apply a highlight", function()
     local win_id = popup.create("hello there", {
       highlight = "PopupColor1",