Skip to content

Commit 7fbc292

Browse files
fix: response buffer fold issue
- don't set `buftype=nofile`. it breaks with `nvim-ufo` - set `modifiable` to `false` by default in pane UI - prevent `:Rest run` run on non-http files
1 parent 7ab1007 commit 7fbc292

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

lua/rest-nvim/commands.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ local ui = require("rest-nvim.ui.result")
4747
local rest_command_tbl = {
4848
run = {
4949
impl = function(args, _opts)
50+
if vim.bo.filetype ~= "http" or vim.b.__rest_no_http_file then
51+
vim.notify("`:Rest run` can be only called from http file", vim.log.levels.ERROR)
52+
return
53+
end
5054
if #args > 1 then
5155
vim.notify("Running multiple request isn't supported yet", vim.log.levels.WARN)
5256
return

lua/rest-nvim/ui/panes.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ function M.create_pane_group(name, pane_opts, opts)
7272
-- unless lazy-setting winbar won't work
7373
vim.fn.bufload(self.bufnr)
7474
vim.bo[self.bufnr].swapfile = false
75-
vim.bo[self.bufnr].buftype = "nofile"
7675
vim.b[self.bufnr].__pane_group = name
77-
-- HACK: I can't set buffer name because it will allow `:edit` command
78-
-- vim.api.nvim_buf_set_name(self.bufnr, name .. "#" .. self.name)
76+
vim.api.nvim_buf_set_name(self.bufnr, name .. "#" .. self.name)
7977
if opts and opts.on_init then
8078
opts.on_init(self)
8179
end
@@ -91,6 +89,7 @@ function M.create_pane_group(name, pane_opts, opts)
9189
vim.bo[self.bufnr].undolevels = vim.o.undolevels
9290
end
9391
vim.bo[self.bufnr].modifiable = modifiable
92+
vim.bo[self.bufnr].modified = false
9493
end
9594
}
9695
table.insert(group.panes, pane)

lua/rest-nvim/ui/result.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ local panes = {
5454
-- HACK: `vim.treesitter.foldexpr()` finds fold based on filetype not registered parser of
5555
-- current buffer
5656
vim.bo[self.bufnr].filetype = "http"
57+
vim.b[self.bufnr].__rest_no_http_file = true
5758
-- syntax_highlight(self.bufnr, "http")
5859
local lines = render_request(data.request)
5960
if data.response then
@@ -169,14 +170,6 @@ local group = paneui.create_pane_group("rest_nvim_result", panes, {
169170
vim.keymap.set("n", "?", help.open, { buffer = self.bufnr })
170171
vim.bo[self.bufnr].filetype = "rest_nvim_result"
171172
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-
})
180173
end,
181174
})
182175

0 commit comments

Comments
 (0)