From 742a708c0c0788b50c0e0ee08ca8025d5dc93271 Mon Sep 17 00:00:00 2001 From: Smaug123 Date: Sun, 24 Mar 2024 17:14:24 +0000 Subject: [PATCH] Tidy up --- home-manager/nvim/init.lua | 2 +- home-manager/nvim/ionide-vim.lua | 6 +++--- home-manager/nvim/lspconfig.lua | 36 ++++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/home-manager/nvim/init.lua b/home-manager/nvim/init.lua index cc6458f..32f20b3 100644 --- a/home-manager/nvim/init.lua +++ b/home-manager/nvim/init.lua @@ -78,7 +78,7 @@ vim.api.nvim_create_autocmd("BufReadPost", { -- Trim trailing whitespace on save function CleanExtraSpaces() - local save_cursor = vim.api.nvim.win_get_cursor(0) + local save_cursor = vim.api.nvim_win_get_cursor(0) local old_query = vim.fn.getreg("/") vim.cmd("%s/\\s\\+$//e") vim.api.nvim_win_set_cursor(0, save_cursor) diff --git a/home-manager/nvim/ionide-vim.lua b/home-manager/nvim/ionide-vim.lua index 450bfd8..2fba1d9 100644 --- a/home-manager/nvim/ionide-vim.lua +++ b/home-manager/nvim/ionide-vim.lua @@ -183,7 +183,7 @@ end -- if handle then -- local stdout = handle:read("*all") -- handle:close() --- +-- -- local allResults = {} -- for match in string.gmatch(stdout, "([^%z]+)") do -- table.insert(allResults, match) @@ -199,7 +199,7 @@ end -- return a < b -- If both or neither end with 'proj', sort alphabetically -- end -- end) --- +-- -- for _, line in ipairs(allResults) do -- table.insert(results, line) -- end @@ -234,7 +234,7 @@ vim.api.nvim_create_user_command("BuildFSharpProject", function(opts) }) :find() end -end, { nargs = "?", complete = 'file' }) +end, { nargs = "?", complete = "file" }) local function SetupFSharpKeyBindings() local status, whichkey = pcall(require, "which-key") diff --git a/home-manager/nvim/lspconfig.lua b/home-manager/nvim/lspconfig.lua index a0336a9..750d865 100644 --- a/home-manager/nvim/lspconfig.lua +++ b/home-manager/nvim/lspconfig.lua @@ -56,12 +56,31 @@ require("lspconfig").nil_ls.setup(coq.lsp_ensure_capabilities({ }, })) --- Global mappings. --- See `:help vim.diagnostic.*` for documentation on any of the below functions -vim.keymap.set("n", "e", vim.diagnostic.open_float) -vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) -vim.keymap.set("n", "]d", vim.diagnostic.goto_next) -vim.keymap.set("n", "q", vim.diagnostic.setloclist) +function ToggleLocList() + local winid = vim.fn.getloclist(0, { winid = 0 }).winid + if winid == 0 then + vim.cmd.lopen() + else + vim.cmd.lclose() + end +end + +local whichkey_status, whichkey = pcall(require, "which-key") +if whichkey_status then + whichkey.register({ + l = { + p = { vim.diagnostic.goto_prev, "Go to previous entry in loclist" }, + n = { vim.diagnostic.goto_next, "Go to next entry in loclist" }, + l = { ToggleLocList, "Toggle loclist" }, + f = { vim.diagnostic.open_float, "Open current loclist entry in floating window" }, + }, + }, { prefix = vim.api.nvim_get_var("maplocalleader") }) +else + vim.keymap.set("n", "lp", vim.diagnostic.goto_prev) + vim.keymap.set("n", "ln", vim.diagnostic.goto_next) + vim.keymap.set("n", "ll", ToggleLocList) + vim.keymap.set("n", "lf", vim.diagnostic.open_float) +end -- Use LspAttach autocommand to only map the following keys -- after the language server attaches to the current buffer @@ -74,8 +93,7 @@ vim.api.nvim_create_autocmd("LspAttach", { -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local opts = { buffer = ev.buf } - local status, whichkey = pcall(require, "which-key") - if status then + if whichkey_status then whichkey.register({ g = { D = { vim.lsp.buf.declaration, "Go to declaration" }, @@ -114,7 +132,7 @@ vim.api.nvim_create_autocmd("LspAttach", { a = { vim.lsp.buf.code_action, "Select a code action" }, }, r = { - n = { vim.lsp.buf.rename, "Rename buffer" }, + n = { vim.lsp.buf.rename, "Rename variable" }, }, D = { vim.lsp.buf.type_definition, "Go to type definition" }, }, { prefix = "" })