diff options
author | talha <talha@talhaamir.xyz> | 2024-04-23 02:40:02 +0500 |
---|---|---|
committer | talha <talha@talhaamir.xyz> | 2024-04-23 02:40:02 +0500 |
commit | 148116c22d7074f0eae4a4a3ef8a98290c99c4af (patch) | |
tree | c2bd5279852f32b4674cf4f84ccbb1709c402a9e /after/plugin/lsp.lua | |
parent | 1f793299c6c3f6b60f8c036b742454b229a46de6 (diff) |
Improved autocomplete, added formatting specific to python
Diffstat (limited to 'after/plugin/lsp.lua')
-rw-r--r-- | after/plugin/lsp.lua | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 7d8e3ab..63c369f 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,6 +1,5 @@ local lsp = require('lsp-zero').preset({}) --- TODO: add bindings to work when no lsp available, to allow normal functionality lsp.on_attach(function(client, bufnr) -- see :help lsp-zero-keybindings -- to learn the available actions @@ -14,8 +13,55 @@ lsp.on_attach(function(client, bufnr) vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts) vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts) vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "<leader>vbf", function() vim.lsp.buf.format() end, opts) + vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, {buffer = bfnr}) end) +-- specific setup for python as it's lsp does not come with formatting +require('lspconfig').pyright.setup({ + single_file_support = false, + on_attach = function(client, bufnr) + local opts = {buffer = bfnr} + vim.keymap.set({'n', 'x'}, '<leader>vpf', function() + local filename = GetCurrFileName() + vim.cmd(":silent !autopep8 -i " .. filename) + vim.cmd(":silent !isort " .. filename) + end, opts) + end +}) + lsp.setup() +local cmp = require('cmp') +local cmp_action = require('lsp-zero').cmp_action() + +cmp.setup({ + sources = { + { name = 'nvim_lsp' }, + { name = 'nvim_lua' }, + { name = 'buffer' }, + }, + preselect = 'item', + completion = { + autocomplete = false, + completeopt = 'menu,menuone,noinsert' + }, + mapping = cmp.mapping.preset.insert({ + -- Ctrl+Space to trigger completion menu + ['<C-Space>'] = cmp.mapping.complete(), + + -- Navigate between snippet placeholder + -- @note: don't know what this is + ['<C-f>'] = cmp_action.luasnip_jump_forward(), + ['<C-b>'] = cmp_action.luasnip_jump_backward(), + + -- Scroll up and down in the completion documentation + ['<C-u>'] = cmp.mapping.scroll_docs(-4), + ['<C-d>'] = cmp.mapping.scroll_docs(4), + }), + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, +}) |