From 57e115339d00a2a8afe09dba6f83009cc5a02e99 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Mon, 10 Apr 2023 16:38:26 -0300 Subject: nvim update, semi-refactor --- .config/nvim/lua/plugins.lua | 131 ++++++++++++++++++++++++++----------------- 1 file changed, 79 insertions(+), 52 deletions(-) mode change 100755 => 100644 .config/nvim/lua/plugins.lua (limited to '.config/nvim/lua/plugins.lua') diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua old mode 100755 new mode 100644 index 9655992..e956ae4 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -1,17 +1,28 @@ local ensure_packer = function() local fn = vim.fn - local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' + local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then - fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) + fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) vim.cmd [[packadd packer.nvim]] return true end return false end +vim.api.nvim_create_autocmd('BufWritePost', { + pattern = require('utils').config_home() .. '/nvim/lua/plugins.lua', + group = vim.api.nvim_create_augroup('packer', {}), + command = 'source | PackerCompile' +}) + local packer_bootstrap = ensure_packer() +require('packer').init({ + compile_path = vim.fn.stdpath('data') .. '/site/pack/loader/start/packer/plugin/packer.lua', +}) + return require('packer').startup(function(use) + use 'wbthomason/packer.nvim' use { @@ -24,36 +35,53 @@ return require('packer').startup(function(use) use { "SmiteshP/nvim-navic", - requires = "neovim/nvim-lspconfig" + requires = "neovim/nvim-lspconfig", } use { - "folke/which-key.nvim", + "ibhagwan/fzf-lua", config = function() - require("which-key").setup { - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below - } + local opts = {noremap = true, silent = true} + vim.keymap.set('n', 'f', require('fzf-lua').files, opts) + vim.keymap.set('n', 'b', require('fzf-lua').buffers, opts) + vim.keymap.set('n', 'Q', require('fzf-lua').quick_fix, opts) + vim.keymap.set('n', 't', require('fzf-lua').tabs, opts) end } use { 'neovim/nvim-lspconfig', + --ft = vim.g.lsp_langs, config = function() local lspconfig = require('lspconfig') - local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) + local capabilities = require('cmp_nvim_lsp').default_capabilities() local cache = os.getenv("XDG_RUNTIME_DIR") or "/tmp/" local on_attach = function(client, bufnr) - vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'}) + local bind_opts = { silent = true, noremap = true, buffer = true } require('nvim-navic').attach(client, bufnr) + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bind_opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bind_opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bind_opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bind_opts) + vim.keymap.set('n', 'k', vim.lsp.buf.signature_help, bind_opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bind_opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bind_opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bind_opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bind_opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bind_opts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bind_opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bind_opts) + --vim.keymap.set('n', 'f', vim.lsp.buf.formatting, bind_opts) + vim.keymap.set('n', 'e', vim.diagnostic.open_float, bind_opts) + vim.keymap.set('n', 'E', vim.diagnostic.setqflist, bind_opts) end lspconfig.ccls.setup { on_attach = on_attach, capabilities = capabilities, - single_file_support = true, init_options = { cache = { directory = cache .. "/ccls" @@ -86,7 +114,7 @@ return require('packer').startup(function(use) }, diagnostics = { - globals = {'vim'}, + globals = { 'vim', 'packer_plugins' }, }, workspace = { @@ -105,9 +133,10 @@ return require('packer').startup(function(use) use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate', + after = 'nvim-lspconfig', config = function() - require'nvim-treesitter.configs'.setup { - ensure_installed = { "c", "cpp", "php", "lua" }, + require 'nvim-treesitter.configs'.setup { + ensure_installed = vim.g.ts_langs, sync_install = false, auto_install = true, highlight = { @@ -118,75 +147,73 @@ return require('packer').startup(function(use) end } + use { + 'L3MON4D3/LuaSnip', + config = function() + require('luasnip.loaders.from_vscode').lazy_load({ paths = "~/.config/nvim/snippets" }) + end + } + use { 'hrsh7th/nvim-cmp', requires = { 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-vsnip', - 'hrsh7th/vim-vsnip', + 'L3MON4D3/LuaSnip', + 'saadparwaiz1/cmp_luasnip', 'hrsh7th/cmp-nvim-lsp-signature-help', 'hrsh7th/cmp-nvim-lsp-document-symbol', }, + --ft = vim.g.lsp_langs, config = function() - -- Setup nvim-cmp. - local cmp = require'cmp' - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - - local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) - end - + local cmp = require('cmp') + local luasnip = require('luasnip') cmp.setup({ snippet = { - -- REQUIRED - you must specify a snippet engine expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + require('luasnip').lsp_expand(args.body) end, }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.confirm({ select = false }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif vim.fn["vsnip#available"](1) == 1 then - feedkey("(vsnip-expand-or-jump)", "") - elseif has_words_before() then - cmp.complete() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() else - fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + fallback() end end, { "i", "s" }), - [''] = cmp.mapping(function() + [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() - elseif vim.fn["vsnip#jumpable"](-1) == 1 then - feedkey("(vsnip-jump-prev)", "") + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() end end, { "i", "s" }), + [''] = cmp.mapping(function(fallback) + if luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, - { name = 'vsnip' }, -- For vsnip users. - -- { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. + { name = 'luasnip' }, { name = 'nvim_lsp_signature_help' } - }, { - { name = 'buffer' }, + }), + }) + cmp.setup.cmdline({ '/', '?' }, { + sources = cmp.config.sources({ + { name = 'nvim_lsp_document_symbol' } }) }) end -- cgit v1.2.3