Skip to content

Commit 3bf17a2

Browse files
fix(ui): always use rest_nvim_result filetype
1 parent 6edb8fd commit 3bf17a2

File tree

6 files changed

+9
-7
lines changed

6 files changed

+9
-7
lines changed

lua/rest-nvim/commands.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ local rest_command_tbl = {
100100
},
101101
run = {
102102
impl = function(args, opts)
103-
if vim.bo.filetype ~= "http" or vim.b.__rest_no_http_file then
103+
if vim.bo.filetype ~= "http" then
104104
vim.notify(
105105
"`:Rest run` can be only called from http file",
106106
vim.log.levels.ERROR,

lua/rest-nvim/ui/result.lua

+4-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ end
2020
---@param buffer integer
2121
---@param filetype string
2222
local function syntax_highlight(buffer, filetype)
23+
-- manually stop any attached tree-sitter parsers (#424, #429)
24+
vim.treesitter.stop(buffer)
2325
local lang = vim.treesitter.language.get_lang(filetype)
2426
local ok = pcall(vim.treesitter.start, buffer, lang)
25-
if not ok then
27+
if not lang or not ok then
2628
vim.bo[buffer].syntax = filetype
2729
end
2830
end
@@ -59,11 +61,7 @@ local panes = {
5961
set_lines(self.bufnr, { "No Request running" })
6062
return
6163
end
62-
-- HACK: `vim.treesitter.foldexpr()` finds fold based on filetype not registered parser of
63-
-- current buffer
64-
vim.bo[self.bufnr].filetype = "http"
65-
vim.b[self.bufnr].__rest_no_http_file = true
66-
-- syntax_highlight(self.bufnr, "http")
64+
syntax_highlight(self.bufnr, "rest_nvim_result")
6765
local lines = render_request(data.request)
6866
if data.response then
6967
logger.debug(data.response.status)

plugin/rest-nvim.lua

+1
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ vim.g.rest_nvim_deps = rest_nvim_deps
7272

7373
require("rest-nvim.autocmds").setup()
7474
require("rest-nvim.commands").setup()
75+
vim.treesitter.language.register("http", "rest_nvim_result")
7576

7677
vim.g.loaded_rest_nvim = true

queries/rest_nvim_result/folds.scm

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
; inherits http
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
; inherits http
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
; inherits http

0 commit comments

Comments
 (0)