2021-11-25 22:10:31 +01:00
|
|
|
USER = vim.fn.expand('$USER')
|
|
|
|
|
|
|
|
-- Language specific key mappings
|
|
|
|
--require('lang.keymappings')
|
|
|
|
|
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
|
|
|
|
require'lsp_signature'.on_attach(client)
|
|
|
|
|
|
|
|
local function buf_set_keymap(...)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
|
|
|
end
|
|
|
|
local function buf_set_option(...)
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, ...)
|
|
|
|
end
|
|
|
|
|
|
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
|
|
|
|
-- Mappings.
|
|
|
|
local opts = {noremap = true, silent = true}
|
|
|
|
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
|
|
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
|
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
|
|
|
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
2022-10-23 01:48:10 +02:00
|
|
|
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
|
|
|
|
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '[l', '<cmd>lua vim.diagnostic.show_line_diagnostics()<CR>', opts)
|
|
|
|
buf_set_keymap('n', ']l', '<cmd>lua vim.diagnostic.set_loclist()<CR>', opts)
|
2021-11-25 22:10:31 +01:00
|
|
|
buf_set_keymap('n', '<leader>law', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>lrw', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>llw', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>lt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>lrn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>lca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
|
|
|
|
|
|
-- Set some keybinds conditional on server capabilities
|
2022-10-23 01:48:10 +02:00
|
|
|
if client.server_capabilities.document_formatting then
|
2021-11-25 22:10:31 +01:00
|
|
|
buf_set_keymap("n", "<leader>lf",
|
|
|
|
"<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
|
2022-10-23 01:48:10 +02:00
|
|
|
elseif client.server_capabilities.document_range_formatting then
|
2021-11-25 22:10:31 +01:00
|
|
|
buf_set_keymap("n", "<leader>lf",
|
|
|
|
"<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Set autocommands conditional on server_capabilities
|
2022-10-23 01:48:10 +02:00
|
|
|
if client.server_capabilities.document_highlight then
|
2021-11-25 22:10:31 +01:00
|
|
|
vim.api.nvim_exec([[
|
|
|
|
hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
|
|
|
|
hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
|
|
|
|
hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
|
|
|
|
augroup lsp_document_highlight
|
|
|
|
autocmd! * <buffer>
|
|
|
|
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
|
|
|
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
|
|
|
augroup END
|
|
|
|
]], false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local nvim_lsp = require('lspconfig')
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
|
|
|
|
-- Code actions
|
|
|
|
capabilities.textDocument.codeAction = {
|
|
|
|
dynamicRegistration = true,
|
|
|
|
codeActionLiteralSupport = {
|
|
|
|
codeActionKind = {
|
|
|
|
valueSet = (function()
|
|
|
|
local res = vim.tbl_values(vim.lsp.protocol.CodeActionKind)
|
|
|
|
table.sort(res)
|
|
|
|
return res
|
|
|
|
end)()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
capabilities.textDocument.completion.completionItem.snippetSupport = true;
|
|
|
|
|
|
|
|
-- LSPs
|
2023-05-16 01:22:43 +02:00
|
|
|
local servers = {"vimls", "ocamllsp",}
|
2021-11-25 22:10:31 +01:00
|
|
|
for _, lsp in ipairs(servers) do
|
|
|
|
nvim_lsp[lsp].setup {capabilities = capabilities, on_attach = on_attach}
|
|
|
|
end
|
|
|
|
|
2023-05-16 01:22:43 +02:00
|
|
|
nvim_lsp.pyright.setup({
|
|
|
|
on_attach = on_attach,
|
|
|
|
})
|
|
|
|
|
2023-05-14 00:26:04 +02:00
|
|
|
nvim_lsp.ruff_lsp.setup({
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
init_options = {
|
|
|
|
settings = {
|
|
|
|
-- Any extra CLI arguments for `ruff` go here.
|
|
|
|
args = {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-02-24 22:46:53 +01:00
|
|
|
nvim_lsp.rust_analyzer.setup({
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
imports = {
|
|
|
|
granularity = {
|
|
|
|
group = "module",
|
|
|
|
},
|
|
|
|
prefix = "self",
|
|
|
|
},
|
|
|
|
cargo = {
|
|
|
|
buildScripts = {
|
|
|
|
enable = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
procMacro = {
|
|
|
|
enable = true
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-11-25 22:10:31 +01:00
|
|
|
-- symbols-outline.nvim
|
|
|
|
vim.g.symbols_outline = {
|
|
|
|
highlight_hovered_item = true,
|
|
|
|
show_guides = true,
|
|
|
|
auto_preview = false, -- experimental
|
|
|
|
position = 'right',
|
|
|
|
keymaps = {
|
|
|
|
close = "<Esc>",
|
|
|
|
goto_location = "<Cr>",
|
|
|
|
focus_location = "o",
|
|
|
|
hover_symbol = "<C-space>",
|
|
|
|
rename_symbol = "r",
|
|
|
|
code_actions = "a"
|
|
|
|
},
|
|
|
|
lsp_blacklist = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
-- LSP Enable diagnostics
|
|
|
|
vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
|
|
|
vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
|
|
|
virtual_text = false,
|
|
|
|
underline = true,
|
|
|
|
signs = true,
|
|
|
|
update_in_insert = false
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Send diagnostics to quickfix list
|
|
|
|
do
|
|
|
|
local method = "textDocument/publishDiagnostics"
|
|
|
|
local default_handler = vim.lsp.handlers[method]
|
|
|
|
vim.lsp.handlers[method] = function(err, method, result, client_id, bufnr,
|
|
|
|
config)
|
|
|
|
default_handler(err, method, result, client_id, bufnr, config)
|
2022-10-23 01:48:10 +02:00
|
|
|
local diagnostics = vim.diagnostic.get()
|
2021-11-25 22:10:31 +01:00
|
|
|
local qflist = {}
|
|
|
|
for bufnr, diagnostic in pairs(diagnostics) do
|
|
|
|
for _, d in ipairs(diagnostic) do
|
|
|
|
d.bufnr = bufnr
|
|
|
|
d.lnum = d.range.start.line + 1
|
|
|
|
d.col = d.range.start.character + 1
|
|
|
|
d.text = d.message
|
|
|
|
table.insert(qflist, d)
|
|
|
|
end
|
|
|
|
end
|
2022-10-23 01:48:10 +02:00
|
|
|
-- setqflist(qflist)
|
2021-11-25 22:10:31 +01:00
|
|
|
end
|
|
|
|
end
|