diff options
-rw-r--r-- | after/plugin/lsp.lua | 50 | ||||
-rw-r--r-- | lazy-lock.json | 2 | ||||
-rw-r--r-- | lua/talha/functions.lua | 5 | ||||
-rw-r--r-- | lua/talha/lazy.lua | 2 |
4 files changed, 54 insertions, 5 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, + }, +}) diff --git a/lazy-lock.json b/lazy-lock.json index 270621b..b2286c4 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,6 +1,8 @@ { "LuaSnip": { "branch": "master", "commit": "72eea98b1900013e0cb214f29b898c8d91564930" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, "lazy.nvim": { "branch": "main", "commit": "3f13f080434ac942b150679223d54f5ca91e0d52" }, "lsp-zero.nvim": { "branch": "v2.x", "commit": "9a686513eaaa13d737d0fec8956a18268ead8b29" }, diff --git a/lua/talha/functions.lua b/lua/talha/functions.lua index fdad26c..b75185b 100644 --- a/lua/talha/functions.lua +++ b/lua/talha/functions.lua @@ -1,9 +1,8 @@ local Path = require"plenary.path" -function FormatFile() +function GetCurrFileName() local filename = vim.api.nvim_buf_get_name(0) - vim.cmd(":silent !autopep8 -i " .. filename) - vim.cmd(":silent !isort " .. filename) + return filename end function CreateDailyNote() diff --git a/lua/talha/lazy.lua b/lua/talha/lazy.lua index 089f254..8ac7f43 100644 --- a/lua/talha/lazy.lua +++ b/lua/talha/lazy.lua @@ -39,6 +39,8 @@ require("lazy").setup({ -- Autocompletion {'hrsh7th/nvim-cmp'}, -- Required {'hrsh7th/cmp-nvim-lsp'}, -- Required + {'hrsh7th/cmp-buffer'}, -- Required + {'hrsh7th/cmp-nvim-lua'}, {'L3MON4D3/LuaSnip'}, -- Required } }, |