summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-07-15 15:49:24 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-07-15 15:49:24 +0530
commit16ee7441f40a71872f8fb6a89da470564e76ce04 (patch)
tree79bd0516cb4230593de537f283e6db537990666c
parent32077b19df1d8895e051de1c4e323aeff6b084c9 (diff)
nvim: Adding autocompletions- nvim-cmp+luasnip+nvim-lsp+cmdline+path
-rw-r--r--.config/nvim/init.lua1
-rw-r--r--.config/nvim/lua/justsaumit/cmp-config.lua88
-rw-r--r--.config/nvim/lua/justsaumit/lsp-config.lua76
-rw-r--r--.config/nvim/lua/justsaumit/plugins.lua29
-rw-r--r--.config/nvim/plugin/packer_compiled.lua20
5 files changed, 159 insertions, 55 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua
index 32d509b..3f8a04b 100644
--- a/.config/nvim/init.lua
+++ b/.config/nvim/init.lua
@@ -13,4 +13,5 @@ require("justsaumit.telescope-config")
require("justsaumit.nvim-comment-config")
require("justsaumit.mason")
require("justsaumit.lsp-config")
+require("justsaumit.cmp-config")
print ("while(!(succeed = try() ) );")
diff --git a/.config/nvim/lua/justsaumit/cmp-config.lua b/.config/nvim/lua/justsaumit/cmp-config.lua
new file mode 100644
index 0000000..7e29155
--- /dev/null
+++ b/.config/nvim/lua/justsaumit/cmp-config.lua
@@ -0,0 +1,88 @@
+vim.g.completeopt="menu,menuone,noselect,noinsert"
+
+local has_words_before = function()
+ unpack = unpack or table.unpack
+ local line, col = unpack(vim.api.nvim_win_get_cursor(0))
+ return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
+end
+
+local luasnip = require("luasnip")
+local cmp = require'cmp'
+
+cmp.setup({
+ snippet = {
+ -- REQUIRED - you must specify a snippet engine
+ expand = function(args)
+ -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
+ luasnip.lsp_expand(args.body)
+ end,
+ },
+ window = {
+ -- completion = cmp.config.window.bordered(),
+ -- documentation = cmp.config.window.bordered(),
+ },
+ mapping = cmp.mapping.preset.insert({
+ ['<C-b>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-f>'] = cmp.mapping.scroll_docs(4),
+ ['<C-Space>'] = cmp.mapping.complete(),
+ ['<C-e>'] = cmp.mapping.abort(),
+ ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
+ ["<Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
+ -- they way you will only jump inside the snippet region
+ elseif luasnip.expand_or_jumpable() then
+ luasnip.expand_or_jump()
+ elseif has_words_before() then
+ cmp.complete()
+ else
+ fallback()
+ end
+ end, { "i", "s" }),
+
+ ["<S-Tab>"] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item()
+ elseif luasnip.jumpable(-1) then
+ luasnip.jump(-1)
+ else
+ fallback()
+ end
+ end, { "i", "s" }),
+ }),
+ sources = cmp.config.sources({
+ { name = 'nvim_lsp' },
+ { name = 'luasnip' }, -- For luasnip users.
+ { name = 'buffer' },
+ { name = 'path' },
+ }),
+})
+
+-- Set configuration for specific filetype.
+cmp.setup.filetype('gitcommit', {
+ sources = cmp.config.sources({
+ { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
+ }, {
+ { name = 'buffer' },
+ })
+})
+
+-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
+cmp.setup.cmdline({ '/', '?' }, {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = {
+ { name = 'buffer' }
+ }
+})
+
+-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
+cmp.setup.cmdline(':', {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = cmp.config.sources({
+ { name = 'path' }
+ }, {
+ { name = 'cmdline' }
+ })
+})
+
diff --git a/.config/nvim/lua/justsaumit/lsp-config.lua b/.config/nvim/lua/justsaumit/lsp-config.lua
index f4db75f..3e1db1f 100644
--- a/.config/nvim/lua/justsaumit/lsp-config.lua
+++ b/.config/nvim/lua/justsaumit/lsp-config.lua
@@ -1,83 +1,95 @@
-local on_attach = function(client, bufnr)
- local function buf_set_keymap(...)
- vim.api.nvim_buf_set_keymap(bufnr, ...)
- end
- local function buf_set_option(...)
- vim.api.nvim_buf_set_option(bufnr, ...)
- end
+local lspconfig = require("lspconfig")
+local on_attach = function(_, bufnr)
+ local function buf_set_keymap(...)
+ vim.api.nvim_buf_set_keymap(bufnr, ...)
+ end
+ local function buf_set_option(...)
+ vim.api.nvim_buf_set_option(bufnr, ...)
+ end
- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
+ buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
- local opts = { noremap = true, silent = true }
-
- buf_set_keymap("n", "gd", ":lua vim.lsp.buf.definition()<CR>", opts) --> jumps to the definition of the symbol under the cursor
- buf_set_keymap("n", "<leader>lh", ":lua vim.lsp.buf.hover()<CR>", opts) --> information about the symbol under the cursos in a floating window
- buf_set_keymap("n", "gi", ":lua vim.lsp.buf.implementation()<CR>", opts) --> lists all the implementations for the symbol under the cursor in the quickfix window
- buf_set_keymap("n", "<leader>rn", ":lua vim.lsp.util.rename()<CR>", opts) --> renaname old_fname to new_fname
- buf_set_keymap("n", "<leader>ca", ":lua vim.lsp.buf.code_action()<CR>", opts) --> selects a code action available at the current cursor position
- buf_set_keymap("n", "gr", ":lua vim.lsp.buf.references()<CR>", opts) --> lists all the references to the symbl under the cursor in the quickfix window
- buf_set_keymap("n", "<leader>ld", ":lua vim.diagnostic.open_float()<CR>", opts)
- buf_set_keymap("n", "[d", ":lua vim.diagnostic.goto_prev()<CR>", opts)
- buf_set_keymap("n", "]d", ":lua vim.diagnostic.goto_next()<CR>", opts)
- buf_set_keymap("n", "<leader>lq", ":lua vim.diagnostic.setloclist()<CR>", opts)
- buf_set_keymap("n", "<leader>lf", ":lua vim.lsp.buf.formatting()<CR>", opts) --> formats the current buffer
+ local opts = { noremap = true, silent = true }
+ buf_set_keymap("n", "K", ":lua vim.lsp.buf.hover()<CR>", opts) --> information about the symbol under the cursors in a floating window
+ buf_set_keymap("n", "<leader>rn", ":lua vim.lsp.util.rename()<CR>", opts) --> rename old_fname to new_fname
+ buf_set_keymap("n", "<leader>ca", ":lua vim.lsp.buf.code_action()<CR>", opts) --> selects a code action available at the current cursor position
+ buf_set_keymap("n", "gd", ":lua vim.lsp.buf.definition()<CR>", opts) --> jumps to the definition of the symbol under the cursor
+ buf_set_keymap("n", "gi", ":lua vim.lsp.buf.implementation()<CR>", opts) --> lists all the implementations for the symbol under the cursor in the quickfix window
+ buf_set_keymap("n", "gr", ":lua vim.lsp.buf.references()<CR>", opts) --> lists all the references to the symbl under the cursor in the quickfix window
+ buf_set_keymap("n", "<leader>ld", ":lua vim.diagnostic.open_float()<CR>", opts)
+ buf_set_keymap("n", "[d", ":lua vim.diagnostic.goto_prev()<CR>", opts)
+ buf_set_keymap("n", "]d", ":lua vim.diagnostic.goto_next()<CR>", opts)
+ buf_set_keymap("n", "<leader>lq", ":lua vim.diagnostic.setloclist()<CR>", opts)
+ buf_set_keymap("n", "<leader>lf", ":lua vim.lsp.buf.formatting()<CR>", opts) --> formats the current buffer
end
---@diagnostic disable-next-line: undefined-global
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
-require("lspconfig")["clangd"].setup({
+--lspconfig x cmp_nvim_lsp
+-- Set up lspconfig.
+-- require("lspconfig")["clangd"].setup({
+lspconfig.clangd.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["pyright"].setup({
+lspconfig.pyright.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["bashls"].setup({
+lspconfig.bashls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["cssls"].setup({
+lspconfig.cssls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["gopls"].setup({
+lspconfig.gopls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["html"].setup({
+lspconfig.html.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["lua_ls"].setup({
+lspconfig.lua_ls.setup({
on_attach = on_attach,
capabilities = capabilities,
+ settings = {
+ Lua = {
+ runtime = { version = 'LuaJIT',},
+ diagnostics = {
+ globals = {'vim','require',},},
+ workspace = { library = vim.api.nvim_get_runtime_file("", true),},
+ telemetry = {enable = false,},
+ },
+ },
})
-require("lspconfig")["marksman"].setup({
+lspconfig.marksman.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["rust_analyzer"].setup({
+lspconfig.rust_analyzer.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["tsserver"].setup({
+lspconfig.tsserver.setup({
on_attach = on_attach,
capabilities = capabilities,
})
-require("lspconfig")["yamlls"].setup({
+lspconfig.yamlls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
diff --git a/.config/nvim/lua/justsaumit/plugins.lua b/.config/nvim/lua/justsaumit/plugins.lua
index 4d0edd9..c14149b 100644
--- a/.config/nvim/lua/justsaumit/plugins.lua
+++ b/.config/nvim/lua/justsaumit/plugins.lua
@@ -68,31 +68,24 @@ return packer.startup(function(use)
--lsp
use("williamboman/mason-lspconfig.nvim")
use("neovim/nvim-lspconfig") --> Collection of configurations for built-in LSP client
- use("jose-elias-alvarez/null-ls.nvim") --> inject lsp diagnistocs, formattings, code actions, and more ...
use("tami5/lspsaga.nvim") --> icons for LSP diagnostics
use("onsails/lspkind-nvim") --> vscode-like pictograms for neovim lsp completion items
- use("hrsh7th/nvim-cmp") --> Autocompletion plugin
- use("hrsh7th/cmp-nvim-lsp") --> LSP source for nvim-cmp
- use("saadparwaiz1/cmp_luasnip") --> Snippets source for nvim-cmp
- use("L3MON4D3/LuaSnip") --> Snippets plugin
+--cmp - Autocompletions
+ use("hrsh7th/nvim-cmp") --completion engine
+ use("L3MON4D3/LuaSnip") --snippets engine
+ use("saadparwaiz1/cmp_luasnip") --luasnip completion source for nvim-cmp
+--cmp plugins
+ use("hrsh7th/cmp-nvim-lsp")--nvim-cmp source for neovim's built-in language server client.
+ use("hrsh7th/cmp-buffer") --nvim-cmp source for buffer words.
+ use("hrsh7th/cmp-path") --nvim-cmp source for filesystem path
+ use("hrsh7th/cmp-cmdline") --nvim-cmp source for vim's cmdline
+
+-- use("jose-elias-alvarez/null-ls.nvim") --> inject lsp diagnistocs, formattings, code actions, and more ...
--HTML
-- use 'windwp/nvim-ts-autotag'
--Markdown + Zenmode
--Telescope
use {'nvim-telescope/telescope.nvim', tag = '0.1.2', requires = { {'nvim-lua/plenary.nvim'} }}
---cmp
--- use 'hrsh7th/nvim-cmp'
---cmp plugins
--- use 'hrsh7th/cmp-buffer'
--- use 'hrsh7th/cmp-path'
--- use 'hrsh7th/cmp-cmdline'
--- use 'hrsh7th/cmp-nvim-lsp'
- -- use 'neovim/nvim-lspconfig'
-
--- use "saadparwaiz1/cmp_luasnip" -- snippet completions
-
- -- snippets
--- use "L3MON4D3/LuaSnip" --snippet engine
-- use "rafamadriz/friendly-snippets" -- a bunch of snippets to use
--
-- Comments - Toggle comments in Neovim
diff --git a/.config/nvim/plugin/packer_compiled.lua b/.config/nvim/plugin/packer_compiled.lua
index 725dc9d..67f0b41 100644
--- a/.config/nvim/plugin/packer_compiled.lua
+++ b/.config/nvim/plugin/packer_compiled.lua
@@ -89,11 +89,26 @@ _G.packer_plugins = {
path = "/home/saumit/.local/share/nvim/site/pack/packer/start/catppuccin",
url = "https://github.com/catppuccin/nvim"
},
+ ["cmp-buffer"] = {
+ loaded = true,
+ path = "/home/saumit/.local/share/nvim/site/pack/packer/start/cmp-buffer",
+ url = "https://github.com/hrsh7th/cmp-buffer"
+ },
+ ["cmp-cmdline"] = {
+ loaded = true,
+ path = "/home/saumit/.local/share/nvim/site/pack/packer/start/cmp-cmdline",
+ url = "https://github.com/hrsh7th/cmp-cmdline"
+ },
["cmp-nvim-lsp"] = {
loaded = true,
path = "/home/saumit/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
url = "https://github.com/hrsh7th/cmp-nvim-lsp"
},
+ ["cmp-path"] = {
+ loaded = true,
+ path = "/home/saumit/.local/share/nvim/site/pack/packer/start/cmp-path",
+ url = "https://github.com/hrsh7th/cmp-path"
+ },
cmp_luasnip = {
loaded = true,
path = "/home/saumit/.local/share/nvim/site/pack/packer/start/cmp_luasnip",
@@ -124,11 +139,6 @@ _G.packer_plugins = {
path = "/home/saumit/.local/share/nvim/site/pack/packer/start/mason.nvim",
url = "https://github.com/williamboman/mason.nvim"
},
- ["null-ls.nvim"] = {
- loaded = true,
- path = "/home/saumit/.local/share/nvim/site/pack/packer/start/null-ls.nvim",
- url = "https://github.com/jose-elias-alvarez/null-ls.nvim"
- },
["nvim-cmp"] = {
loaded = true,
path = "/home/saumit/.local/share/nvim/site/pack/packer/start/nvim-cmp",