Repository: nvim-lua/plenary.nvim
Pull request #624 (2024-10-04 17:12:25)

feat: Add swift filetype.

ehmurray8: Hi @Conni2461 can you take a look at this

Patch:
diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml
index 302ab2b..cc227fa 100644
--- a/.github/workflows/default.yml
+++ b/.github/workflows/default.yml
@@ -11,7 +11,7 @@ jobs:
       matrix:
         include:
           - os: ubuntu-22.04
-            rev: nightly/nvim-linux64.tar.gz
+            rev: nightly/nvim-linux-x86_64.tar.gz
           - os: ubuntu-22.04
             rev: v0.7.2/nvim-linux64.tar.gz
           - os: ubuntu-22.04
@@ -19,12 +19,12 @@ jobs:
           - os: ubuntu-22.04
             rev: v0.9.5/nvim-linux64.tar.gz
           - os: ubuntu-22.04
-            rev: v0.10.0/nvim-linux64.tar.gz
+            rev: v0.10.4/nvim-linux-x86_64.tar.gz
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - run: date +%F > todays-date
       - name: Restore cache for today's nightly.
-        uses: actions/cache@v3
+        uses: actions/cache@v4
         with:
           path: _neovim
           key: ${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }}
@@ -46,7 +46,7 @@ jobs:
     name: stylua
     runs-on: ubuntu-22.04
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - uses: JohnnyMorganz/stylua-action@v2
         with:
           token: ${{ secrets.GITHUB_TOKEN }}
@@ -58,7 +58,7 @@ jobs:
     name: Luacheck
     runs-on: ubuntu-22.04
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
 
       - name: Prepare
         run: |
diff --git a/data/plenary/filetypes/builtin.lua b/data/plenary/filetypes/builtin.lua
index c4b6d50..a7ecf15 100644
--- a/data/plenary/filetypes/builtin.lua
+++ b/data/plenary/filetypes/builtin.lua
@@ -51,6 +51,7 @@ return {
     ['resi'] = 'rescript',
     ['rkt'] = 'racket',
     ['svelte'] = 'svelte',
+    ['swift'] = 'swift',
     ['tres'] = 'gdresource',
     ['tscn'] = 'gdresource',
     ['tsx'] = 'typescriptreact',
diff --git a/lua/plenary/async/uv_async.lua b/lua/plenary/async/uv_async.lua
index 4ef0eba..427e1a5 100644
--- a/lua/plenary/async/uv_async.lua
+++ b/lua/plenary/async/uv_async.lua
@@ -3,8 +3,8 @@ local uv = vim.loop
 
 local M = {}
 
-local function add(name, argc)
-  local success, ret = pcall(a.wrap, uv[name], argc)
+local function add(name, argc, custom)
+  local success, ret = pcall(a.wrap, custom or uv[name], argc)
 
   if not success then
     error("Failed to add function with name " .. name)
@@ -48,7 +48,9 @@ add("fs_chown", 4)
 add("fs_fchown", 4)
 -- 'fs_lchown',
 add("fs_copyfile", 4)
--- add('fs_opendir', 3) -- TODO: fix this one
+add("fs_opendir", 3, function(path, entries, callback)
+  return uv.fs_opendir(path, callback, entries)
+end)
 add("fs_readdir", 2)
 add("fs_closedir", 2)
 -- 'fs_statfs',
diff --git a/lua/plenary/curl.lua b/lua/plenary/curl.lua
index b7fc997..20e8cc2 100644
--- a/lua/plenary/curl.lua
+++ b/lua/plenary/curl.lua
@@ -251,15 +251,25 @@ end
 ------------------------------------------------------------
 parse.response = function(lines, dump_path, code)
   local headers = P.readlines(dump_path)
-  local status = tonumber(string.match(headers[1], "([%w+]%d+)"))
-  local body = F.join(lines, "\n")
+  local status = nil
+  local processed_headers = {}
+
+  -- Process headers in a single pass
+  for _, line in ipairs(headers) do
+    local status_match = line:match "^HTTP/%S*%s+(%d+)"
+    if status_match then
+      status = tonumber(status_match)
+    elseif line ~= "" then
+      table.insert(processed_headers, line)
+    end
+  end
 
+  local body = F.join(lines, "\n")
   vim.loop.fs_unlink(dump_path)
-  table.remove(headers, 1)
 
   return {
-    status = status,
-    headers = headers,
+    status = status or 0,
+    headers = processed_headers,
     body = body,
     exit = code,
   }
diff --git a/lua/plenary/job.lua b/lua/plenary/job.lua
index 44a7348..7f54971 100644
--- a/lua/plenary/job.lua
+++ b/lua/plenary/job.lua
@@ -361,7 +361,7 @@ local on_output = function(self, result_key, cb)
         cb(err, result_line, self)
       end
 
-      if data == nil or is_complete then
+      if is_complete then
         return
       end
 
diff --git a/lua/plenary/path.lua b/lua/plenary/path.lua
index 51229f1..701679e 100644
--- a/lua/plenary/path.lua
+++ b/lua/plenary/path.lua
@@ -929,7 +929,7 @@ end
 
 function Path:find_upwards(filename)
   local folder = Path:new(self)
-  local root = path.root(folder)
+  local root = path.root(folder:absolute())
 
   while folder:absolute() ~= root do
     local p = folder:joinpath(filename)
@@ -938,7 +938,7 @@ function Path:find_upwards(filename)
     end
     folder = folder:parent()
   end
-  return ""
+  return nil
 end
 
 return Path


Test patch:
diff --git a/tests/plenary/job_spec.lua b/tests/plenary/job_spec.lua
index d9213be..c2edde0 100644
--- a/tests/plenary/job_spec.lua
+++ b/tests/plenary/job_spec.lua
@@ -99,7 +99,7 @@ describe("Job", function()
       assert.are.same(job:result(), results)
     end)
 
-    pending("should split stdin across newlines with no ending newline", function()
+    it("should split stdin across newlines with no ending newline", function()
       local results = {}
       local job = Job:new {
         -- writer = "hello\nword\nthis is\ntj",
@@ -113,6 +113,8 @@ describe("Job", function()
       job:start()
       job:send "hello\nwor"
       job:send "ld"
+
+      wait_for_result(job, { "hello", "world" })
       job:shutdown()
 
       assert.are.same(job:result(), { "hello", "world" })
@@ -137,7 +139,7 @@ describe("Job", function()
       assert.are.same(job:result(), results)
     end)
 
-    pending("should return last line when there is no ending newline", function()
+    it("should return last line when there is no ending newline", function()
       local results = {}
       local job = Job:new {
         command = "printf",