Skip to content

:Rest last fails with "request failed" due to missing nio.run() in run_last() #569

@satoshiyamamoto

Description

@satoshiyamamoto

Prerequisites

  • I am using the latest stable release of Neovim
  • I am using the latest version of the plugin
  • I can reproduce the bug with minimal config below

Neovim Version

0.11.6

Operating system/version

MacOS 25.3.0

Actual behavior

Running :Rest last after executing a request always fails with a "request failed" notification. The error log shows:

ERROR | ... | lua/rest-nvim/request.lua:66 | request failed

Expected behavior

:Rest last should re-run the last executed HTTP request successfully, the same way :Rest run works.

Steps to reproduce

  1. Open any .http file
  2. Run a request with :Rest run
  3. Run :Rest last
  4. Observe the "request failed" notification and the error in :Rest logs

Root cause

This is a regression introduced in #535 (98f0bfc — "fix: prevent buffer change while parsing"), which moved nio.run() from inside run_request() to inside M.run(). However, M.run_last() was not updated to match.

run_request() calls .wait on a nio.control.Future, which requires being called inside a nio coroutine. After the refactor, M.run() correctly wraps the call in nio.run(), but M.run_last() still calls run_request() directly outside a coroutine:

-- M.run() — correctly wrapped
function M.run(name)
    nio.run(function()
        local req = parser.parse(...)
        run_request(req)  -- called inside nio coroutine ✓
    end)
end

-- M.run_last() — NOT wrapped, causes error
function M.run_last()
    local req = rest_nvim_last_request
    ...
    run_request(req)  -- called outside nio coroutine ✗
end

Fix: wrap run_request(req) in nio.run() inside M.run_last():

function M.run_last()
    local req = rest_nvim_last_request
    if not req then
        vim.notify("No last request found", vim.log.levels.WARN, { title = "rest.nvim" })
        return false
    end
    nio.run(function()
        run_request(req)
    end)
end

Minimal config for repro (using lazy.nvim)

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        "rest-nvim/rest.nvim",
        {
            "nvim-treesitter/nvim-treesitter",
            build = ":TSUpdate",
            main = "nvim-treesitter.configs",
            opts = {
                ensure_installed = { "http" },
                sync_install = false,
                highlight = { enable = true },
                indent = { enable = true },
            },
        },
    },
})

Then open a .http file, run :Rest run, then :Rest last.

Other information

  • Regression introduced in commit 98f0bfc (released in v3.11.2)
  • :Rest run works correctly; only :Rest last is affected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions