repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
neovim/lua/bugabinga/lsp/commands.lua
Rawlocal user_command = require 'std.user_command'
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 = {}
local seen = {}
for _, client in ipairs( clients ) do
if not seen[client.name] then
seen[client.name] = true
names[#names + 1] = client.name
end
end
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()
local clients = vim.lsp.get_clients()
local seen = {}
local names = {}
for _, client in ipairs( clients ) do
if not seen[client.name] then
seen[client.name] = true
names[#names + 1] = client.name
end
end
return names
end,
})( restart_clients )
user_command.LspReload 'Reload current lsp server and buffer' ( function()
local clients = vim.lsp.get_clients { bufnr = 0 }
local names = {}
local seen = {}
for _, client in ipairs( clients ) do
if not seen[client.name] then
seen[client.name] = true
names[#names + 1] = client.name
end
end
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 basic info about running LSP servers in a popup' ( function()
require 'bugabinga.lsp.info'.show( vim.lsp.get_clients() )
end )