rework(preview): Ask providers for hover info

Now lsp checks if client supports hover
Addresses #82
This commit is contained in:
simrat39
2021-11-24 21:44:23 -08:00
parent 552b67993e
commit f4f2b5edfb
5 changed files with 251 additions and 207 deletions

View File

@@ -1,21 +1,30 @@
local M = {}
function M.should_use_provider(_)
local coc_installed = vim.fn.exists("*CocActionAsync")
local coc_installed = vim.fn.exists("*CocActionAsync")
if coc_installed == 0 then return end
if coc_installed == 0 then
return
end
local coc_attached = vim.fn.call('CocAction', {'ensureDocument'})
local has_symbols = vim.fn.call('CocHasProvider', {'documentSymbol'})
local coc_attached = vim.fn.call("CocAction", { "ensureDocument" })
local has_symbols = vim.fn.call("CocHasProvider", { "documentSymbol" })
return coc_attached and has_symbols;
return coc_attached and has_symbols
end
function M.hover_info(_, _, on_info)
on_info(nil, { contents = { kind = "markdown", contents = { "No extra information availaible!" } } })
end
---@param on_symbols function
function M.request_symbols(on_symbols)
vim.fn.call('CocActionAsync', {'documentSymbols', function (_, symbols)
on_symbols{[1000000]={result=symbols}}
end})
vim.fn.call("CocActionAsync", {
"documentSymbols",
function(_, symbols)
on_symbols({ [1000000] = { result = symbols } })
end,
})
end
return M

View File

@@ -1,34 +1,35 @@
local M = {}
local providers = {
'symbols-outline/providers/nvim-lsp',
'symbols-outline/providers/coc',
'symbols-outline/providers/markdown'
"symbols-outline/providers/nvim-lsp",
"symbols-outline/providers/coc",
"symbols-outline/providers/markdown",
}
local current_provider;
_G._symbols_outline_current_provider = nil
function M.has_provider()
local ret = false;
for _, value in ipairs(providers) do
local provider = require(value)
if provider.should_use_provider(0) then
ret = true;
break
end
end
return ret
local ret = false
for _, value in ipairs(providers) do
local provider = require(value)
if provider.should_use_provider(0) then
ret = true
break
end
end
return ret
end
---@param on_symbols function
function M.request_symbols(on_symbols)
for _, value in ipairs(providers) do
local provider = require(value)
if provider.should_use_provider(0) then
provider.request_symbols(on_symbols)
break
end
end
for _, value in ipairs(providers) do
local provider = require(value)
if provider.should_use_provider(0) then
_G._symbols_outline_current_provider = provider
provider.request_symbols(on_symbols)
break
end
end
end
return M

View File

@@ -1,15 +1,19 @@
local md_parser = require('symbols-outline.markdown')
local md_parser = require("symbols-outline.markdown")
local M = {}
-- probably change this
function M.should_use_provider(bufnr)
return vim.api.nvim_buf_get_option(bufnr, 'ft') == 'markdown'
return vim.api.nvim_buf_get_option(bufnr, "ft") == "markdown"
end
function M.hover_info(_, _, on_info)
on_info(nil, { contents = { kind = "markdown", contents = { "No extra information availaible!" } } })
end
---@param on_symbols function
function M.request_symbols(on_symbols)
on_symbols(md_parser.handle_markdown())
on_symbols(md_parser.handle_markdown())
end
return M

View File

@@ -1,35 +1,57 @@
local config = require('symbols-outline.config')
local config = require("symbols-outline.config")
local M = {}
local function getParams()
return {textDocument = vim.lsp.util.make_text_document_params()}
return { textDocument = vim.lsp.util.make_text_document_params() }
end
function M.hover_info(bufnr, params, on_info)
local clients = vim.lsp.buf_get_clients(bufnr)
local used_client
for id, client in pairs(clients) do
if config.is_client_blacklisted(id) then
goto continue
else
if client.server_capabilities.hoverProvider then
used_client = client
break
end
end
::continue::
end
if not used_client then
on_info(nil, { contents = { kind = "markdown", content = { "No extra information availaible!" } } })
end
used_client.request("textDocument/hover", params, on_info, bufnr)
end
-- probably change this
function M.should_use_provider(bufnr)
local clients = vim.lsp.buf_get_clients(bufnr)
local ret = false
local clients = vim.lsp.buf_get_clients(bufnr)
local ret = false
for id, client in pairs(clients) do
if config.is_client_blacklisted(id) then
goto continue
else
if client.server_capabilities.documentSymbolProvider then
ret = true
break
end
end
::continue::
end
for id, client in pairs(clients) do
if config.is_client_blacklisted(id) then
goto continue
else
if client.server_capabilities.documentSymbolProvider then
ret = true
break
end
end
::continue::
end
return ret
return ret
end
---@param on_symbols function
function M.request_symbols(on_symbols)
vim.lsp.buf_request_all(0, "textDocument/documentSymbol", getParams(),
on_symbols)
vim.lsp.buf_request_all(0, "textDocument/documentSymbol", getParams(), on_symbols)
end
return M