Skip to content

Commit

Permalink
Return nil from Infoview:get_line when the line doesn't exist.
Browse files Browse the repository at this point in the history
We currently only use this function in tests, and this produces a
potentially better error message than some vim out-of-bounds exception.

Eventually we'll have semantic methods instead.
  • Loading branch information
Julian committed Nov 1, 2024
1 parent e4d0e0d commit e177caa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lua/lean/infoview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,14 @@ end

---Retrieve a specific line from the infoview window.
---@param line number
---@return string? line the infoview contents at the given line
function Infoview:get_line(line)
return self:get_lines(line, line + 1)[1]
if not self.window then
error 'infoview is not open'
end

local lines = vim.api.nvim_buf_get_lines(self.info.__renderer.buf, line, line + 1, false)
return lines[1]
end

---Retrieve the contents of the diff window as a table.
Expand Down

0 comments on commit e177caa

Please sign in to comment.