Skip to content

Commit 826118b

Browse files
fix: don't try to highlight over the last line
1 parent f16b420 commit 826118b

File tree

3 files changed

+8
-33
lines changed

3 files changed

+8
-33
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ local default_config = {
180180
},
181181
highlight = {
182182
enable = true,
183-
timeout = 250,
183+
timeout = 750,
184184
},
185185
}
186186
```

lua/rest-nvim/config/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ local default_config = {
130130
},
131131
highlight = {
132132
enable = true,
133-
timeout = 250,
133+
timeout = 750,
134134
},
135135
}
136136

lua/rest-nvim/utils.lua

+6-31
Original file line numberDiff line numberDiff line change
@@ -119,36 +119,6 @@ local transform = {
119119
utils.transform_time = transform.time
120120
utils.transform_size = transform.size
121121

122-
---Highlight a request
123-
---@param bufnr number Buffer handler ID
124-
---@param start number Request tree-sitter node start
125-
---@param end_ number Request tree-sitter node end
126-
---@param ns number rest.nvim Neovim namespace
127-
function utils.highlight(bufnr, start, end_, ns)
128-
local highlight = _G._rest_nvim.highlight
129-
local higroup = "IncSearch"
130-
local timeout = highlight.timeout
131-
132-
-- Clear buffer highlights
133-
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
134-
135-
-- Highlight request
136-
vim.highlight.range(
137-
bufnr,
138-
ns,
139-
higroup,
140-
{ start, 0 },
141-
{ end_, string.len(vim.fn.getline(end_)) }
142-
)
143-
144-
-- Clear buffer highlights again after timeout
145-
vim.defer_fn(function()
146-
if vim.api.nvim_buf_is_valid(bufnr) then
147-
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
148-
end
149-
end, timeout)
150-
end
151-
152122
---@param bufnr number
153123
---@param node TSNode
154124
---@param ns number
@@ -160,6 +130,11 @@ function utils.ts_highlight_node(bufnr, node, ns)
160130
local higroup = "IncSearch"
161131
local s_row, s_col = node:start()
162132
local e_row, e_col = node:end_()
133+
-- don't try to highlight over the last line
134+
if e_col == 0 then
135+
e_row = e_row - 1
136+
e_col = -1
137+
end
163138
vim.highlight.range(
164139
bufnr,
165140
ns,
@@ -187,7 +162,7 @@ function utils.ts_parse_source(source)
187162
else
188163
ts_parser = vim.treesitter.get_parser(source, "http")
189164
end
190-
return ts_parser, assert(ts_parser:parse({})[1])
165+
return ts_parser, assert(ts_parser:parse(false)[1])
191166
end
192167

193168
---@param node TSNode

0 commit comments

Comments
 (0)