From ef91f14af8c60cf58ef032dca6d1531c05cce6fb Mon Sep 17 00:00:00 2001 From: PeteChu Date: Fri, 7 Apr 2023 13:41:32 +0700 Subject: [PATCH] Add buffer completion source to nvim-cmp plugin in defaults.lua and integrate lspsaga.nvim plugin for LSP functionality in keymaps.lua and init.lua --- after/plugin/defaults.lua | 2 -- after/plugin/keymaps.lua | 4 ++-- init.lua | 43 ++++++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/after/plugin/defaults.lua b/after/plugin/defaults.lua index c10e22fe..44a578c5 100644 --- a/after/plugin/defaults.lua +++ b/after/plugin/defaults.lua @@ -10,5 +10,3 @@ vim.opt.scrolloff = 8 vim.opt.colorcolumn = "80" vim.opt.swapfile = false - -vim.o.cmdheight = 2 diff --git a/after/plugin/keymaps.lua b/after/plugin/keymaps.lua index be58cc8c..17673bcc 100644 --- a/after/plugin/keymaps.lua +++ b/after/plugin/keymaps.lua @@ -47,8 +47,8 @@ keymap('n', 'y', "\"+y", { desc = "[Y]ank to clipboard" }) keymap('v', 'y', "\"+y", { desc = "[Y]ank to clipboard" }) keymap('n', 'Y', "\"+Y", { desc = "[Y]ank to clipboard" }) --- Open folder in workspace in tmux session -keymap("n", "op", "silent !tmux neww tmux-sessionizer", { desc = "[O]pen [P]roject" }) +-- -- Open folder in workspace in tmux session +-- keymap("n", "op", "silent !tmux neww tmux-sessionizer", { desc = "[O]pen [P]roject" }) -- Search cheat sheet keymap("n", "ch", "silent !tmux neww tmux-cht.sh", { desc = "[C]heat [S]heet" }) diff --git a/init.lua b/init.lua index d0585b88..1d805164 100644 --- a/init.lua +++ b/init.lua @@ -98,7 +98,7 @@ require('lazy').setup({ { -- Autocompletion 'hrsh7th/nvim-cmp', - dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, + dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', 'hrsh7th/cmp-buffer' }, }, -- Useful plugin to show you pending keybinds. @@ -186,6 +186,19 @@ require('lazy').setup({ end, }, + { + "glepnir/lspsaga.nvim", + event = "LspAttach", + dependencies = { + { "nvim-tree/nvim-web-devicons" }, + --Please make sure you install markdown and markdown_inline parser + { "nvim-treesitter/nvim-treesitter" } + }, + config = function() + require("lspsaga").setup({}) + end, + }, + -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart -- These are some example plugins that I've included in the kickstart repository. -- Uncomment any of the lines below to enable them. @@ -302,7 +315,7 @@ vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { de -- See `:help nvim-treesitter` require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'help', 'vim' }, + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'help', 'vim', 'markdown', 'markdown_inline' }, -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) auto_install = true, @@ -387,18 +400,29 @@ local on_attach = function(_, bufnr) vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) end - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + -- nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') + -- nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + nmap('rn', ":Lspsaga rename", '[R]e[n]ame') + nmap('ca', ":Lspsaga code_action", '[C]ode [A]ction') + + -- nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') + nmap("gp", ":Lspsaga peek_definition", "[gP]eek [D]efinition") + nmap('gd', ":Lspsaga goto_definition", '[G]oto [D]efinition') + nmap('gh', ":Lspsaga lsp_finder", '[G]oto [H]elp') + - nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') - nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') + + -- nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') + nmap('D', ":Lspsaga peek_type_definition", 'Type [D]efinition') + nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + -- nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + nmap('K', ":Lspsaga hover_doc", 'Hover Documentation') -- nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') -- Lesser used LSP functionality @@ -409,6 +433,10 @@ local on_attach = function(_, bufnr) print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, '[W]orkspace [L]ist Folders') + + -- Toggle outline + nkeymap("o", ":Lspsaga outline", '[O]utline') + -- Create a command `:Format` local to the LSP buffer vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.lsp.buf.format() @@ -504,6 +532,7 @@ cmp.setup { sources = { { name = 'nvim_lsp' }, { name = 'luasnip' }, + { name = 'buffer' }, }, }