summaryrefslogtreecommitdiff
path: root/after
diff options
context:
space:
mode:
Diffstat (limited to 'after')
-rw-r--r--after/plugin/lsp.lua50
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,
+ },
+})