From 1bcfbdaa2476cf8397b580d33f1c28ad1ad6f49f Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 5 Nov 2024 21:51:36 +0100 Subject: [PATCH] fix(api): better check in documentation and add types --- lua/care/init.lua | 2 +- lua/care/types/api.lua | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/care/init.lua b/lua/care/init.lua index f85d754..e8f984d 100644 --- a/lua/care/init.lua +++ b/lua/care/init.lua @@ -34,7 +34,7 @@ care.api = { return care.core and care.core.menu and care.core.menu:docs_visible() end, get_documentation = function() - return care.core.menu:docs_visible() + return (care.core and care.core.menu and care.core.menu:docs_visible()) and vim.api.nvim_buf_get_lines(care.core.menu.docs_window.buf, 0, -1, false) or {} end, diff --git a/lua/care/types/api.lua b/lua/care/types/api.lua index 56d337e..e6ac5e7 100644 --- a/lua/care/types/api.lua +++ b/lua/care/types/api.lua @@ -56,8 +56,12 @@ --- indicates the visible position in the menu. --- --- This is really useful to create shortcuts to certain entries like in the ---- [example in configuration recipes](/configuration_recipes#labels-and-shortcuts). +--- [Example usage](/configuration_recipes#labels-and-shortcuts). ---@field select_visible fun(index: integer): nil --- Indicated whether the menu is reversed --- Only relevant when using sorting direction "away-from-cursor" ---@field is_reversed fun(): boolean +--- Get the documentation of the currently selected entry. +--- Will return an empty table if no documentation is available. +--- [Example usage](/configuration_recipes#access-documentation) +---@field get_documentation fun(): string[]