Skip to content

Commit

Permalink
[NVIM] autocompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
goncrust committed Dec 3, 2023
1 parent ba3e9cc commit e68d4e3
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 19 deletions.
43 changes: 29 additions & 14 deletions .config/nvim/lua/goncrust/packer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,39 @@
vim.cmd([[packadd packer.nvim]])

return require('packer').startup(function(use)
-- Packer can manage itself
use("wbthomason/packer.nvim")
-- Packer can manage itself
use("wbthomason/packer.nvim")

use("joshdick/onedark.vim")
use("joshdick/onedark.vim")

use("nvim-treesitter/nvim-treesitter", {run = ':TSUpdate'})
use("nvim-treesitter/nvim-treesitter", { run = ':TSUpdate' })

use("nvim-tree/nvim-tree.lua")
use("nvim-tree/nvim-web-devicons")
use("nvim-tree/nvim-tree.lua")
use("nvim-tree/nvim-web-devicons")

use("mhinz/vim-startify")
use("mhinz/vim-startify")

use("vim-airline/vim-airline")
use("vim-airline/vim-airline-themes")
use("vim-airline/vim-airline")
use("vim-airline/vim-airline-themes")

use {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig"
}
use("williamboman/mason.nvim")
use("williamboman/mason-lspconfig.nvim")
use("neovim/nvim-lspconfig")

use("hrsh7th/nvim-cmp")
use("hrsh7th/cmp-buffer")
use("hrsh7th/cmp-path")
use("hrsh7th/cmp-cmdline")
use("hrsh7th/cmp-nvim-lsp")

use("L3MON4D3/LuaSnip")
use("saadparwaiz1/cmp_luasnip")
use("rafamadriz/friendly-snippets")

use({
"windwp/nvim-autopairs",
config = function() require("nvim-autopairs").setup {} end
})

use("hrsh7th/cmp-nvim-lsp-signature-help")
end)
151 changes: 146 additions & 5 deletions .config/nvim/lua/goncrust/plugins/lsp-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,149 @@ vim.api.nvim_create_autocmd('LspAttach', {

-- format on save
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = buffer,
callback = function()
vim.lsp.buf.format { async = false }
end
})
buffer = buffer,
callback = function()
vim.lsp.buf.format { async = false }
end
})

------------------- cmp ------------------
local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
return
end

local snip_status_ok, luasnip = pcall(require, "luasnip")
if not snip_status_ok then
return
end

require("luasnip/loaders/from_vscode").lazy_load()

local check_backspace = function()
local col = vim.fn.col "." - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"
end

local kind_icons = {
Text = "󰉿",
Method = "󰆧",
Function = "󰊕",
Constructor = "",
Field = "",
Variable = "󰀫",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "󰑭",
Value = "󰎠",
Enum = "",
Keyword = "󰌋",
Snippet = "",
Color = "󰏘",
File = "󰈙",
Reference = "",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "",
Event = "",
Operator = "󰆕",
TypeParameter = "",
Misc = "",
}
-- find more here: https://www.nerdfonts.com/cheat-sheet

cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body) -- For `luasnip` users.
end,
},
mapping = {
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
["<C-e>"] = cmp.mapping {
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
},
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
["<CR>"] = cmp.mapping.confirm { select = true },
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
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",
}),
},
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
-- Kind icons
vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
-- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind
vim_item.menu = ({
nvim_lsp = "[LSP]",
luasnip = "[Snippet]",
buffer = "[Buffer]",
path = "[Path]",
})[entry.source.name]
return vim_item
end,
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
{ name = 'nvim_lsp_signature_help' }
},
confirm_opts = {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
window = {
documentation = {
border = { "", "", "", "", "", "", "", "" },
},
},
experimental = {
ghost_text = false,
native_menu = false,
},
}

-- autopairs integration
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)
55 changes: 55 additions & 0 deletions .config/nvim/plugin/packer_compiled.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,46 @@ end
time([[try_loadstring definition]], false)
time([[Defining packer_plugins]], true)
_G.packer_plugins = {
LuaSnip = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/LuaSnip",
url = "https://github.com/L3MON4D3/LuaSnip"
},
["cmp-buffer"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/cmp-buffer",
url = "https://github.com/hrsh7th/cmp-buffer"
},
["cmp-cmdline"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/cmp-cmdline",
url = "https://github.com/hrsh7th/cmp-cmdline"
},
["cmp-nvim-lsp"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
url = "https://github.com/hrsh7th/cmp-nvim-lsp"
},
["cmp-nvim-lsp-signature-help"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp-signature-help",
url = "https://github.com/hrsh7th/cmp-nvim-lsp-signature-help"
},
["cmp-path"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/cmp-path",
url = "https://github.com/hrsh7th/cmp-path"
},
cmp_luasnip = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/cmp_luasnip",
url = "https://github.com/saadparwaiz1/cmp_luasnip"
},
["friendly-snippets"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/friendly-snippets",
url = "https://github.com/rafamadriz/friendly-snippets"
},
["mason-lspconfig.nvim"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim",
Expand All @@ -84,6 +124,17 @@ _G.packer_plugins = {
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/mason.nvim",
url = "https://github.com/williamboman/mason.nvim"
},
["nvim-autopairs"] = {
config = { "\27LJ\2\n@\0\0\3\0\3\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0004\2\0\0B\0\2\1K\0\1\0\nsetup\19nvim-autopairs\frequire\0" },
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/nvim-autopairs",
url = "https://github.com/windwp/nvim-autopairs"
},
["nvim-cmp"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/nvim-cmp",
url = "https://github.com/hrsh7th/nvim-cmp"
},
["nvim-lspconfig"] = {
loaded = true,
path = "/home/goncrust/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
Expand Down Expand Up @@ -132,6 +183,10 @@ _G.packer_plugins = {
}

time([[Defining packer_plugins]], false)
-- Config for: nvim-autopairs
time([[Config for nvim-autopairs]], true)
try_loadstring("\27LJ\2\n@\0\0\3\0\3\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0004\2\0\0B\0\2\1K\0\1\0\nsetup\19nvim-autopairs\frequire\0", "config", "nvim-autopairs")
time([[Config for nvim-autopairs]], false)

_G._packer.inside_compile = false
if _G._packer.needs_bufread == true then
Expand Down

0 comments on commit e68d4e3

Please sign in to comment.