Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

neovim/lua/bugabinga/lsp/commands.lua

Raw
local user_command = require 'std.user_command'

local function client_names( clients )
	return vim.iter( clients )
		:map( function( client ) return client.name end )
		:unique()
		:totable()
end

local restart_clients = function( opts )
	local server = opts.args
	if server and server ~= '' then
		vim.lsp.enable( server, false )
		vim.lsp.enable( server, true )
		return
	end
	local clients = opts.bang and vim.lsp.get_clients() or vim.lsp.get_clients { bufnr = 0 }
	local names = client_names( clients )
	if #names == 0 then return end
	vim.lsp.enable( names, false )
	vim.lsp.enable( names, true )
end

user_command.LspRestart 'Restarts LSP servers' ({
	nargs = '?',
	bang = true,
	complete = function()
		return client_names( vim.lsp.get_clients() )
	end,
})( restart_clients )

user_command.LspReload 'Reload current lsp server and buffer' ( function()
	local clients = vim.lsp.get_clients { bufnr = 0 }
	local names = client_names( clients )
	if #names == 0 then return end
	vim.lsp.enable( names, false )
	vim.lsp.enable( names, true )
	vim.cmd.edit()
end )

user_command.LspCapabilities 'Show capabilities of currently running lsp server' ( function()
	local clients = vim.lsp.get_clients { bufnr = 0 }
	local client = clients[1]
	if not client then
		vim.notify( 'No LSP client attached to current buffer', vim.log.levels.WARN )
		return
	end
	vim.notify( vim.inspect( client.server_capabilities ) )
end )

user_command.LspConfig 'Show configuration of current lsp server' ( function()
	local clients = vim.lsp.get_clients { bufnr = 0 }
	local client = clients[1]
	if not client then
		vim.notify( 'No LSP client attached to current buffer', vim.log.levels.WARN )
		return
	end
	vim.notify( vim.inspect( client.config ) )
	vim.notify( vim.inspect( client.settings ) )
end )

user_command.LspInfo 'Show LSP health' ( function()
	vim.cmd.checkhealth 'vim.lsp'
end )