diff --git a/ftplugin/rust.lua b/ftplugin/rust.lua new file mode 100644 index 0000000..5a732c3 --- /dev/null +++ b/ftplugin/rust.lua @@ -0,0 +1,46 @@ +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) + +local function lsp_keymaps(bufnr) + local opt = { noremap = true, silent = true } + local keymap = vim.api.nvim_buf_set_keymap + keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opt) + keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opt) + keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opt) + keymap(bufnr, 'n', 'gI', 'lua vim.lsp.buf.implementation()', opt) + keymap(bufnr, 'n', 'gr', 'TroubleToggle lsp_references', opt) + keymap(bufnr, 'n', 'gl', 'lua vim.diagnostic.open_float()', opt) + keymap(bufnr, 'n', 'lf', 'lua vim.lsp.buf.format { async = true }', opt) + keymap(bufnr, 'n', 'li', 'LspInfo', opt) + keymap(bufnr, 'n', 'lI', 'LspInstallInfo', opt) + keymap(bufnr, 'n', 'la', 'lua vim.lsp.buf.code_action()', opt) + keymap(bufnr, 'n', 'lj', 'lua vim.diagnostic.goto_next({buffer=0})', opt) + keymap(bufnr, 'n', 'lk', 'lua vim.diagnostic.goto_prev({buffer=0})', opt) + keymap(bufnr, 'n', 'lr', 'lua vim.lsp.buf.rename()', opt) + keymap(bufnr, 'n', 'ls', 'lua vim.lsp.buf.signature_help()', opt) + keymap(bufnr, 'n', 'lq', 'lua vim.diagnostic.setloclist()', opt) + keymap(bufnr, 'n', 'e', 'lua vim.diagnostic.open_float()', 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 + if nls.has_formatter(ft) then + 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, + }, +} diff --git a/lua/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua index 02cb024..9c21d35 100644 --- a/lua/plugins/lsp/init.lua +++ b/lua/plugins/lsp/init.lua @@ -121,13 +121,6 @@ function M.config() require('lspconfig')[server].setup(opts) ::continue:: end, - ['rust_analyzer'] = function() - require('rust-tools').setup { - server = { - on_attach = on_attach, - } - } - end, } local config = {