From 0050526934a4e94b11caf543776bc29a7162f072 Mon Sep 17 00:00:00 2001 From: fiplox Date: Tue, 27 Jun 2023 11:08:28 +0200 Subject: [PATCH] chore: move rust stuff to lsp --- ftplugin/rust.lua | 53 ---------------------------------------- lua/plugins/lsp/init.lua | 9 +++++++ 2 files changed, 9 insertions(+), 53 deletions(-) delete mode 100644 ftplugin/rust.lua diff --git a/ftplugin/rust.lua b/ftplugin/rust.lua deleted file mode 100644 index f9c8d26..0000000 --- a/ftplugin/rust.lua +++ /dev/null @@ -1,53 +0,0 @@ -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 has_formatter(ft) - local sources = require 'null-ls.sources' - local available = sources.get_available(ft, 'NULL_LS_FORMATTING') - return #available > 0 -end - -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 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, - standalone = false, - }, -} diff --git a/lua/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua index 02e0114..20da923 100644 --- a/lua/plugins/lsp/init.lua +++ b/lua/plugins/lsp/init.lua @@ -104,6 +104,15 @@ function M.config() -- vim.cmd "command! -buffer JdtJshell lua require('jdtls').jshell()" goto continue end + if server == 'rust_analyzer' then + require('rust-tools').setup { + server = { + on_attach = on_attach, + standalone = false, + }, + } + goto continue + end lspconfig[server].setup(opts) ::continue:: end