repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim/lua/bugabinga/lsp_info.lua

Raw
File outline
local icon = require 'std.icon'
local table = require 'std.table'

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))
		table.insert(lines, string.format('**ID:** %d', client.id))
		if client.rpc and client.rpc.pid then
			table.insert(lines, string.format('**PID:** %d', client.rpc.pid))
		end
		table.insert(lines, string.format('**Attached Buffers:** %d', #client.attached_buffers))
		if client.server_info and client.server_info.version then
			table.insert(lines, string.format('**Version:** %s', client.server_info.version))
		end
		table.insert(lines, '**Capabilities:**')
		local caps = client.server_capabilities
		local cap_list = {}
		if caps.hoverProvider then table.insert(cap_list, 'Hover') end
		if caps.definitionProvider then table.insert(cap_list, 'Definition') end
		if caps.referencesProvider then table.insert(cap_list, 'References') end
		if caps.completionProvider then table.insert(cap_list, 'Completion') end
		if caps.renameProvider then table.insert(cap_list, 'Rename') end
		if caps.codeActionProvider then table.insert(cap_list, 'Code Actions') end
		if caps.documentFormattingProvider then table.insert(cap_list, 'Formatting') end
		if caps.documentSymbolProvider then table.insert(cap_list, 'Document Symbols') end
		if caps.workspaceSymbolProvider then table.insert(cap_list, 'Workspace Symbols') end
		if caps.inlayHintProvider then table.insert(cap_list, 'Inlay Hints') end
		if caps.semanticTokensProvider then table.insert(cap_list, 'Semantic Tokens') end
		table.insert(lines, '  - ' .. table.concat(cap_list, ', '))
		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
	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, 'wrap', true)
	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 }