2023-01-29 13:50:30 +01:00
|
|
|
local cmp_nvim_lsp = require 'cmp_nvim_lsp'
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
|
|
|
capabilities = cmp_nvim_lsp.default_capabilities(capabilities)
|
|
|
|
|
2023-04-08 23:47:10 +02:00
|
|
|
local function has_formatter(ft)
|
|
|
|
local sources = require 'null-ls.sources'
|
|
|
|
local available = sources.get_available(ft, 'NULL_LS_FORMATTING')
|
|
|
|
return #available > 0
|
|
|
|
end
|
|
|
|
|
2023-01-29 13:50:30 +01:00
|
|
|
local function lsp_keymaps(bufnr)
|
|
|
|
local opt = { noremap = true, silent = true }
|
|
|
|
local keymap = vim.api.nvim_buf_set_keymap
|
|
|
|
keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opt)
|
|
|
|
keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opt)
|
|
|
|
keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opt)
|
|
|
|
keymap(bufnr, 'n', 'gI', '<cmd>lua vim.lsp.buf.implementation()<CR>', opt)
|
|
|
|
keymap(bufnr, 'n', 'gr', '<cmd>TroubleToggle lsp_references<CR>', opt)
|
|
|
|
keymap(bufnr, 'n', 'gl', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>lf', '<cmd>lua vim.lsp.buf.format { async = true }<cr>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>li', '<cmd>LspInfo<cr>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>lI', '<cmd>LspInstallInfo<cr>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>la', '<cmd>lua vim.lsp.buf.code_action()<cr>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>lj', '<cmd>lua vim.diagnostic.goto_next({buffer=0})<cr>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>lk', '<cmd>lua vim.diagnostic.goto_prev({buffer=0})<cr>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>lr', '<cmd>lua vim.lsp.buf.rename()<cr>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>ls', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>lq', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt)
|
|
|
|
keymap(bufnr, 'n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
|
|
|
|
end
|
|
|
|
|
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
--[[ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') ]]
|
|
|
|
lsp_keymaps(bufnr)
|
|
|
|
local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype')
|
|
|
|
local nls = require 'plugins.null-ls'
|
|
|
|
|
|
|
|
local enable = false
|
2023-04-08 23:47:10 +02:00
|
|
|
if has_formatter(ft) then
|
2023-01-29 13:50:30 +01:00
|
|
|
enable = client.name == 'null-ls'
|
|
|
|
else
|
|
|
|
enable = not (client.name == 'null-ls')
|
|
|
|
end
|
|
|
|
|
|
|
|
client.server_capabilities.documentFormattingProvider = enable
|
|
|
|
end
|
|
|
|
require('rust-tools').setup {
|
|
|
|
server = {
|
|
|
|
on_attach = on_attach,
|
2023-02-21 21:48:42 +01:00
|
|
|
standalone = false,
|
2023-01-29 13:50:30 +01:00
|
|
|
},
|
|
|
|
}
|