rest-nvim / rest.nvim

A fast Neovim http client written in Lua
GNU General Public License v3.0
1.58k stars 141 forks source link

Feature: Change file type of buffer Response to rest_nvim_result #424

Closed eeeXun closed 1 month ago

eeeXun commented 2 months ago

Issues

Feature description

After sending request, there are four buffers open. Response, Headers, Cookies and Statistics.

The file type of the last three buffers is rest_nvim_result. But the file type of Response buffer is http. Can this be unified into rest_nvim_result?

boltlessengineer commented 2 months ago

It is because we are using tree-sitter-http parser for parsing the response buffer. I can run vim.treesitter.start(0, “http”) to attach the tree-sitter parser without setting the filetype, but then folding won’t work because vim.treesitter.foldexpr() depends on tree-sitter parser registered to current buffer’s filetype, not attached parser.

I thought folding is crucial feature for response pane, so I end up manually setting filetype for that specific buffer to http.

Maybe I can register http parser to rest_nvim_result filetype, but then I have to make sure it doesn’t conflict with plugins like nvim-treesitter or rocks-treesitter.nvim.

boltlessengineer commented 1 month ago

Can’t find good reason to set all four buffers to rest_nvim_result filetype for now. I agree it feels bit weird right now, but it will make more sense when we introduce save the response as file feature

eeeXun commented 1 month ago

Can’t find good reason to set all four buffers to rest_nvim_result filetype for now.

Hi @boltlessengineer , I enable the winbar for all filetypes with lualine. But there is a dedicated winbar for response pane of rest.nvim. So I have to disable the winbar provided by lualine by filetype.

In current situation, I have to disable filetypes http and rest_nvim_result. But disabling filetype http is not what I want. So it would be nice if all four buffers can be set to rest_nvim_result filetype.

boltlessengineer commented 1 month ago

Sounds fair. I’ll try to see if setting general rest_nvim_result filetype for all those buffers. I’m not sure if it will work well without any issues. If it is too buggy to implement, I’ll at least provide some buffer-local variable to detect the “rest.nvim result” pane.

Actually there is a buffer-local variable to do this right now. You can check if vim.b.__pane_group is set to ”rest_nvim_result”.

eeeXun commented 1 month ago

Actually there is a buffer-local variable to do this right now. You can check if vim.b.__pane_group is set to ”rest_nvim_result”.

Yes, it's rest_nvim_result. But I don't know how to use the variable vim.b.__pane_group with lualine.

boltlessengineer commented 1 month ago

Wait, this breaks with nvim-treesitter’s auto highlighting feature. I’ll revert the recent fix.

boltlessengineer commented 1 month ago

@eeeXun This issue will take some time to fix. Or it might be unfixable in the end.

Instead of fixing this, I can help you register lualine to result UI buffers. How did you set dedicated winbar for rest_nvim_result filetype?

edit: typo

eeeXun commented 1 month ago

@eeeXun This issue will take some time to fix. Or it might be unfixable in the end.

  • vim.treesitter.foldexpr() uses a parser registered to current filetype and not a general parser
  • so if we use same rest_nvim_result filetype for all buffers, we can’t use folds in response body
  • we can register http parser to rest_nvim_result filetype, but then nvim-treesitter will try to parse all 4 buffers with http parser (which will break in buffers for headers/cookies/statistics)

Okay. I get it. I really appreciate all your efforts.

Instead of fixing this, I can help you register lualine to result UI buffers. How did you set dedicated winbar for rest_nvim_result filetype?

This is my minimal config for lualine

require("lualine").setup({
    options = {
        globalstatus = true,
        section_separators = "",
        component_separators = "",
        disabled_filetypes = {
            winbar = {
                "rest_nvim_result",
                "http",
            },
        },
    },
    winbar = {
        lualine_a = {},
        lualine_b = { "filetype" },
        lualine_c = {},
        lualine_x = {},
        lualine_y = { "filename" },
        lualine_z = {},
    },
    inactive_winbar = {
        lualine_a = { "filetype" },
        lualine_b = {},
        lualine_c = {},
        lualine_x = {},
        lualine_y = {},
        lualine_z = { "filename" },
    },
})

I enable the globalstatus, so I turn on winbar for every filetype. And disable some winbars by filetype.

boltlessengineer commented 1 month ago

Oh, I thought you were using FileType autocommand or something. Then changing your config might be way harder because there are crazy stuffs going on setting global/local winbars if I remember correctly. I’ll make a new PR for this issue but I will merge it when I test it enough and make sure it won’t break any other plugins.