Skip to content

Commit

Permalink
fix(ui): always use rest_nvim_result filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
boltlessengineer committed Sep 14, 2024
1 parent 6edb8fd commit 3bf17a2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lua/rest-nvim/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions lua/rest-nvim/ui/result.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions plugin/rest-nvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions queries/rest_nvim_result/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; inherits http
1 change: 1 addition & 0 deletions queries/rest_nvim_result/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; inherits http
1 change: 1 addition & 0 deletions queries/rest_nvim_result/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; inherits http

0 comments on commit 3bf17a2

Please sign in to comment.