From 1ccb8eabf9b3948d26994d6d30932386ba7978fd Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Wed, 27 Jul 2022 19:06:44 +0930 Subject: [PATCH] Wed 27 Jul 2022 19:06:44 ACST --- .config/nvim/lua/config/cmp.lua | 112 ++++++++++++------------ .config/nvim/lua/config/lsp/keymaps.lua | 1 + .config/nvim/lua/lsp/init.lua | 52 ----------- .config/nvim/lua/lsp/installer.lua | 26 ------ .config/nvim/lua/lsp/keymaps.lua | 36 -------- .config/nvim/plugin/telescope.lua | 1 + 6 files changed, 60 insertions(+), 168 deletions(-) delete mode 100644 .config/nvim/lua/lsp/init.lua delete mode 100644 .config/nvim/lua/lsp/installer.lua delete mode 100644 .config/nvim/lua/lsp/keymaps.lua diff --git a/.config/nvim/lua/config/cmp.lua b/.config/nvim/lua/config/cmp.lua index cb2beb4..b81bbdc 100644 --- a/.config/nvim/lua/config/cmp.lua +++ b/.config/nvim/lua/config/cmp.lua @@ -29,8 +29,8 @@ function M.setup() })[entry.source.name] return vim_item end, - }, - mapping = { + }, + mapping = { [""] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), @@ -38,77 +38,81 @@ function M.setup() [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), [""] = cmp.mapping { i = cmp.mapping.close(), c = cmp.mapping.close() }, [""] = cmp.mapping { - i = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false }, - c = function(fallback) + i = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false }, + c = function(fallback) + if cmp.visible() then + cmp.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false } + else + fallback() + end + end, + }, + [""] = cmp.mapping( + function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { + "i", + "s", + "c", + }), + [""] = cmp.mapping(function(fallback) if cmp.visible() then - cmp.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false } + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) else - fallback() + fallback() end - end, - }, - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end end, { "i", "s", "c", - }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { - "i", - "s", - "c", - }), -}, -sources = { - { name = "nvim_lsp" }, - { name = "treesitter" }, - { name = "buffer" }, - { name = "luasnip" }, - { name = "nvim_lua" }, - { name = "path" }, - -- { name = "spell" }, - -- { name = "emoji" }, - -- { name = "calc" }, -}, -window = { - documentation = { - border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, - winhighlight = "NormalFloat:NormalFloat,FloatBorder:TelescopeBorder", + }), + + }, + sources = { + { name = "nvim_lsp" }, + { name = "treesitter" }, + { name = "buffer" }, + { name = "luasnip" }, + { name = "nvim_lua" }, + { name = "path" }, + -- { name = "spell" }, + -- { name = "emoji" }, + -- { name = "calc" }, + }, + window = { + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + winhighlight = "NormalFloat:NormalFloat,FloatBorder:TelescopeBorder", + }, }, -}, } -- Use buffer source for `/` cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), sources = { { name = "buffer" }, }, }) - -- Use cmdline & path source for ':' - cmp.setup.cmdline(":", { + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ - { name = "path" }, + { name = 'path' } }, { - { name = "cmdline" }, - }), + { name = 'cmdline' } + }) }) end diff --git a/.config/nvim/lua/config/lsp/keymaps.lua b/.config/nvim/lua/config/lsp/keymaps.lua index f33d9b1..8d6d06c 100644 --- a/.config/nvim/lua/config/lsp/keymaps.lua +++ b/.config/nvim/lua/config/lsp/keymaps.lua @@ -23,6 +23,7 @@ local function keymappings(client, bufnr) vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + -- vim.keymap.set("n", "gr", function() vim.lsp.buf.references({ includeDeclaration = false }) end, opts) vim.keymap.set("n", "gh", vim.lsp.buf.signature_help, opts) vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, opts) diff --git a/.config/nvim/lua/lsp/init.lua b/.config/nvim/lua/lsp/init.lua deleted file mode 100644 index 700b0ee..0000000 --- a/.config/nvim/lua/lsp/init.lua +++ /dev/null @@ -1,52 +0,0 @@ -local M = {} - -local servers = { - gopls = {}, - html = {}, - jsonls = {}, - pyright = {}, - tsserver = {}, - vimls = {}, - dartls = {}, - dockerls = {}, - intelephense = {}, - sqlls = {}, - volar = {}, -} - -local function on_attach(client, bufnr) - -- Enable completion triggered by - -- See `:help omnifunc` and `:help ins-completion` for more information. - vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") - - -- Use LSP as the handler for formatexpr. - -- See `:help formatexpr` for more information. - vim.api.nvim_buf_set_option(0, "formatexpr", "v:lua.vim.lsp.formatexpr()") - - -- Configure key mappings - require("lsp.keymaps").setup(client, bufnr) -end - -local lsp_signature = require "lsp_signature" -lsp_signature.setup { - bind = true, - handler_opts = { - border = "rounded", - }, -} - -local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) - -local opts = { - on_attach = on_attach, - capabilities = cababilities, - flags = { - debounce_text_changes = 150, - }, -} - -function M.setup() - require("lsp.installer").setup(servers, opts) -end - -return M diff --git a/.config/nvim/lua/lsp/installer.lua b/.config/nvim/lua/lsp/installer.lua deleted file mode 100644 index 012eb69..0000000 --- a/.config/nvim/lua/lsp/installer.lua +++ /dev/null @@ -1,26 +0,0 @@ -local lsp_installer_servers = require "nvim-lsp-installer.servers" -local utils = require "utils" - -local M = {} - -function M.setup(servers, options) - for server_name, _ in pairs(servers) do - local server_available, server = lsp_installer_servers.get_server(server_name) - - if server_available then - server:on_ready(function() - local opts = vim.tbl_deep_extend("force", options, servers[server.name] or {}) - server:setup(opts) - end) - - if not server:is_installed() then - utils.info("Installing " .. server.name) - server:install() - end - else - utils.error(server) - end - end -end - -return M diff --git a/.config/nvim/lua/lsp/keymaps.lua b/.config/nvim/lua/lsp/keymaps.lua deleted file mode 100644 index a2e7c1d..0000000 --- a/.config/nvim/lua/lsp/keymaps.lua +++ /dev/null @@ -1,36 +0,0 @@ -local M = {} - -local keymap = vim.api.nvim_set_keymap -local buf_keymap = vim.api.nvim_buf_set_keymap - -local function keymappings(client, bufnr) - local opts = { noremap = true, silent = true } - - -- Key mappings - vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) - vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) - vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) - vim.keymap.set("n", "[e", function () vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR}) end, opts) - vim.keymap.set("n", "]e", function () vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR}) end, opts) - - vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) - vim.keymap.set("n", "K", vim.lsp.buf.code_action, opts) - vim.keymap.set("n", "of", vim.diagnostic.open_float, opts) - - if client.resolved_capabilities.document_formatting then - vim.keymap.set("n", "ff", vim.lsp.buf.formatting, opts) - end - - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) - vim.keymap.set("n", "gh", vim.lsp.buf.signature_help, opts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) - vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, opts) - -end - -function M.setup(client, bufnr) - keymappings(client, bufnr) -end - -return M diff --git a/.config/nvim/plugin/telescope.lua b/.config/nvim/plugin/telescope.lua index fd2025c..322048c 100644 --- a/.config/nvim/plugin/telescope.lua +++ b/.config/nvim/plugin/telescope.lua @@ -57,4 +57,5 @@ end, options) -- end, options) vim.keymap.set('n', 'fb', require('telescope.builtin').buffers, options) +vim.keymap.set('n', 'gr', require('telescope.builtin').lsp_references, options)