From 642266466c6766c4397ed41bd35eaf12abbfdfce Mon Sep 17 00:00:00 2001 From: kjuulh Date: Wed, 12 Oct 2022 17:55:25 +0200 Subject: [PATCH] with keybinds --- lua/config/options.lua | 1 + lua/config/plugins.lua | 7 ++ lua/plugins/indent-blankline.lua | 4 +- lua/plugins/lsp/init.lua | 5 +- lua/plugins/lsp/keys.lua | 70 +++++++++++++++++ lua/plugins/rust-tools.lua | 125 +++++++++++++++++++++++++++++++ lua/plugins/terminal.lua | 7 ++ lua/plugins/toggleterm.lua | 17 +++++ 8 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 lua/plugins/lsp/keys.lua create mode 100644 lua/plugins/rust-tools.lua create mode 100644 lua/plugins/terminal.lua create mode 100644 lua/plugins/toggleterm.lua diff --git a/lua/config/options.lua b/lua/config/options.lua index d31072c..d9cab94 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -42,6 +42,7 @@ vim.opt.undofile = true vim.opt.undolevels = 10000 vim.opt.updatetime = 200 -- save swap file and trigger CursorHold vim.opt.wildmode = "longest:full,full" -- Command-line completion mode +vim.opt.completeopt = "menu,menuone,noselect" vim.opt.wrap = false -- Disable line wrap vim.opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" } vim.opt.fillchars = { diff --git a/lua/config/plugins.lua b/lua/config/plugins.lua index d123705..522b6c1 100644 --- a/lua/config/plugins.lua +++ b/lua/config/plugins.lua @@ -102,6 +102,8 @@ local function plugins(use, plugin) module = "mason-lspconfig", }) + plugin("simrat39/rust-tools.nvim") + -- Autocomplete plugin("hrsh7th/nvim-cmp") @@ -121,6 +123,10 @@ local function plugins(use, plugin) -- Utility plugin("windwp/nvim-autopairs") + -- Terminal + plugin("s1n7ax/nvim-terminal") + plugin("akinsho/toggleterm.nvim") + -- Yanking use({ "AckslD/nvim-neoclip.lua", @@ -177,6 +183,7 @@ local function plugins(use, plugin) use({ "folke/which-key.nvim", + branch = "mapping_dsl", module = "which-key", }) diff --git a/lua/plugins/indent-blankline.lua b/lua/plugins/indent-blankline.lua index 13f3ec1..a89cf28 100644 --- a/lua/plugins/indent-blankline.lua +++ b/lua/plugins/indent-blankline.lua @@ -6,8 +6,8 @@ function M.config() local indent = require("indent_blankline") --- PERF: debounce indent-blankline refresh - local refresh = indent.refresh - indent.refresh = require("util").debounce(100, refresh) + --local refresh = indent.refresh + --indent.refresh = require("util").debounce(100, refresh) indent.setup({ buftype_exclude = { "terminal", "nofile" }, diff --git a/lua/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua index d698e61..716c86a 100644 --- a/lua/plugins/lsp/init.lua +++ b/lua/plugins/lsp/init.lua @@ -14,7 +14,7 @@ function M.config() local function on_attach(client, bufnr) require("nvim-navic").attach(client, bufnr) require("plugins.lsp.formatting").setup(client, bufnr) - --require("plugins.lsp.keys").setup(client, bufnr) + require("plugins.lsp.keys").setup(client, bufnr) end ---@type lspconfig.options @@ -87,10 +87,9 @@ function M.config() on_attach = on_attach, capabilities = capabilities, flags = { - debounce_text_change = 150, + debounce_text_changes = 150, }, } - for server, opts in pairs(servers) do opts = vim.tbl_deep_extend("force", {}, options, opts or {}) require("lspconfig")[server].setup(opts) diff --git a/lua/plugins/lsp/keys.lua b/lua/plugins/lsp/keys.lua new file mode 100644 index 0000000..3c27c1c --- /dev/null +++ b/lua/plugins/lsp/keys.lua @@ -0,0 +1,70 @@ +local wk = require("which-key") + +local M = {} + +function M.setup(client, buffer) + local cap = client.server_capabilities + + local keymap = { + buffer = buffer, + [""] = { + c = { + name = "+code", + r = { + vim.lsp.buf.rename, + "Rename", + cond = cap.renameProvider, + }, + a = { + { vim.lsp.buf.code_action, "Code Action" }, + { "lua vim.lsp.buf.code_action()", "Code Action", mode = "v" }, + }, + f = { + { + require("plugins.lsp.formatting").format, + "Format Document", + cond = cap.documentFormatting, + }, + { + require("plugins.lsp.formatting").format, + "Format Range", + cond = cap.documentRangeFormatting, + mode = "v", + }, + }, + d = { vim.diagnostic.open_float, "Line Diagnostics" }, + l = { + name = "+lsp", + i = { "LspInfo", "Lsp Info" }, + a = { "lua vim.lsp.buf.add_workspace_folder()", "Add Folder" }, + r = { "lua vim.lsp.buf.remove_workspace_folder()", "Remove Folder" }, + l = { "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", "List Folders" }, + }, + }, + x = { + d = { "Telescope diagnostics", "Search Diagnostics" }, + }, + }, + g = { + name = "+goto", + d = { "Telescope lsp_definitions", "Goto Definition" }, + r = { "Telescope lsp_references", "References" }, + R = { "Trouble lsp_references", "Trouble References" }, + D = { "Telescope lsp_declarations", "Goto Declaration" }, + s = { "lua vim.lsp.buf.signature_help()", "Signature Help" }, + I = { "Telescope lsp_implementations", "Goto Implementation" }, + t = { "Telescope lsp_type_definitions", "Goto Type Definition" }, + }, + ["K"] = { "lua vim.lsp.buf.hover()", "Hover" }, + ["[d"] = { "lua vim.diagnostic.goto_prev()", "Next Diagnostic" }, + ["]d"] = { "lua vim.diagnostic.goto_next()", "Prev Diagnostic" }, + ["[e"] = { "lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})", "Next Error" }, + ["]e"] = { "lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})", "Prev Error" }, + ["[w"] = { "lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.WARNING})", "Next Warning" }, + ["]w"] = { "lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.WARNING})", "Prev Warning" }, + } + + wk.register(keymap) +end + +return M diff --git a/lua/plugins/rust-tools.lua b/lua/plugins/rust-tools.lua new file mode 100644 index 0000000..61306df --- /dev/null +++ b/lua/plugins/rust-tools.lua @@ -0,0 +1,125 @@ +local M = { + module = "rust-tools", +} + +function M.setup(options) + local opts = { + tools = { -- rust-tools options + -- -- Automatically set inlay hints (type hints) + -- autoSetHints = true, + + -- -- Whether to show hover actions inside the hover window + -- -- This overrides the default hover handler + -- hover_with_actions = true, + + -- -- how to execute terminal commands + -- -- options right now: termopen / quickfix + -- executor = require("rust-tools/executors").termopen, + + -- runnables = { + -- -- whether to use telescope for selection menu or not + -- use_telescope = true, + + -- -- rest of the opts are forwarded to telescope + -- }, + + -- debuggables = { + -- -- whether to use telescope for selection menu or not + -- use_telescope = true, + + -- -- rest of the opts are forwarded to telescope + -- }, + + -- -- These apply to the default RustSetInlayHints command + inlay_hints = { + + -- -- Only show inlay hints for the current line + -- only_current_line = false, + + -- -- Event which triggers a refersh of the inlay hints. + -- -- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but + -- -- not that this may cause higher CPU usage. + -- -- This option is only respected when only_current_line and + -- -- autoSetHints both are true. + -- only_current_line_autocmd = "CursorHold", + + -- -- wheter to show parameter hints with the inlay hints or not + -- show_parameter_hints = true, + + -- -- prefix for parameter hints + parameter_hints_prefix = " <- ", + + -- -- prefix for all the other hints (type, chaining) + other_hints_prefix = " => ", + + -- -- whether to align to the length of the longest line in the file + -- max_len_align = true, + + -- -- padding from the left if max_len_align is true + -- max_len_align_padding = 10, + + -- -- whether to align to the extreme right or not + -- right_align = false, + + -- -- padding from the right if right_align is true + -- right_align_padding = 7, + + -- -- The color of the hints + highlight = "LspCodeLens", + }, + + -- hover_actions = { + -- -- the border that is used for the hover window + -- -- see vim.api.nvim_open_win() + -- border = { + -- { "\u256d", "FloatBorder" }, + -- { "\u2500", "FloatBorder" }, + -- { "\u256e", "FloatBorder" }, + -- { "\u2502", "FloatBorder" }, + -- { "\u256f", "FloatBorder" }, + -- { "\u2500", "FloatBorder" }, + -- { "\u2570", "FloatBorder" }, + -- { "\u2502", "FloatBorder" }, + -- }, + + -- -- whether the hover action window gets automatically focused + -- auto_focus = false, + -- }, + + -- -- settings for showing the crate graph based on graphviz and the dot + -- -- command + -- crate_graph = { + -- -- Backend used for displaying the graph + -- -- see: https://graphviz.org/docs/outputs/ + -- -- default: x11 + -- backend = "x11", + -- -- where to store the output, nil for no output stored (relative + -- -- path from pwd) + -- -- default: nil + -- output = nil, + -- -- true for all crates.io and external crates, false only the local + -- -- crates + -- -- default: true + -- full = true, + -- }, + }, + + -- -- all the opts to send to nvim-lspconfig + -- -- these override the defaults set by rust-tools.nvim + -- -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = options, -- rust-analyer options + + -- -- debugging stuff + -- dap = { + -- adapter = { + -- type = "executable", + -- command = "lldb-vscode", + -- name = "rt_lldb", + -- }, + -- }, + } + + require("rust-tools").setup(opts) +end + +return M diff --git a/lua/plugins/terminal.lua b/lua/plugins/terminal.lua new file mode 100644 index 0000000..d88fab0 --- /dev/null +++ b/lua/plugins/terminal.lua @@ -0,0 +1,7 @@ +return { + ft = "terminal", + module = "nvim-terminal", + config = function() + require("terminal").setup() + end, +} diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua new file mode 100644 index 0000000..86c1754 --- /dev/null +++ b/lua/plugins/toggleterm.lua @@ -0,0 +1,17 @@ +return { + keys = "", + module = "nvim-toggleterm", + config = function() + require("toggleterm").setup({ + size = 20, + hide_numbers = true, + open_mapping = [[]], + shade_filetypes = {}, + shade_terminals = false, + shading_factor = 0.3, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + start_in_insert = true, + persist_size = true, + direction = "horizontal", + }) + end, +}