Skip to content

Commit cbe31e7

Browse files
fix: enable fold in result UI
1 parent 01c661b commit cbe31e7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lua/rest-nvim/response.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function response.try_format_body(content_type, body)
6161
logger.info(msg)
6262
vim.notify(msg, vim.log.levels.INFO)
6363
end
64-
return vim.split(body, "\n")
64+
return vim.split(body, "\n", {trimempty = res_type == "json"})
6565
end
6666
end
6767

lua/rest-nvim/ui/result.lua

+12-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ local panes = {
5151
set_lines(self.bufnr, { "Loading..." })
5252
return
5353
end
54-
syntax_highlight(self.bufnr, "http")
54+
-- HACK: `vim.treesitter.foldexpr()` finds fold based on filetype not registered parser of
55+
-- current buffer
56+
vim.bo[self.bufnr].filetype = "http"
57+
-- syntax_highlight(self.bufnr, "http")
5558
local lines = render_request(data.request)
5659
if data.response then
5760
local body = res.try_format_body(data.response.headers["content-type"], data.response.body)
@@ -166,6 +169,14 @@ local group = paneui.create_pane_group("rest_nvim_result", panes, {
166169
vim.keymap.set("n", "?", help.open, { buffer = self.bufnr })
167170
vim.bo[self.bufnr].filetype = "rest_nvim_result"
168171
utils.nvim_lazy_set_wo(self.bufnr, "winbar", winbar)
172+
-- HACK: hack to enable fold inside buftype=nofile
173+
vim.api.nvim_create_autocmd("WinEnter", {
174+
buffer = self.bufnr,
175+
callback = function ()
176+
vim.api.nvim_set_option_value("foldmethod", "expr", { scope = "local" })
177+
end,
178+
once = true,
179+
})
169180
end,
170181
})
171182

0 commit comments

Comments
 (0)