From a7ba30f8d545ab0fd181e0f4fb84544ef9f236ac Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 13 Feb 2023 16:30:20 +0200 Subject: [PATCH] fix: define `update` function before usage, fixes #7 --- lua/docs-view.lua | 72 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/lua/docs-view.lua b/lua/docs-view.lua index 37112ca..4500068 100644 --- a/lua/docs-view.lua +++ b/lua/docs-view.lua @@ -3,6 +3,42 @@ local cfg = {} local buf, win, prev_win, autocmd local get_clients +local function update() + if not win or not vim.api.nvim_win_is_valid(win) then + toggle() + end + + local clients = get_clients() + local gotHover = false + for i = 1, #clients do + if clients[i].supports_method("textDocument/hover") then + gotHover = true + break + end + end + if not gotHover then + return + end + + local l, c = unpack(vim.api.nvim_win_get_cursor(0)) + vim.lsp.buf_request(0, "textDocument/hover", { + textDocument = { uri = "file://" .. vim.api.nvim_buf_get_name(0) }, + position = { line = l - 1, character = c }, + }, function(err, result, ctx, config) + if win and vim.api.nvim_win_is_valid(win) and result and result.contents then + local md_lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents) + md_lines = vim.lsp.util.trim_empty_lines(md_lines) + if vim.tbl_isempty(md_lines) then + return + end + + vim.api.nvim_buf_set_option(buf, "modifiable", true) + vim.lsp.util.stylize_markdown(buf, md_lines) + vim.api.nvim_buf_set_option(buf, "modifiable", false) + end + end) +end + local function toggle() if win and vim.api.nvim_win_is_valid(win) then vim.api.nvim_win_close(win, false) @@ -65,42 +101,6 @@ local function toggle() end end -local function update() - if not win or not vim.api.nvim_win_is_valid(win) then - toggle() - end - - local clients = get_clients() - local gotHover = false - for i = 1, #clients do - if clients[i].supports_method("textDocument/hover") then - gotHover = true - break - end - end - if not gotHover then - return - end - - local l, c = unpack(vim.api.nvim_win_get_cursor(0)) - vim.lsp.buf_request(0, "textDocument/hover", { - textDocument = { uri = "file://" .. vim.api.nvim_buf_get_name(0) }, - position = { line = l - 1, character = c }, - }, function(err, result, ctx, config) - if win and vim.api.nvim_win_is_valid(win) and result and result.contents then - local md_lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents) - md_lines = vim.lsp.util.trim_empty_lines(md_lines) - if vim.tbl_isempty(md_lines) then - return - end - - vim.api.nvim_buf_set_option(buf, "modifiable", true) - vim.lsp.util.stylize_markdown(buf, md_lines) - vim.api.nvim_buf_set_option(buf, "modifiable", false) - end - end) -end - M.setup = function(user_cfg) local default_cfg = { position = "right",