repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
neovim/lua/bugabinga/lsp_info.lua
RawFile outline
local icon = require 'std.icon'
local table = require 'std.table'
local cap_fields = {
hoverProvider = 'Hover',
definitionProvider = 'Go to Definition',
referencesProvider = 'References',
completionProvider = 'Completion',
renameProvider = 'Rename',
codeActionProvider = 'Code Actions',
documentFormattingProvider = 'Formatting',
documentSymbolProvider = 'Document Symbols',
workspaceSymbolProvider = 'Workspace Symbols',
inlayHintProvider = 'Inlay Hints',
semanticTokensProvider = 'Semantic Tokens',
signatureHelpProvider = 'Signature Help',
declarationProvider = 'Go to Declaration',
typeDefinitionProvider = 'Go to Type Definition',
implementationProvider = 'Go to Implementation',
documentHighlightProvider = 'Document Highlight',
codeLensProvider = 'Code Lens',
documentLinkProvider = 'Document Links',
foldingRangeProvider = 'Folding Range',
selectionRangeProvider = 'Selection Range',
callHierarchyProvider = 'Call Hierarchy',
documentRangeFormattingProvider = 'Range Formatting',
documentOnTypeFormattingProvider = 'On-Type Formatting',
diagnosticProvider = 'Pull Diagnostics',
executeCommandProvider = 'Execute Command',
}
local function show(clients)
if #clients == 0 then
vim.notify('No active LSP clients', vim.log.levels.INFO)
return
end
local buf = vim.api.nvim_create_buf(false, true)
local width = math.floor(vim.o.columns * 0.8)
local height = math.floor(vim.o.lines * 0.8)
local row = math.floor((vim.o.lines - height) / 2)
local col = math.floor((vim.o.columns - width) / 2)
local win = vim.api.nvim_open_win(buf, true, {
relative = 'editor',
width = width,
height = height,
row = row,
col = col,
style = 'minimal',
border = 'rounded',
title = icon.lsp .. ' LSP Info',
title_pos = 'center',
})
local lines = {}
for i, client in ipairs(clients) do
if i > 1 then table.insert(lines, '') end
table.insert(lines, string.format('# %s %s', icon.lsp, client.name))
local root = client.config.root_dir or 'No root'
table.insert(lines, string.format('**Root:** %s', root))
if client.config.filetypes then
table.insert(lines, string.format('**Filetypes:** %s', table.concat(client.config.filetypes, ', ')))
end
table.insert(lines, string.format('**ID:** %d', client.id))
local cmd = client.config.cmd
if type(cmd) == 'table' and cmd[1] then
table.insert(lines, string.format('**Binary:** %s', cmd[1]))
end
if client.workspace_folders and #client.workspace_folders > 0 then
table.insert(lines, '**Workspace Folders:**')
for _, wf in ipairs(client.workspace_folders) do
table.insert(lines, string.format(' - %s', wf.name))
end
end
local caps = client.server_capabilities
local cap_list = {}
for field, name in pairs(cap_fields) do
if caps[field] then cap_list[#cap_list + 1] = name end
end
table.insert(lines, string.format('**Capabilities (%d):**', #cap_list))
table.insert(lines, ' ' .. table.concat(cap_list, ', '))
if client.server_info and client.server_info.version then
table.insert(lines, string.format('**Version:** %s', client.server_info.version))
end
end
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
vim.api.nvim_buf_set_option(buf, 'spell', false)
vim.api.nvim_buf_set_option(buf, 'wrap', true)
vim.api.nvim_buf_set_option(buf, 'readonly', true)
vim.api.nvim_buf_set_option(buf, 'modifiable', false)
vim.api.nvim_buf_set_keymap(buf, 'n', 'q', '<cmd>close<CR>', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(buf, 'n', '<Esc>', '<cmd>close<CR>', { noremap = true, silent = true })
vim.api.nvim_set_current_win(win)
end
return { show = show }