Files
outline.nvim/lua/outline/providers/nvim-lsp.lua
hedy 965a3842c8 MAJOR: Project rename and preparation for v1.0.0
I hope I haven't missed any for the renames!
2023-11-12 12:40:32 +08:00

85 lines
1.8 KiB
Lua

local config = require 'outline.config'
local lsp_utils = require 'outline.utils.lsp_utils'
local jsx = require 'outline.utils.jsx'
local M = {}
local function getParams()
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
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
end
function M.postprocess_symbols(response)
local symbols = lsp_utils.flatten_response(response)
local jsx_symbols = jsx.get_symbols()
if #jsx_symbols > 0 then
return lsp_utils.merge_symbols(symbols, jsx_symbols)
else
return symbols
end
end
---@param on_symbols function
function M.request_symbols(on_symbols, opts)
vim.lsp.buf_request_all(
0,
'textDocument/documentSymbol',
getParams(),
function (response)
response = M.postprocess_symbols(response)
on_symbols(response, opts)
end
)
end
return M