diff --git a/doc/rest-nvim-api.txt b/doc/rest-nvim-api.txt index b3330a4..f858de0 100644 --- a/doc/rest-nvim-api.txt +++ b/doc/rest-nvim-api.txt @@ -372,6 +372,7 @@ utils.gq_lines({lines}, {filetype}) *utils.gq_lines* Returns: ~ (string[]) + (boolean) Whether formatting is done with `gq` ============================================================================== diff --git a/lua/rest-nvim/ui/result.lua b/lua/rest-nvim/ui/result.lua index f4be7cc..c914703 100644 --- a/lua/rest-nvim/ui/result.lua +++ b/lua/rest-nvim/ui/result.lua @@ -76,9 +76,8 @@ local panes = { ) ) local content_type = data.response.headers["content-type"] - table.insert(lines, "") - table.insert(lines, "# @_RES") local body = vim.split(data.response.body, "\n") + local body_meta = {} if content_type then local base_type, res_type = content_type[1]:match("(.*)/([^;]+)") if base_type == "image" then @@ -87,9 +86,19 @@ local panes = { body = { "Binary answer" } elseif config.response.hooks.format then -- NOTE: format hook runs here because it should be done last. - body = utils.gq_lines(body, res_type) + local ok + body, ok = utils.gq_lines(body, res_type) + if ok then + table.insert(body_meta, "formatted") + end end end + local meta_str = "" + if #body_meta > 0 then + meta_str = " (" .. table.concat(body_meta, ",") .. ")" + end + table.insert(lines, "") + table.insert(lines, "# @_RES" .. meta_str) vim.list_extend(lines, body) table.insert(lines, "# @_END") else diff --git a/lua/rest-nvim/utils.lua b/lua/rest-nvim/utils.lua index 0071c4a..11503a6 100644 --- a/lua/rest-nvim/utils.lua +++ b/lua/rest-nvim/utils.lua @@ -288,6 +288,7 @@ end ---@param lines string[] ---@param filetype string ---@return string[] +---@return boolean ok Whether formatting is done with `gq` function utils.gq_lines(lines, filetype) logger.debug("formatting with `gq`") local format_buf = vim.api.nvim_create_buf(false, true) @@ -313,12 +314,12 @@ function utils.gq_lines(lines, filetype) logger.debug(("formatting %s filetype with formatprg=%s"):format(filetype, formatprg)) else logger.debug(("can't find formatexpr or formatprg for %s filetype. Formatting is canceled"):format(filetype)) - return lines + return lines, false end vim.api.nvim_buf_call(format_buf, function() vim.cmd("silent normal gggqG") end) - return vim.api.nvim_buf_get_lines(format_buf, 0, -1, false) + return vim.api.nvim_buf_get_lines(format_buf, 0, -1, false), true end return utils