my neovim configuration

update to have autocomplete

+1
init.lua
···
require "ptero.plugins"
require "ptero.keymaps"
require "ptero.options"
···
require "ptero.plugins"
require "ptero.keymaps"
require "ptero.options"
+
require "ptero.lsp"
+14 -4
lazy-lock.json
···
{
"catppuccin": { "branch": "main", "commit": "3020af75aae098a77737d91ee37c7147c8450d99" },
-
"gitsigns.nvim": { "branch": "main", "commit": "d4f8c01280413919349f5df7daccd0c172143d7c" },
-
"lazy.nvim": { "branch": "main", "commit": "e77be3cf3b01402b86464e1734fb5ead448ce12e" },
-
"nvim-treesitter": { "branch": "master", "commit": "3e316204f8ec8450bbaace69d0bf8fe332633fec" },
"plenary.nvim": { "branch": "master", "commit": "9d81624fbcedd3dd43b38d7e13a1e7b3f873d8cd" },
"telescope.nvim": { "branch": "master", "commit": "04af51dbfb17c2afa0b8d82b0e842e0638201ca9" },
-
"which-key.nvim": { "branch": "main", "commit": "802219ba26409f325a5575e3b684b6cb054e2cc5" }
}
···
{
"catppuccin": { "branch": "main", "commit": "3020af75aae098a77737d91ee37c7147c8450d99" },
+
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
+
"cmp-nvim-lsp": { "branch": "main", "commit": "59224771f91b86d1de12570b4070fe4ad7cd1eeb" },
+
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
+
"cmp-tabnine": { "branch": "main", "commit": "ee1341c53e7b82f55c6e83287828f652c2ac35e1" },
+
"cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
+
"gitsigns.nvim": { "branch": "main", "commit": "114362a85e51918ab2965181ffa31932c181f32f" },
+
"lazy.nvim": { "branch": "main", "commit": "ef87c24e8ede2a94cbeaea1667eaeb7f8ed40dc0" },
+
"luasnip": { "branch": "master", "commit": "5d57303efde86fcb0959c52b1a6d40f923940f34" },
+
"mason-lspconfig.nvim": { "branch": "main", "commit": "3751eb5c56c67b51e68a1f4a0da28ae74ab771c1" },
+
"mason.nvim": { "branch": "main", "commit": "a4ebe1f14ba31242cd09f9e0709d5b1f9d2bcecb" },
+
"nvim-cmp": { "branch": "main", "commit": "11a95792a5be0f5a40bab5fc5b670e5b1399a939" },
+
"nvim-lspconfig": { "branch": "master", "commit": "7b98aadc6e85db4fc3af6c1ec22c4774d965506e" },
+
"nvim-treesitter": { "branch": "master", "commit": "5b8b711926d1f3ef5c63fbe5db2d8f33b912025e" },
"plenary.nvim": { "branch": "master", "commit": "9d81624fbcedd3dd43b38d7e13a1e7b3f873d8cd" },
"telescope.nvim": { "branch": "master", "commit": "04af51dbfb17c2afa0b8d82b0e842e0638201ca9" },
+
"which-key.nvim": { "branch": "main", "commit": "85f69b07afce4ea77c58ae9a3aeb4e6c918b4d34" }
}
+193
lua/ptero/configs/cmp.lua
···
···
+
local cmp_ok, cmp = pcall(require, "cmp")
+
if not cmp_ok then
+
vim.notify('cmp not loaded')
+
return
+
end
+
+
local compare_ok, compare = pcall(require, "cmp.config.compare")
+
if not compare_ok then
+
vim.notify('cmp.config.compare not loaded')
+
return
+
end
+
+
local compare_tabnine_ok, compare_tabnine = pcall(require, "cmp_tabnine.compare")
+
if not compare_tabnine_ok then
+
vim.notify('cmp_tabnine.compare not loaded')
+
return
+
end
+
+
local luasnip_ok, luasnip = pcall(require, "luasnip")
+
if not luasnip_ok then
+
vim.notify('luasnip not loaded')
+
end
+
+
require("luasnip.loaders.from_vscode").lazy_load()
+
+
local icons = require("ptero.icons")
+
local border = require("ptero.borders").style
+
+
-- Used by nvim-cmp to override the completion menu popups.
+
-- FloatBorder is removed to leave it as the default.
+
-- Default: "Normal:Normal,FloatBorder:Normal,CursorLine:Visual,Search:None"
+
-- NOTE: This is related to the theme. So maybe consider defining this in theme.lua.
+
local winhighlight = "Normal:NormalFloat,CursorLine:Visual,Search:None"
+
+
local source_names = {
+
cmp_tabnine = "[T9]",
+
nvim_lsp = "[LSP]",
+
path = "[P]",
+
luasnip = "[S]",
+
buffer = "[B]",
+
}
+
+
local duplicates = {
+
nvim_lsp = 0,
+
path = 1,
+
luasnip = 1,
+
buffer = 1,
+
}
+
+
local has_words_before = function()
+
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
+
+
cmp.setup({
+
preselect = cmp.PreselectMode.None,
+
experimental = {
+
ghost_text = true,
+
},
+
formatting = {
+
fields = { "kind", "abbr", "menu" },
+
format = function(entry, vim_item)
+
vim_item.kind = icons.kind[vim_item.kind]
+
vim_item.menu = source_names[entry.source.name]
+
vim_item.dup = duplicates[entry.source.name] or 0
+
+
-- Set custom kind icons for specific sources.
+
if entry.source.name == "cmp_tabnine" then
+
vim_item.kind = icons.kind.Event
+
local detail = (entry.completion_item.data or {}).detail
+
if detail and detail:find(".*%%.*") then
+
vim_item.kind = vim_item.kind .. " " .. detail
+
end
+
+
if (entry.completion_item.data or {}).multiline then
+
vim_item.kind = vim_item.kind .. " " .. "[ML]"
+
end
+
end
+
+
local max_width = 80
+
if #vim_item.abbr > max_width then
+
vim_item.abbr = string.sub(vim_item.abbr, 1, max_width - 1) .. icons.ui.Ellipsis
+
end
+
+
return vim_item
+
end,
+
},
+
snippet = {
+
expand = function(args)
+
luasnip.lsp_expand(args.body)
+
end,
+
},
+
window = {
+
completion = cmp.config.window.bordered({
+
border = border,
+
winhighlight = winhighlight,
+
}),
+
documentation = cmp.config.window.bordered({
+
border = border,
+
winhighlight = winhighlight,
+
}),
+
},
+
sources = {
+
{
+
name = "cmp_tabnine",
+
max_item_count = 5,
+
trigger_characters = {
+
".",
+
":",
+
"(",
+
"'",
+
'"',
+
"[",
+
",",
+
"#",
+
"*",
+
"@",
+
"|",
+
"=",
+
"-",
+
"{",
+
"/",
+
"\\",
+
"+",
+
"?",
+
" ",
+
},
+
},
+
{ name = "nvim_lsp" },
+
{ name = "path" },
+
{ name = "luasnip" },
+
{ name = "buffer" },
+
},
+
sorting = {
+
priority_weight = 2,
+
comparators = {
+
compare_tabnine,
+
compare.offset,
+
compare.exact,
+
compare.score,
+
compare.recently_used,
+
compare.locality,
+
compare.kind,
+
compare.sort_text,
+
compare.length,
+
compare.order,
+
},
+
},
+
mapping = cmp.mapping.preset.insert({
+
["<C-k>"] = cmp.mapping.select_prev_item(),
+
["<C-j>"] = cmp.mapping.select_next_item(),
+
["<Down>"] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), { "i" }),
+
["<Up>"] = cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), { "i" }),
+
["<C-d>"] = cmp.mapping.scroll_docs(4),
+
["<C-u>"] = cmp.mapping.scroll_docs(-4),
+
["<C-Space>"] = cmp.mapping.complete(),
+
["<C-e>"] = cmp.mapping.abort(),
+
["<CR>"] = cmp.mapping.confirm({ select = false }),
+
+
["<C-y>"] = cmp.mapping({
+
i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }),
+
c = function(fallback)
+
if cmp.visible() then
+
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
+
else
+
fallback()
+
end
+
end,
+
}),
+
+
["<Tab>"] = cmp.mapping(function(fallback)
+
if cmp.visible() then
+
cmp.select_next_item()
+
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" }),
+
}),
+
})
+12
lua/ptero/configs/mason.lua
···
···
+
local ok, mason = pcall(require, "mason")
+
if not ok then
+
return
+
end
+
+
local border = require("ptero.borders").style
+
+
mason.setup({
+
ui = {
+
border = border,
+
},
+
})
+6
lua/ptero/configs/tabnine.lua
···
···
+
local tabnine_ok, tabnine = pcall(require, "tabnine")
+
if not tabnine_ok then
+
return
+
end
+
+
tabnine:setup()
+30
lua/ptero/lsp/config.lua
···
···
+
local icons = require("ptero.icons")
+
local border = require("ptero.borders").style
+
+
local sign = function(name, text)
+
vim.fn.sign_define(na,e, {texthl = name, text=text, numhl=name })
+
end
+
+
sign("DiagnosticSignError", icons.diagnostics.Error)
+
sign("DiagnosticSignWarn", icons.diagnostics.Warning)
+
sign("DiagnosticSignHint", icons.diagnostics.Hint)
+
sign("DiagnosticSignInfo", icons.diagnostics.Information)
+
+
vim.diagnostic.config({
+
virtual_text = false,
+
signs = true,
+
underline = true,
+
update_in_insert = false,
+
severity_sort = true,
+
float = {
+
focusable = false,
+
style = "minimal",
+
border = border,
+
source = "always",
+
header = "",
+
prefix = "",
+
},
+
})
+
+
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
+
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = border })
+29
lua/ptero/lsp/handlers.lua
···
···
+
local M = {}
+
+
-- Helper function to set keymap for specific buffer with a description.
+
local keymap = function(bufnr, mode, lhs, rhs, desc)
+
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc, silent = true })
+
end
+
+
-- capabilities handler
+
local cmp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
+
if cmp_ok then
+
M.capabilities = cmp_nvim_lsp.default_capabilities()
+
else
+
M.capabilities = vim.lsp.protocol.make_client_capabilities()
+
end
+
+
-- on_attach handler
+
M.on_attach = function(_, bufnr)
+
keymap(bufnr, "n", "K", vim.lsp.buf.hover, "Show Hover")
+
keymap(bufnr, "n", "gd", vim.lsp.buf.definition, "Goto Definition")
+
keymap(bufnr, "n", "gD", vim.lsp.buf.declaration, "Goto Declaration")
+
keymap(bufnr, "n", "gr", vim.lsp.buf.references, "Goto References")
+
keymap(bufnr, "n", "gI", vim.lsp.buf.implementation, "Goto Implementation")
+
keymap(bufnr, "n", "gs", vim.lsp.buf.signature_help, "Show Signature Help")
+
keymap(bufnr, "n", "gl", vim.diagnostic.open_float, "Show Line Diagnostics")
+
keymap(bufnr, "n", "]d", vim.diagnostic.goto_next, "Next Diagnostic")
+
keymap(bufnr, "n", "[d", vim.diagnostic.goto_prev, "Prev Diagnostic")
+
end
+
+
return M
+39
lua/ptero/lsp/init.lua
···
···
+
local lspconfig_ok, lspconfig = pcall(require, "lspconfig")
+
if not lspconfig_ok then
+
return
+
end
+
+
local mason_lsp_config_ok, mason_lspconfig = pcall(require, "mason-lspconfig")
+
if not mason_lspconfig_ok then
+
return
+
end
+
+
require("ptero.lsp.config")
+
+
local servers = {
+
"bashls",
+
"dockerls",
+
"gopls",
+
"html",
+
"jsonls",
+
"pyright",
+
"rust_analyzer",
+
"tsserver",
+
}
+
+
local handlers = require("ptero.lsp.handlers")
+
local opts = {
+
on_attach = handlers.on_attach,
+
capabilities = handlers.capabilities,
+
}
+
+
mason_lspconfig.setup({
+
ensure_installed = servers,
+
automatic_installation = true,
+
})
+
+
mason_lspconfig.setup_handlers({
+
function(server_name)
+
lspconfig[server_name].setup(opts)
+
end,
+
})
+44 -8
lua/ptero/plugins.lua
···
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
-
vim.fn.system({
-
"git",
-
"clone",
-
"--filter=blob:none",
-
"https://github.com/folke/lazy.nvim.git",
-
"--branch=stable", -- latest stable release
-
lazypath,
-
})
end
vim.opt.rtp:prepend(lazypath)
···
config=function() require("ptero.configs.gitsigns") end
},
"folke/which-key.nvim"
})
···
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
+
vim.fn.system({
+
"git",
+
"clone",
+
"--filter=blob:none",
+
"https://github.com/folke/lazy.nvim.git",
+
"--branch=stable", -- latest stable release
+
lazypath,
+
})
end
vim.opt.rtp:prepend(lazypath)
···
config=function() require("ptero.configs.gitsigns") end
},
+
-- completeion
+
{
+
"hrsh7th/nvim-cmp",
+
config=function() require('ptero.configs.cmp') end,
+
dependencies = {
+
"hrsh7th/cmp-buffer",
+
"hrsh7th/cmp-nvim-lsp",
+
"hrsh7th/cmp-path",
+
{
+
"saadparwaiz1/cmp_luasnip",
+
dependencies = {
+
"L3MON4D3/luasnip"
+
}
+
},
+
{
+
"tzachar/cmp-tabnine",
+
build="./install.sh",
+
config=function() require('ptero.configs.tabnine') end
+
},
+
},
+
},
+
+
-- lsp
+
+
"neovim/nvim-lspconfig",
+
+
{
+
"williamboman/mason.nvim",
+
config=function() require('ptero.configs.mason') end,
+
dependencies = {
+
"williamboman/mason-lspconfig.nvim"
+
}
+
},
+
+
+
-- visual keybindings
"folke/which-key.nvim"
})