aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/ui/init.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-10-25 14:55:47 +0200
committerGitHub <noreply@github.com>2021-10-25 14:55:47 +0200
commitf60d78a29fbe772e0724ee0853a13894b9765fdf (patch)
treeadf8fd822587d779c5b90d5ed30987a982fd497e /lua/nvim-lsp-installer/ui/init.lua
parentfix :LspPrintInstalled (diff)
downloadmason-f60d78a29fbe772e0724ee0853a13894b9765fdf.tar
mason-f60d78a29fbe772e0724ee0853a13894b9765fdf.tar.gz
mason-f60d78a29fbe772e0724ee0853a13894b9765fdf.tar.bz2
mason-f60d78a29fbe772e0724ee0853a13894b9765fdf.tar.lz
mason-f60d78a29fbe772e0724ee0853a13894b9765fdf.tar.xz
mason-f60d78a29fbe772e0724ee0853a13894b9765fdf.tar.zst
mason-f60d78a29fbe772e0724ee0853a13894b9765fdf.zip
add proper emmylua annotations (#196)
Diffstat (limited to 'lua/nvim-lsp-installer/ui/init.lua')
-rw-r--r--lua/nvim-lsp-installer/ui/init.lua73
1 files changed, 48 insertions, 25 deletions
diff --git a/lua/nvim-lsp-installer/ui/init.lua b/lua/nvim-lsp-installer/ui/init.lua
index 4f8d6935..b40c0c47 100644
--- a/lua/nvim-lsp-installer/ui/init.lua
+++ b/lua/nvim-lsp-installer/ui/init.lua
@@ -1,83 +1,106 @@
local Data = require "nvim-lsp-installer.data"
local M = {}
-M.NodeType = Data.enum {
- "NODE",
- "CASCADING_STYLE",
- "VIRTUAL_TEXT",
- "HL_TEXT",
- "KEYBIND_HANDLER",
-}
+---@alias NodeType
+---| '"NODE"'
+---| '"CASCADING_STYLE"'
+---| '"VIRTUAL_TEXT"'
+---| '"HL_TEXT"'
+---| '"KEYBIND_HANDLER"'
+---@alias INode Node | HlTextNode | CascadingStyleNode | VirtualTextNode | KeybindHandlerNode
+
+---@param children INode[]
function M.Node(children)
- return {
- type = M.NodeType.NODE,
+ ---@class Node
+ local node = {
+ type = "NODE",
children = children,
}
+ return node
end
+---@param lines_with_span_tuples string[][]|string[]
function M.HlTextNode(lines_with_span_tuples)
if type(lines_with_span_tuples[1]) == "string" then
-- this enables a convenience API for just rendering a single line (with just a single span)
lines_with_span_tuples = { { lines_with_span_tuples } }
end
- return {
- type = M.NodeType.HL_TEXT,
+ ---@class HlTextNode
+ local node = {
+ type = "HL_TEXT",
lines = lines_with_span_tuples,
}
+ return node
end
+---@param lines string[]
function M.Text(lines)
return M.HlTextNode(Data.list_map(function(line)
return { { line, "" } }
end, lines))
end
-M.CascadingStyle = Data.enum {
- "INDENT",
- "CENTERED",
-}
+---@alias CascadingStyle
+---| '"INDENT"'
+---| '"CENTERED"'
+---@param styles CascadingStyle[]
+---@param children INode[]
function M.CascadingStyleNode(styles, children)
- return {
- type = M.NodeType.CASCADING_STYLE,
+ ---@class CascadingStyleNode
+ local node = {
+ type = "CASCADING_STYLE",
styles = styles,
children = children,
}
+ return node
end
+---@param virt_text string[][] @List of (text, highlight) tuples.
function M.VirtualTextNode(virt_text)
- return {
- type = M.NodeType.VIRTUAL_TEXT,
+ ---@class VirtualTextNode
+ local node = {
+ type = "VIRTUAL_TEXT",
virt_text = virt_text,
}
+ return node
end
-function M.When(condition, a)
+---@param condition boolean
+---@param node INode | fun(): INode
+function M.When(condition, node)
if condition then
- if type(a) == "function" then
- return a()
+ if type(node) == "function" then
+ return node()
else
- return a
+ return node
end
end
return M.Node {}
end
+---@param key string @The keymap to register to. Example: "<CR>".
+---@param effect string @The effect to call when keymap is triggered by the user.
+---@param payload any @The payload to pass to the effect handler when triggered.
+---@param is_global boolean @Whether to register the keybind to apply on all lines in the buffer.
function M.Keybind(key, effect, payload, is_global)
- return {
- type = M.NodeType.KEYBIND_HANDLER,
+ ---@class KeybindHandlerNode
+ local node = {
+ type = "KEYBIND_HANDLER",
key = key,
effect = effect,
payload = payload,
is_global = is_global or false,
}
+ return node
end
function M.EmptyLine()
return M.Text { "" }
end
+---@param rows string[][][] @A list of rows to include in the table. Each row consists of an array of (text, highlight) tuples (aka spans).
function M.Table(rows)
local col_maxwidth = {}
for i = 1, #rows do