diff --git a/lua/rest-nvim/commands.lua b/lua/rest-nvim/commands.lua index 0eeeb60..055e69f 100644 --- a/lua/rest-nvim/commands.lua +++ b/lua/rest-nvim/commands.lua @@ -100,7 +100,7 @@ local rest_command_tbl = { }, run = { impl = function(args, opts) - if vim.bo.filetype ~= "http" or vim.b.__rest_no_http_file then + if vim.bo.filetype ~= "http" then vim.notify( "`:Rest run` can be only called from http file", vim.log.levels.ERROR, diff --git a/lua/rest-nvim/ui/result.lua b/lua/rest-nvim/ui/result.lua index c914703..d019b52 100644 --- a/lua/rest-nvim/ui/result.lua +++ b/lua/rest-nvim/ui/result.lua @@ -20,9 +20,11 @@ end ---@param buffer integer ---@param filetype string local function syntax_highlight(buffer, filetype) + -- manually stop any attached tree-sitter parsers (#424, #429) + vim.treesitter.stop(buffer) local lang = vim.treesitter.language.get_lang(filetype) local ok = pcall(vim.treesitter.start, buffer, lang) - if not ok then + if not lang or not ok then vim.bo[buffer].syntax = filetype end end @@ -59,11 +61,7 @@ local panes = { set_lines(self.bufnr, { "No Request running" }) return end - -- HACK: `vim.treesitter.foldexpr()` finds fold based on filetype not registered parser of - -- current buffer - vim.bo[self.bufnr].filetype = "http" - vim.b[self.bufnr].__rest_no_http_file = true - -- syntax_highlight(self.bufnr, "http") + syntax_highlight(self.bufnr, "rest_nvim_result") local lines = render_request(data.request) if data.response then logger.debug(data.response.status) diff --git a/plugin/rest-nvim.lua b/plugin/rest-nvim.lua index 09d3d51..996d997 100644 --- a/plugin/rest-nvim.lua +++ b/plugin/rest-nvim.lua @@ -72,5 +72,6 @@ vim.g.rest_nvim_deps = rest_nvim_deps require("rest-nvim.autocmds").setup() require("rest-nvim.commands").setup() +vim.treesitter.language.register("http", "rest_nvim_result") vim.g.loaded_rest_nvim = true diff --git a/queries/rest_nvim_result/folds.scm b/queries/rest_nvim_result/folds.scm new file mode 100644 index 0000000..a5f0335 --- /dev/null +++ b/queries/rest_nvim_result/folds.scm @@ -0,0 +1 @@ +; inherits http diff --git a/queries/rest_nvim_result/highlights.scm b/queries/rest_nvim_result/highlights.scm new file mode 100644 index 0000000..a5f0335 --- /dev/null +++ b/queries/rest_nvim_result/highlights.scm @@ -0,0 +1 @@ +; inherits http diff --git a/queries/rest_nvim_result/injections.scm b/queries/rest_nvim_result/injections.scm new file mode 100644 index 0000000..a5f0335 --- /dev/null +++ b/queries/rest_nvim_result/injections.scm @@ -0,0 +1 @@ +; inherits http