Repository: neovim/neovim
File: runtime/lua/vim/fs.lua (Lua)

Code before:
    end
  else
    error('invalid type for argument "source": expected string or buffer number')
  end

  local marker_t = type(marker)
  if marker_t == 'string' or marker_t == 'function' then
    local paths = M.find(marker, {
      upward = true,
      path = vim.fn.fnamemodify(path, ':p:h'),
    })

    if #paths ~= 0 then
      return vim.fs.dirname(paths[1])
    end
  else
    for _, mark in ipairs(marker) do
      local paths = M.find(mark, {
        upward = true,
        path = vim.fn.fnamemodify(path, ':p:h'),
      })

      if #paths ~= 0 then
        return vim.fs.dirname(paths[1])
      end
    end
  end

  return nil
end

--- Split a Windows path into a prefix and a body, such that the body can be processed like a POSIX
--- path. The path must use forward slashes as path separator.
---
--- Does not check if the path is a valid Windows path. Invalid paths will give invalid results.
---
--- Examples:
--- - `//./C:/foo/bar` -> `//./C:`, `/foo/bar`
--- - `//?/UNC/server/share/foo/bar` -> `//?/UNC/server/share`, `/foo/bar`
--- - `//./system07/C$/foo/bar` -> `//./system07`, `/C$/foo/bar`
--- - `C:/foo/bar` -> `C:`, `/foo/bar`
--- - `C:foo/bar` -> `C:`, `foo/bar`
---
--- @param path string Path to split.
--- @return string, string, boolean : prefix, body, whether path is invalid.
local function split_windows_path(path)
  local prefix = ''

  --- Match pattern. If there is a match, move the matched pattern from the path to the prefix.
  --- Returns the matched pattern.
  ---

Review comment (suggestion):
this `else` assumes that `marker` is a list? anyway, similar to the old code in lsp.lua, we don't two separate codepaths. if `marker` is not a list, just convert it into a list.

```lua
    local markers = type(marker) == 'table' and marker or { marker }
    for _, mark in ipairs(markers) do
      local paths = M.find(mark, {
        upward = true,
        path = vim.fn.fnamemodify(path, ':p:h'),
      })

      if #paths ~= 0 then
        return vim.fs.dirname(paths[1])
      end

```

Code after:
    end
  else
    error('invalid type for argument "source": expected string or buffer number')
  end

  local markers = type(marker) == 'table' and marker or { marker }
  for _, mark in ipairs(markers) do
    local paths = M.find(mark, {
      upward = true,
      path = vim.fn.fnamemodify(path, ':p:h'),
    })

    if #paths ~= 0 then
      return vim.fs.dirname(paths[1])
    end
  end

  return nil
end

--- Split a Windows path into a prefix and a body, such that the body can be processed like a POSIX
--- path. The path must use forward slashes as path separator.
---
--- Does not check if the path is a valid Windows path. Invalid paths will give invalid results.
---
--- Examples:
--- - `//./C:/foo/bar` -> `//./C:`, `/foo/bar`
--- - `//?/UNC/server/share/foo/bar` -> `//?/UNC/server/share`, `/foo/bar`
--- - `//./system07/C$/foo/bar` -> `//./system07`, `/C$/foo/bar`
--- - `C:/foo/bar` -> `C:`, `/foo/bar`
--- - `C:foo/bar` -> `C:`, `foo/bar`
---
--- @param path string Path to split.
--- @return string, string, boolean : prefix, body, whether path is invalid.
local function split_windows_path(path)
  local prefix = ''

  --- Match pattern. If there is a match, move the matched pattern from the path to the prefix.
  --- Returns the matched pattern.
  ---
  --- @param pattern string Pattern to match.
  --- @return string|nil Matched pattern
  local function match_to_prefix(pattern)
    local match = path:match(pattern)

    if match then
      prefix = prefix .. match --[[ @as string ]]
      path = path:sub(#match + 1)
    end

    return match