restructured nvim config
This commit is contained in:
parent
45770bf54b
commit
4b5aad807e
7 changed files with 184 additions and 114 deletions
|
|
@ -1,96 +0,0 @@
|
|||
local lspconfig = require('lspconfig')
|
||||
local lsp_defaults = lspconfig.util.default_config
|
||||
|
||||
lsp_defaults.capabilities = vim.tbl_deep_extend(
|
||||
'force',
|
||||
lsp_defaults.capabilities,
|
||||
require('cmp_nvim_lsp').default_capabilities()
|
||||
)
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
desc = 'LSP actions',
|
||||
callback = function(event)
|
||||
local opts = { buffer = event.buf }
|
||||
vim.keymap.set('n', '<leader>i', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
|
||||
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
|
||||
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
|
||||
vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
|
||||
vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
|
||||
vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
|
||||
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
|
||||
vim.keymap.set('n', '<leader>r', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
|
||||
vim.keymap.set('n', '<leader>f', '<cmd>lua vim.lsp.buf.format({async=true})<cr>', opts)
|
||||
vim.keymap.set('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
|
||||
vim.keymap.set('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>', opts)
|
||||
vim.keymap.set('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>', opts)
|
||||
vim.keymap.set('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>', opts)
|
||||
end
|
||||
})
|
||||
|
||||
local default_setup = function(server)
|
||||
lspconfig[server].setup({})
|
||||
end
|
||||
|
||||
require('mason').setup({
|
||||
ui = {
|
||||
border = 'rounded'
|
||||
}
|
||||
})
|
||||
-- Install language servers
|
||||
require('mason-lspconfig').setup({
|
||||
ensure_installed = {
|
||||
'lua_ls', 'clangd', 'pylsp', 'yamlls', 'esbonio',
|
||||
},
|
||||
handlers = {
|
||||
default_setup,
|
||||
pylsp = function()
|
||||
require('lspconfig').pylsp.setup({
|
||||
settings = {
|
||||
pylsp = {
|
||||
plugins = {
|
||||
--flake8 = { enabled = true },
|
||||
autopep8 = { enabled = false },
|
||||
yapf = {
|
||||
enabled = true,
|
||||
},
|
||||
isort = { enabled = true },
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
},
|
||||
})
|
||||
|
||||
local cmp = require('cmp')
|
||||
|
||||
cmp.setup({
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end),
|
||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end),
|
||||
['<C-e>'] = cmp.mapping.abort(),
|
||||
['<C-space>'] = cmp.mapping.complete(),
|
||||
['<C-j>'] = cmp.mapping.scroll_docs(1),
|
||||
['<C-k>'] = cmp.mapping.scroll_docs(-1),
|
||||
['<CR>'] = cmp.mapping.confirm({ select = false }),
|
||||
}),
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
})
|
||||
|
|
@ -15,3 +15,4 @@ vim.g.mapleader = ' ' -- needs to be set before lazy im
|
|||
require('lazy').setup('plugins')
|
||||
|
||||
require('lennartalff')
|
||||
require('plugins.lsp')
|
||||
|
|
|
|||
47
.config/nvim/lua/plugins/cmp.lua
Normal file
47
.config/nvim/lua/plugins/cmp.lua
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
return {
|
||||
'hrsh7th/nvim-cmp',
|
||||
dependencies = {
|
||||
{'hrsh7th/cmp-nvim-lsp'},
|
||||
{'hrsh7th/cmp-nvim-lua'},
|
||||
{'L3MON4D3/LuaSnip'},
|
||||
},
|
||||
config = function()
|
||||
local cmp = require('cmp')
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'nvim_lua' },
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end),
|
||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end),
|
||||
['<C-e>'] = cmp.mapping.abort(),
|
||||
['<C-space>'] = cmp.mapping.complete(),
|
||||
['<C-j>'] = cmp.mapping.scroll_docs(1),
|
||||
['<C-k>'] = cmp.mapping.scroll_docs(-1),
|
||||
['<CR>'] = cmp.mapping.confirm({ select = false }),
|
||||
}),
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
})
|
||||
end
|
||||
}
|
||||
|
|
@ -1,5 +1,10 @@
|
|||
return {
|
||||
{ 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate' },
|
||||
{
|
||||
'L3MON4D3/LuaSnip',
|
||||
tag = 'v2.*',
|
||||
build = 'make install_jsregexp',
|
||||
},
|
||||
'lewis6991/gitsigns.nvim',
|
||||
{
|
||||
'nvim-telescope/telescope.nvim',
|
||||
|
|
@ -9,28 +14,22 @@ return {
|
|||
{ 'rose-pine/neovim', name = 'rose-pine' },
|
||||
{ 'catppuccin/nvim', name = 'catppuccin', priority = 1000 },
|
||||
{ 'tpope/vim-fugitive', name = 'fugitive' },
|
||||
{
|
||||
'VonHeikemen/lsp-zero.nvim',
|
||||
branch = 'v2.x',
|
||||
dependencies = {
|
||||
-- LSP Support
|
||||
{ 'neovim/nvim-lspconfig' }, -- Required
|
||||
{ 'williamboman/mason.nvim' }, -- Optional
|
||||
{ 'williamboman/mason-lspconfig.nvim' }, -- Optional
|
||||
|
||||
-- Autocompletion
|
||||
{ 'hrsh7th/nvim-cmp' }, -- Required
|
||||
{ 'hrsh7th/cmp-nvim-lsp' }, -- Required
|
||||
{ 'L3MON4D3/LuaSnip' }, -- Required
|
||||
},
|
||||
},
|
||||
{
|
||||
'ThePrimeagen/harpoon',
|
||||
dependencies = {
|
||||
{ 'nvim-lua/plenary.nvim' },
|
||||
},
|
||||
},
|
||||
{ 'ray-x/lsp_signature.nvim', event = 'VeryLazy', opts = {},
|
||||
config = function(_, opts) require('lsp_signature').setup(opts) end },
|
||||
|
||||
{
|
||||
'ray-x/lsp_signature.nvim',
|
||||
event = 'VeryLazy',
|
||||
opts = {},
|
||||
config = function(_, opts) require('lsp_signature').setup(opts) end
|
||||
},
|
||||
'rcarriga/nvim-notify',
|
||||
{
|
||||
'danymat/neogen',
|
||||
dependencies = 'nvim-treesitter/nvim-treesitter',
|
||||
config = true,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
82
.config/nvim/lua/plugins/lsp/init.lua
Normal file
82
.config/nvim/lua/plugins/lsp/init.lua
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
--local lspconfig = require('lspconfig')
|
||||
--local lsp_defaults = lspconfig.util.default_config
|
||||
--
|
||||
--lsp_defaults.capabilities = vim.tbl_deep_extend(
|
||||
-- 'force',
|
||||
-- lsp_defaults.capabilities,
|
||||
-- require('cmp_nvim_lsp').default_capabilities()
|
||||
--)
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
desc = 'LSP actions',
|
||||
callback = function(event)
|
||||
local opts = { buffer = event.buf }
|
||||
vim.keymap.set('n', '<leader>i', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
|
||||
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
|
||||
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
|
||||
vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
|
||||
vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
|
||||
vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
|
||||
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
|
||||
vim.keymap.set('n', '<leader>r', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
|
||||
vim.keymap.set('n', '<leader>f', '<cmd>lua vim.lsp.buf.format({async=true})<cr>', opts)
|
||||
vim.keymap.set('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
|
||||
vim.keymap.set('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>', opts)
|
||||
vim.keymap.set('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>', opts)
|
||||
vim.keymap.set('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>', opts)
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
local handlers = {
|
||||
function(server)
|
||||
require('lspconfig')[server].setup({})
|
||||
end,
|
||||
pylsp = function()
|
||||
require('lspconfig').pylsp.setup({
|
||||
settings = {
|
||||
pylsp = {
|
||||
plugins = {
|
||||
yapf = { enabled = true },
|
||||
autopep8 = { enabled = false },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
ruff_lsp = function()
|
||||
require('lspconfig').ruff_lsp.setup({
|
||||
on_attach = function(client, bufnr)
|
||||
client.server_capabilities.hoverProvider = false
|
||||
client.server_capabilities.documentFormattingProver = false
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
||||
return {
|
||||
{
|
||||
'williamboman/mason.nvim',
|
||||
config = function()
|
||||
require('mason').setup({
|
||||
ui = {
|
||||
border = 'rounded'
|
||||
}
|
||||
})
|
||||
require('mason-registry'):on('package:install:success', require('plugins.lsp.python').mason_post_install)
|
||||
end
|
||||
},
|
||||
{
|
||||
'williamboman/mason-lspconfig.nvim',
|
||||
dependencies = {
|
||||
'rcarriga/nvim-notify',
|
||||
},
|
||||
opts = {
|
||||
handlers = handlers,
|
||||
ensure_installed = {
|
||||
'lua_ls', 'clangd', 'pylsp', 'yamlls', 'esbonio', 'ruff_lsp',
|
||||
},
|
||||
},
|
||||
},
|
||||
{ 'neovim/nvim-lspconfig' },
|
||||
}
|
||||
34
.config/nvim/lua/plugins/lsp/python.lua
Normal file
34
.config/nvim/lua/plugins/lsp/python.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
local M = {}
|
||||
local notify = require('notify')
|
||||
|
||||
M.mason_post_install = function(pkg)
|
||||
--if pkg.name ~= 'python-lsp-server' then
|
||||
-- return
|
||||
--end
|
||||
--local venv = vim.fn.stdpath('data') .. '/mason/packages/python-lsp-server/venv'
|
||||
--local job = require('plenary.job')
|
||||
--job:new({
|
||||
-- command = venv .. '/bin/pip',
|
||||
-- args = {
|
||||
-- 'install',
|
||||
-- '-U',
|
||||
-- '--disable-pip-version-check',
|
||||
-- 'pylsp-mypy',
|
||||
-- },
|
||||
-- cwd = venv,
|
||||
-- env = { VIRTUAL_ENV = venv },
|
||||
-- on_exit = function()
|
||||
-- notify('Finished installing pylsp modules.')
|
||||
-- end,
|
||||
-- on_start = function()
|
||||
-- notify('Installing pylsp modules...')
|
||||
-- end,
|
||||
--}):start()
|
||||
end
|
||||
|
||||
M.ruff = function()
|
||||
local config = {}
|
||||
return config
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -81,6 +81,9 @@ ZSH_THEME=""
|
|||
# Add wisely, as too many plugins slow down shell startup.
|
||||
plugins=(git zsh-autosuggestions ssh-agent jump)
|
||||
|
||||
# only lazyily add ssh keys
|
||||
zstyle :omz:plugins:ssh-agent lazy yes
|
||||
|
||||
source $ZSH/oh-my-zsh.sh
|
||||
|
||||
# Preferred editor for local and remote sessions
|
||||
|
|
|
|||
Loading…
Reference in a new issue