From e177caa1c95bfd3f47ef017d21de29a9a7869de9 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Tue, 29 Oct 2024 12:20:24 -0400 Subject: [PATCH] Return nil from Infoview:get_line when the line doesn't exist. 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. --- lua/lean/infoview.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/lean/infoview.lua b/lua/lean/infoview.lua index bcebbd3d..c5e2e7d0 100644 --- a/lua/lean/infoview.lua +++ b/lua/lean/infoview.lua @@ -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.