Skip to content

Commit

Permalink
deletes placeholder extmarks partially solving #11
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdsk committed Sep 5, 2021
1 parent 8c55402 commit faa3cba
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/prosesitter/on_event/check/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function M.cancelled_schedualled()
end

function M.schedual()
local timeout_ms = 800
local timeout_ms = 500 -- was 800
job = vim.defer_fn(do_check, timeout_ms)
end

Expand Down
37 changes: 36 additions & 1 deletion lua/prosesitter/on_event/marks/marks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,30 @@ local function remove_marks(buf, row)
end
end

local function nvim_buf_set_extmark_traced(buf_id, ns_marks, row, col, opt)
local ok, val = pcall(api.nvim_buf_set_extmark, buf_id, ns_marks, row, col, opt)
if not ok then
log.fatal(
"could not place extmark"
.. "\nbuf_id: "
.. vim.inspect(buf_id)
.. "\nrow: "
.. vim.inspect(row)
.. "\ncol_start: "
.. vim.inspect(col)
.. "\ncol_end: "
.. vim.inspect(opt.end_col)
)
end
return ok, val
end

function M.mark_results(results, areas)
local last_clear_row = -1
for hl in res.hl_iter(results, areas) do
local mark = api.nvim_buf_get_extmark_by_id(hl.buf_id, ns_placeholders, hl.row_id, { details = true })
if mark[1] == nil then goto continue end

local row = mark[1]
local col_offset = mark[2]

Expand All @@ -30,8 +50,23 @@ function M.mark_results(results, areas)
end_col = col_offset + hl.end_col - 1,
hl_group = hl.group,
}
local mark_id = api.nvim_buf_set_extmark(hl.buf_id, ns_marks, row, col_offset + hl.start_col - 2, opt)
local ok, mark_id = nvim_buf_set_extmark_traced(hl.buf_id, ns_marks, row, col_offset + hl.start_col - 2, opt)
if not ok then
log.fatal("mask_id: "..mark_id)
log.fatal("mark: "..vim.inspect(mark))
log.fatal("hl: "..vim.inspect(hl))
end
mark_to_hover[mark_id] = hl.hover_txt
::continue::
end
end

function M.remove_placeholders(buf, start_row, up_to_row)
local start = {start_row, 0}
local up_to = {up_to_row, -1}
local marks = api.nvim_buf_get_extmarks(buf, ns_placeholders, start, up_to, {})
for _, mark in ipairs(marks) do
api.nvim_buf_del_extmark(buf, ns_placeholders, mark[1])
end
end

Expand Down
3 changes: 2 additions & 1 deletion lua/prosesitter/on_event/on_event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local get_parser = vim.treesitter.get_parser
local api = vim.api
local M = {}


local function node_in_range(A, B, node)
local a, _, b, _ = node:range()
if a <= B and b >= A then -- TODO sharpen bounds
Expand Down Expand Up @@ -37,6 +36,7 @@ local function get_nodes(bufnr, cfg, start_l, end_l)

for _, node in prose_query:iter_captures(root_node, bufnr, start_l, end_l + 1) do
if node_in_range(start_l, end_l, node) then
log.info("")
nodes[key(node)] = node
end
end
Expand Down Expand Up @@ -80,6 +80,7 @@ function M.on_lines(_, buf, _, first_changed, last_changed, last_updated, _, _,
-- do not clean up extmarks, they are still needed in case of undo
local lines_removed = first_changed == last_updated
if lines_removed then
marks.remove_placeholders(buf, first_changed, last_changed)
return
end

Expand Down
2 changes: 1 addition & 1 deletion lua/prosesitter/shared.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local M = {}

local default_query = [[
[(line_comment)+] @capture
[(line_comment)+ (block_comment)] @capture
]]
local rust_query = [[
[(line_comment)+ (block_comment) (string_literal)] @capture
Expand Down

0 comments on commit faa3cba

Please sign in to comment.