begin rebuild of config to separate files
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
local env = require 'env'
|
||||
|
||||
-- Telescope picker as a function, loaded on first use
|
||||
local function pick(name)
|
||||
return function()
|
||||
require('telescope.builtin')[name]()
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
-- Lua LSP help for Neovim's own API; also wired into completion (plugins/completion.lua)
|
||||
'folke/lazydev.nvim',
|
||||
ft = 'lua',
|
||||
opts = {
|
||||
library = { { path = '${3rd}/luv/library', words = { 'vim%.uv' } } },
|
||||
},
|
||||
},
|
||||
{
|
||||
'neovim/nvim-lspconfig', -- ships the default per-server configs that vim.lsp.config() builds on
|
||||
dependencies = {
|
||||
{ 'mason-org/mason.nvim', opts = {} },
|
||||
'mason-org/mason-lspconfig.nvim',
|
||||
'WhoIsSethDaniel/mason-tool-installer.nvim',
|
||||
{ 'j-hui/fidget.nvim', opts = {} },
|
||||
'saghen/blink.cmp',
|
||||
},
|
||||
config = function()
|
||||
-- Buffer-local keymaps and cursor-word highlighting, once a server attaches
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('user-lsp-attach', { clear = true }),
|
||||
callback = function(event)
|
||||
local function map(keys, func, desc, mode)
|
||||
vim.keymap.set(mode or 'n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
|
||||
end
|
||||
|
||||
map('gd', pick 'lsp_definitions', '[G]oto [D]efinition')
|
||||
map('gr', pick 'lsp_references', '[G]oto [R]eferences')
|
||||
map('gI', pick 'lsp_implementations', '[G]oto [I]mplementation')
|
||||
map('<leader>D', pick 'lsp_type_definitions', 'Type [D]efinition')
|
||||
map('<leader>ds', pick 'lsp_document_symbols', '[D]ocument [S]ymbols')
|
||||
map('<leader>ws', pick 'lsp_dynamic_workspace_symbols', '[W]orkspace [S]ymbols')
|
||||
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
||||
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
|
||||
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') -- in C this is the header
|
||||
|
||||
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
||||
if client and client:supports_method('textDocument/documentHighlight', event.buf) then
|
||||
local highlight_group = vim.api.nvim_create_augroup('user-lsp-highlight', { clear = false })
|
||||
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
|
||||
buffer = event.buf,
|
||||
group = highlight_group,
|
||||
callback = vim.lsp.buf.document_highlight,
|
||||
})
|
||||
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
|
||||
buffer = event.buf,
|
||||
group = highlight_group,
|
||||
callback = vim.lsp.buf.clear_references,
|
||||
})
|
||||
vim.api.nvim_create_autocmd('LspDetach', {
|
||||
group = vim.api.nvim_create_augroup('user-lsp-detach', { clear = true }),
|
||||
callback = function(event2)
|
||||
vim.lsp.buf.clear_references()
|
||||
vim.api.nvim_clear_autocmds { group = 'user-lsp-highlight', buffer = event2.buf }
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if client and client:supports_method('textDocument/inlayHint', event.buf) then
|
||||
map('<leader>th', function()
|
||||
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
|
||||
end, '[T]oggle Inlay [H]ints')
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.diagnostic.config {
|
||||
severity_sort = true,
|
||||
float = { border = 'rounded', source = 'if_many' },
|
||||
underline = { severity = vim.diagnostic.severity.ERROR },
|
||||
signs = vim.g.have_nerd_font and {
|
||||
text = {
|
||||
[vim.diagnostic.severity.ERROR] = ' ',
|
||||
[vim.diagnostic.severity.WARN] = ' ',
|
||||
[vim.diagnostic.severity.INFO] = ' ',
|
||||
[vim.diagnostic.severity.HINT] = ' ',
|
||||
},
|
||||
} or {},
|
||||
virtual_text = { source = 'if_many', spacing = 2 },
|
||||
}
|
||||
|
||||
-- Every server gets blink.cmp's completion capabilities
|
||||
vim.lsp.config('*', { capabilities = require('blink.cmp').get_lsp_capabilities() })
|
||||
|
||||
-- Servers: lua/servers/init.lua is the list, lua/servers/<name>.lua holds overrides.
|
||||
local wanted = {}
|
||||
for _, server in ipairs(require 'servers') do
|
||||
local name = server[1]
|
||||
if env.has_all(server.requires) then
|
||||
if server.custom then
|
||||
vim.lsp.config(name, require('servers.' .. name))
|
||||
end
|
||||
table.insert(wanted, name)
|
||||
end
|
||||
end
|
||||
|
||||
-- Enable whatever is already runnable (system packages, a previous mason install).
|
||||
-- Servers mason installs during this session are enabled by mason-lspconfig below.
|
||||
for _, name in ipairs(wanted) do
|
||||
local cmd = vim.lsp.config[name] and vim.lsp.config[name].cmd
|
||||
if type(cmd) == 'function' or (type(cmd) == 'table' and env.has(cmd[1])) then
|
||||
vim.lsp.enable(name)
|
||||
end
|
||||
end
|
||||
|
||||
if env.minimal then
|
||||
return
|
||||
end
|
||||
|
||||
-- Formatters and tools that are not language servers. tree-sitter-cli is needed by
|
||||
-- nvim-treesitter's main branch to build parsers.
|
||||
local tools = { 'stylua', 'tree-sitter-cli' }
|
||||
if env.has 'python3' then
|
||||
vim.list_extend(tools, { 'clang-format' })
|
||||
end
|
||||
vim.list_extend(tools, { 'shfmt' })
|
||||
|
||||
require('mason-tool-installer').setup { ensure_installed = tools }
|
||||
require('mason-lspconfig').setup {
|
||||
ensure_installed = wanted,
|
||||
automatic_enable = true, -- enable servers as soon as mason finishes installing them
|
||||
}
|
||||
end,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user