ref: Annotations

This commit is contained in:
danymat
2022-02-08 09:57:47 +01:00
parent 851285aae9
commit 533cd3d389

View File

@@ -3,6 +3,8 @@ local mark = {}
local api = vim.api local api = vim.api
local ns = api.nvim_create_namespace("neogen") local ns = api.nvim_create_namespace("neogen")
--- Start marks creation and get useful informations
---@private
mark.start = function(self) mark.start = function(self)
if self.started then if self.started then
mark:stop() mark:stop()
@@ -17,11 +19,18 @@ mark.start = function(self)
self.started = true self.started = true
end end
--- Get a mark specified with i index
---@param i number
---@private
mark.get_mark = function(self, i) mark.get_mark = function(self, i)
local id = self.ids[i] local id = self.ids[i]
return api.nvim_buf_get_extmark_by_id(self.bufnr, ns, id, {}) return api.nvim_buf_get_extmark_by_id(self.bufnr, ns, id, {})
end end
--- Add a mark with position
---@param pos table Position as line, col
---@return number the id of the inserted mark
---@private
mark.add_mark = function(self, pos) mark.add_mark = function(self, pos)
local line, col = unpack(pos) local line, col = unpack(pos)
local id = api.nvim_buf_set_extmark(self.bufnr, ns, line, col, {}) local id = api.nvim_buf_set_extmark(self.bufnr, ns, line, col, {})
@@ -29,10 +38,17 @@ mark.add_mark = function(self, pos)
return id return id
end end
--- Get how many marks are created
---@return number
---@private
mark.mark_len = function(self) mark.mark_len = function(self)
return #self.ids return #self.ids
end end
--- Verify if the marks can be jumpable
---@param reverse boolean
---@return boolean
---@private
mark.jumpable = function(self, reverse) mark.jumpable = function(self, reverse)
if not self.started then if not self.started then
return false return false
@@ -49,6 +65,9 @@ mark.jumpable = function(self, reverse)
return ret return ret
end end
--- Jump to next/previous mark if possible
---@param reverse boolean
---@private
mark.jump = function(self, reverse) mark.jump = function(self, reverse)
if mark:jumpable(reverse) then if mark:jumpable(reverse) then
self.index = reverse and self.index - 1 or self.index + 1 self.index = reverse and self.index - 1 or self.index + 1
@@ -63,6 +82,8 @@ mark.jump = function(self, reverse)
end end
end end
--- Clear marks and stop jumping ability
---@private
mark.stop = function(self, should_jump) mark.stop = function(self, should_jump)
local bufnr = self.bufnr local bufnr = self.bufnr
if bufnr and bufnr > 0 and api.nvim_buf_is_valid(bufnr) then if bufnr and bufnr > 0 and api.nvim_buf_is_valid(bufnr) then