2023-02-17 09:59:38 +00:00
|
|
|
-- install packer if not already there
|
2022-12-23 09:15:39 +00:00
|
|
|
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
|
|
|
|
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
|
|
|
|
is_bootstrap = true
|
2023-02-17 09:59:38 +00:00
|
|
|
vim.fn.system{'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }
|
2022-12-23 09:15:39 +00:00
|
|
|
vim.cmd [[packadd packer.nvim]]
|
|
|
|
end
|
|
|
|
|
2023-02-17 09:59:38 +00:00
|
|
|
-- Install Plugins
|
|
|
|
require('packer').startup(function(use)
|
|
|
|
use 'wbthomason/packer.nvim'
|
|
|
|
use 'neovim/nvim-lspconfig'
|
|
|
|
use 'nvim-treesitter/nvim-treesitter'
|
|
|
|
use {
|
|
|
|
'hrsh7th/nvim-cmp',
|
2023-02-17 11:34:39 +00:00
|
|
|
requires = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua', 'onsails/lspkind.nvim' }
|
2023-02-17 09:59:38 +00:00
|
|
|
}
|
|
|
|
if is_bootstrap then
|
|
|
|
require('packer').sync()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Don't run additional config if installing packer
|
2022-12-23 09:15:39 +00:00
|
|
|
if is_bootstrap then
|
|
|
|
print '=================================='
|
|
|
|
print ' Plugins are being installed'
|
|
|
|
print ' Wait until Packer completes,'
|
|
|
|
print ' then restart nvim'
|
|
|
|
print '=================================='
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-02-17 09:59:38 +00:00
|
|
|
-- Some basic settings
|
2022-12-23 11:57:25 +00:00
|
|
|
vim.wo.number = true
|
2023-02-17 09:59:38 +00:00
|
|
|
vim.wo.relativenumber = true
|
2023-02-17 11:34:39 +00:00
|
|
|
vim.o.pumheight = 20
|
2022-12-23 11:57:25 +00:00
|
|
|
|
2023-02-17 09:59:38 +00:00
|
|
|
-- Additional keybinds if lsp running
|
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
local bufopts = { noremap=true, silent=true, buffer=bufnr }
|
|
|
|
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
|
|
|
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
|
|
|
|
end
|
2022-12-23 14:52:20 +00:00
|
|
|
|
2023-02-17 09:59:38 +00:00
|
|
|
local lsp_flags = {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
-- lsp configs
|
|
|
|
require('lspconfig')['tsserver'].setup{
|
|
|
|
on_attach = on_attach,
|
|
|
|
flags = lsp_flags
|
|
|
|
}
|
|
|
|
|
|
|
|
require('lspconfig')['lua_ls'].setup{
|
|
|
|
on_attach = on_attach,
|
|
|
|
flags = lsp_flags
|
|
|
|
}
|
|
|
|
|
|
|
|
require('lspconfig')['gopls'].setup{
|
|
|
|
on_attach = on_attach,
|
|
|
|
flags = lsp_flags
|
|
|
|
}
|
|
|
|
|
|
|
|
-- TreeSitter Config
|
|
|
|
require('nvim-treesitter.configs').setup{
|
|
|
|
ensure_installed = {'go', 'vim', 'typescript', 'help', 'lua', 'javascript', 'python'},
|
|
|
|
highlight = {
|
|
|
|
enable = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-- autocompletion
|
|
|
|
local cmp = require 'cmp'
|
2023-02-17 11:34:39 +00:00
|
|
|
local lspkind = require 'lspkind'
|
2023-02-17 09:59:38 +00:00
|
|
|
cmp.setup {
|
|
|
|
sources = {
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
{ name = 'buffer' },
|
|
|
|
{ name = 'cmdline' },
|
|
|
|
{ name = 'path' },
|
|
|
|
{ name = 'nvim-lua' }
|
2023-02-17 11:34:39 +00:00
|
|
|
},
|
|
|
|
formatting = {
|
|
|
|
format = lspkind.cmp_format()
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert {
|
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, {'i', 's'})
|
2023-02-17 09:59:38 +00:00
|
|
|
}
|
|
|
|
}
|