From 418d884df5c7298c6d4722767483bf0994b71f84 Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Wed, 12 Apr 2023 21:28:49 -0700 Subject: [PATCH] updated --- after/plugin/lsp.lua | 54 +++++++++++++++++++++++-------------- after/plugin/rust-tools.lua | 32 ++++++++++++++++++++++ lua/zynh/packer.lua | 5 ++++ 3 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 after/plugin/rust-tools.lua diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index de60945..3e28f5f 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -2,21 +2,20 @@ local lsp = require('lsp-zero') lsp.preset('recommended') lsp.ensure_installed({ - 'tsserver', - 'eslint', - 'rust_analyzer', + 'tsserver', + 'eslint', 'lua_ls', }) lsp.nvim_workspace() local cmp = require('cmp') -local cmp_select = {behaviour = cmp.SelectBehavior.Select} +local cmp_select = { behaviour = cmp.SelectBehavior.Select } local cmp_mappings = lsp.defaults.cmp_mappings({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.complete(), + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.complete(), }) lsp.set_preferences({ @@ -30,20 +29,35 @@ lsp.set_preferences({ }) }) -lsp.on_attach(function(client, bufnr) - local opts = {buffer = bufnr, remap = false} +lsp.on_attach(function(_, bufnr) + local opts = { buffer = bufnr, remap = false } - vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) - vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) - vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) - vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) - vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) - vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) - vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) - vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) - vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) vim.keymap.set("n", "fd", function() vim.lsp.buf.format() end, opts) end) +lsp.skip_server_setup({"rust_analyzer"}) + +lsp_bindings = { + def = "gd", + hover = "K", + workspace_symbol = "vws", + goto_next = "[d", + goto_prev = "]d", + code_action = "vca", + references = "vrr", + rename = "vrr", + sig_help = "", + format = "fd", +} + lsp.setup() diff --git a/after/plugin/rust-tools.lua b/after/plugin/rust-tools.lua new file mode 100644 index 0000000..18129eb --- /dev/null +++ b/after/plugin/rust-tools.lua @@ -0,0 +1,32 @@ +local rt = require("rust-tools") + +rt.setup({ + server = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "K", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "ca", rt.code_action_group.code_action_group, { buffer = bufnr }) + + + local opts = { buffer = bufnr, remap = false } + + -- vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + -- vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + -- vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + -- vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + -- vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + -- vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + -- vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + -- vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + -- vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "fd", function() vim.lsp.buf.format() end, opts) + end, + }, + tools = { + hover_actions = { + auto_focus = true, + } + } +}) diff --git a/lua/zynh/packer.lua b/lua/zynh/packer.lua index da4f5e6..1724712 100644 --- a/lua/zynh/packer.lua +++ b/lua/zynh/packer.lua @@ -65,6 +65,11 @@ return require('packer').startup(function(use) } } + use { + 'simrat39/rust-tools.nvim', + after = 'lsp-zero.nvim' + } + use { "folke/which-key.nvim", config = function()