From 047ea7318b352692b0c2cb49590d75ea1588c148 Mon Sep 17 00:00:00 2001 From: Matthew Wozniak Date: Fri, 29 Dec 2023 19:39:37 -0500 Subject: new config --- after/plugin/colors.lua | 9 ---- after/plugin/lsp.lua | 120 ++++++++++++++++++++++++++------------------ after/plugin/telescope.lua | 6 +-- after/plugin/treesitter.lua | 21 -------- 4 files changed, 74 insertions(+), 82 deletions(-) delete mode 100644 after/plugin/colors.lua delete mode 100644 after/plugin/treesitter.lua (limited to 'after/plugin') diff --git a/after/plugin/colors.lua b/after/plugin/colors.lua deleted file mode 100644 index 7c7bd0f..0000000 --- a/after/plugin/colors.lua +++ /dev/null @@ -1,9 +0,0 @@ -function ColorMyPencils(color) - color = color or 'wal' - vim.cmd.colorscheme(color) - vim.api.nvim_set_hl(0, "Normal", { bg = 'none'}) - vim.api.nvim_set_hl(0, "NormalFloat", { bg = 'none'}) - vim.api.nvim_set_hl(0, "EndOfBuffer", { bg = 'none'}) -end - -ColorMyPencils() diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index cfb10e8..7722c1e 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,59 +1,81 @@ -local lsp = require("lsp-zero") +-- Setup autocomplete/LSP clients +local lspconfig = require('lspconfig') +local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities() -lsp.preset("recommended") +local servers = {"clangd", "zls", "rust_analyzer", "lua_ls"} + for _, lsp in pairs(servers) do + lspconfig[lsp].setup { + capabilities = lsp_capabilities, + on_attach = onattach, + flags = {debounce_text_changes = 500} + } +end -lsp.setup_servers({ - 'clangd', - 'rust_analyzer', - 'lua_ls', -}) +vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function() + local bufmap = function(mode, lhs, rhs) + local opts = {buffer = true} + vim.keymap.set(mode, lhs, rhs, opts) + end --- Fix Undefined global 'vim' -lsp.nvim_workspace() + bufmap('n', 'K', 'lua vim.lsp.buf.hover()') + bufmap('n', 'gd', 'lua vim.lsp.buf.definition()') + bufmap('n', 'gD', 'lua vim.lsp.buf.declaration()') + bufmap('n', 'gi', 'lua vim.lsp.buf.implementation()') + bufmap('n', 'go', 'lua vim.lsp.buf.type_definition()') + bufmap('n', 'gr', 'lua vim.lsp.buf.references()') + bufmap('n', 'gs', 'lua vim.lsp.buf.signature_help()') + bufmap('n', '', 'lua vim.lsp.buf.rename()') + bufmap('n', '', 'lua vim.lsp.buf.code_action()') + bufmap('n', 'gl', 'lua vim.diagnostic.open_float()') + bufmap('n', '[d', 'lua vim.diagnostic.goto_prev()') + bufmap('n', ']d', 'lua vim.diagnostic.goto_next()') + end +}) +require('luasnip.loaders.from_vscode').lazy_load() local cmp = require('cmp') -local cmp_select = {behavior = cmp.SelectBehavior.Select} -local cmp_mappings = lsp.defaults.cmp_mappings({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping.complete(), -}) +local luasnip = require('luasnip') -cmp_mappings[''] = nil -cmp_mappings[''] = nil +local select_opts = {behavior = cmp.SelectBehavior.Select} +cmp.setup({ + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + luasnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + item.menu = menu_icon[entry.source.name] + return item + end, + }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + sources = { + {name = 'path'}, + {name = 'nvim_lsp', keyword_length = 1}, + {name = 'buffer', keyword_length = 3}, + {name = 'luasnip', keyword_length = 2}, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(select_opts), + [''] = cmp.mapping.select_next_item(select_opts), -lsp.setup_nvim_cmp({ - mapping = cmp_mappings -}) + [''] = cmp.mapping.select_prev_item(select_opts), + [''] = cmp.mapping.select_next_item(select_opts), -lsp.set_preferences({ - suggest_lsp_servers = false, - sign_icons = { - error = 'E', - warn = 'W', - hint = 'H', - info = 'I' - } -}) + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), -lsp.on_attach(function(client, 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) -end) - -lsp.setup() - -vim.diagnostic.config({ - virtual_text = true + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({select = true}), + [''] = cmp.mapping.confirm({select = false}), + }, }) diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua index 8dae86b..7eeb0a1 100644 --- a/after/plugin/telescope.lua +++ b/after/plugin/telescope.lua @@ -1,4 +1,4 @@ -local builtin = require('telescope.builtin') +local builtin = require "telescope.builtin" vim.keymap.set('n', 'pf', builtin.find_files, {}) -vim.keymap.set('n', '', builtin.git_files, {}) -vim.keymap.set('n', '', builtin.live_grep, {}) +vim.keymap.set('n', 'fg', builtin.live_grep, {}) +vim.keymap.set('n', 'ff', builtin.buffers, {}) diff --git a/after/plugin/treesitter.lua b/after/plugin/treesitter.lua deleted file mode 100644 index 86826a0..0000000 --- a/after/plugin/treesitter.lua +++ /dev/null @@ -1,21 +0,0 @@ -require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" (the five listed parsers should always be installed) - ensure_installed = { "zig", "rust", "c", "lua", "vim", "vimdoc", "query" }, - - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - - -- Automatically install missing parsers when entering buffer - -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally - auto_install = true, - - highlight = { - enable = true, - - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - additional_vim_regex_highlighting = false, - }, -} -- cgit v1.2.3-54-g00ecf