diff options
Diffstat (limited to 'lua/plugins/cmp.lua')
| -rw-r--r-- | lua/plugins/cmp.lua | 166 |
1 files changed, 157 insertions, 9 deletions
diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index fed96e4..f4766db 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua | |||
| @@ -1,11 +1,159 @@ | |||
| 1 | return { | 1 | return { |
| 2 | 'neovim/nvim-lspconfig', | 2 | { |
| 3 | 'hrsh7th/cmp-nvim-lsp', | 3 | 'hrsh7th/nvim-cmp', |
| 4 | 'hrsh7th/cmp-buffer', | 4 | dependencies = { |
| 5 | 'hrsh7th/cmp-path', | 5 | 'nvim-lua/popup.nvim', |
| 6 | 'hrsh7th/nvim-cmp', | 6 | 'nvim-lua/plenary.nvim', |
| 7 | 'hrsh7th/vim-vsnip', | 7 | 'saadparwaiz1/cmp_luasnip', |
| 8 | 'L3MON4D3/LuaSnip', | 8 | "hrsh7th/cmp-emoji", |
| 9 | 'octaltree/cmp-look', | 9 | 'hrsh7th/cmp-nvim-lsp', |
| 10 | 'saadparwaiz1/cmp_luasnip', | 10 | 'hrsh7th/cmp-buffer', |
| 11 | 'hrsh7th/cmp-path', | ||
| 12 | 'hrsh7th/vim-vsnip', | ||
| 13 | 'octaltree/cmp-look', | ||
| 14 | 'folke/trouble.nvim', | ||
| 15 | 'folke/lazydev.nvim', | ||
| 16 | { | ||
| 17 | 'L3MON4D3/LuaSnip', | ||
| 18 | config = function() | ||
| 19 | vim.keymap.set( | ||
| 20 | {"i", "s"}, | ||
| 21 | "<leader><Tab>", | ||
| 22 | function() require('luasnip').jump(1) end, | ||
| 23 | {silent = true} | ||
| 24 | ) | ||
| 25 | vim.keymap.set( | ||
| 26 | {"i", "s"}, | ||
| 27 | "<leader><S-Tab>", | ||
| 28 | function() require('luasnip').jump(-1) end, | ||
| 29 | {silent = true} | ||
| 30 | ) | ||
| 31 | end, | ||
| 32 | }, | ||
| 33 | }, | ||
| 34 | |||
| 35 | config = function() | ||
| 36 | require('trouble').setup() | ||
| 37 | require('lazydev').setup() | ||
| 38 | |||
| 39 | local cmp = require'cmp' | ||
| 40 | cmp.setup({ | ||
| 41 | snippet = { | ||
| 42 | -- REQUIRED - you must specify a snippet engine | ||
| 43 | expand = function(args) | ||
| 44 | require('luasnip').lsp_expand(args.body) -- For `luasnip` users. | ||
| 45 | -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) | ||
| 46 | end, | ||
| 47 | }, | ||
| 48 | window = { | ||
| 49 | completion = cmp.config.window.bordered(), | ||
| 50 | documentation = cmp.config.window.bordered(), | ||
| 51 | }, | ||
| 52 | mapping = cmp.mapping.preset.insert({ | ||
| 53 | ['<C-b>'] = cmp.mapping.scroll_docs(-4), | ||
| 54 | ['<C-f>'] = cmp.mapping.scroll_docs(4), | ||
| 55 | ['<C-Space>'] = cmp.mapping.complete(), | ||
| 56 | ['<C-e>'] = cmp.mapping.abort(), | ||
| 57 | ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. | ||
| 58 | }), | ||
| 59 | sources = cmp.config.sources({ | ||
| 60 | { name = 'nvim_lsp' }, | ||
| 61 | { name = 'luasnip' }, -- For luasnip users. | ||
| 62 | }, { | ||
| 63 | { name = 'buffer' }, | ||
| 64 | }) | ||
| 65 | }) | ||
| 66 | end | ||
| 67 | }, | ||
| 68 | { | ||
| 69 | 'neovim/nvim-lspconfig', | ||
| 70 | dependencies = { | ||
| 71 | { "folke/neodev.nvim" } | ||
| 72 | }, | ||
| 73 | config = function() | ||
| 74 | -- Set up lspconfig. | ||
| 75 | local keymap = vim.keymap | ||
| 76 | local on_attach = function(client, bufnr) | ||
| 77 | local opts = { noremap = true, silent = true, buffer = bufnr } | ||
| 78 | keymap.set("n", "gf", "<cmd>Lspsaga lsp_finder<CR>", opts) -- show definition, references | ||
| 79 | keymap.set("n", "gD", "<Cmd>Lspsaga goto_definition<CR>", opts) -- got to declaration | ||
| 80 | keymap.set("n", "gd", "<cmd>Lspsaga peek_definition<CR>", opts) -- see definition and make edits in window | ||
| 81 | keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) -- go to implementation | ||
| 82 | keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts) -- see available code actions | ||
| 83 | keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts) -- smart rename | ||
| 84 | keymap.set("n", "<leader>D", "<cmd>Lspsaga show_line_diagnostics<CR>", opts) -- show diagnostics for line | ||
| 85 | keymap.set("n", "<leader>d", "<cmd>Lspsaga show_cursor_diagnostics<CR>", opts) -- show diagnostics for cursor | ||
| 86 | keymap.set("n", "[d", "<cmd>Lspsaga diagnostic_jump_prev<CR>", opts) -- jump to previous diagnostic in buffer | ||
| 87 | keymap.set("n", "]d", "<cmd>Lspsaga diagnostic_jump_next<CR>", opts) -- jump to next diagnostic in buffer | ||
| 88 | keymap.set("n", "K", "<cmd>Lspsaga hover_doc<CR>", opts) -- show documentation for what is under cursor | ||
| 89 | keymap.set("n", "<leader>o", "<cmd>LSoutlineToggle<CR>", opts) -- see outline on right hand side | ||
| 90 | keymap.set("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) | ||
| 91 | vim.keymap.set("n", "<C-n>", ":cnext<CR>") | ||
| 92 | vim.keymap.set("n", "<C-p>", ":cprev<CR>") | ||
| 93 | end | ||
| 94 | |||
| 95 | local capabilities = require("cmp_nvim_lsp").default_capabilities() | ||
| 96 | |||
| 97 | -- # Language Servers | ||
| 98 | -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md | ||
| 99 | for _,server in ipairs({ | ||
| 100 | 'bitbake_language_server', | ||
| 101 | "clangd", -- C/C++ | clang | ||
| 102 | "tsserver", -- javascript | typescript-language-server | ||
| 103 | "lua_ls", -- lua (but not init.lua entirely, hence why neodev) | ||
| 104 | "jdtls", | ||
| 105 | "html", | ||
| 106 | "cssls", -- ccs | vscode-css-languageserver | ||
| 107 | "rust_analyzer", -- rust | rust-analyzer | ||
| 108 | "eslint", -- javascript | eslint | ||
| 109 | 'vimls', -- vimscript | vim-language-server | ||
| 110 | 'html', -- html | ||
| 111 | 'jsonls', -- jsonls | ||
| 112 | "pyright", -- python | ||
| 113 | "bashls", -- bash | bash-language-server | ||
| 114 | "gopls", | ||
| 115 | "emmet_ls", | ||
| 116 | "marksman"}) do | ||
| 117 | require("lspconfig")[server].setup({ | ||
| 118 | capabilities = capabilities, | ||
| 119 | on_attach = on_attach | ||
| 120 | }) | ||
| 121 | end | ||
| 122 | |||
| 123 | -- # specialized config for some LSPs which have non-ideal defaults | ||
| 124 | -- | ||
| 125 | -- require('lspconfig')['java_language_server'].setup{ cmd = { "/usr/share/java/java-language-server/lang_server_linux.sh" }, root_dir = function () return vim.fn.getcwd() end } | ||
| 126 | -- configure html server | ||
| 127 | require('lspconfig')["html"].setup({ | ||
| 128 | init_options = { | ||
| 129 | configurationSection = { "html", "css", "javascript" }, | ||
| 130 | embeddedLanguages = { | ||
| 131 | css = true, | ||
| 132 | javascript = true, | ||
| 133 | }, | ||
| 134 | provideFormatter = true, | ||
| 135 | }, | ||
| 136 | }) | ||
| 137 | require('lspconfig')['pylsp'].setup{ | ||
| 138 | settings = { | ||
| 139 | pylsp = { | ||
| 140 | plugins = { | ||
| 141 | pycodestyle = { | ||
| 142 | ignore = {'W391'}, | ||
| 143 | maxLineLength = 100 | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
| 149 | require("lspconfig").clangd.setup { | ||
| 150 | on_attach = on_attach, | ||
| 151 | capabilities = capabilities, | ||
| 152 | cmd = { | ||
| 153 | "clangd", | ||
| 154 | "--offset-encoding=utf-16", | ||
| 155 | }, | ||
| 156 | } | ||
| 157 | end | ||
| 158 | } | ||
| 11 | } | 159 | } |
