From 4b5aad807e4cfb12fc11dfc932e92fad35225657 Mon Sep 17 00:00:00 2001 From: Thies Lennart Alff Date: Wed, 11 Oct 2023 21:34:52 +0200 Subject: [PATCH] restructured nvim config --- .config/nvim/after/plugin/lsp.lua | 96 ------------------------- .config/nvim/init.lua | 1 + .config/nvim/lua/plugins/cmp.lua | 47 ++++++++++++ .config/nvim/lua/plugins/init.lua | 35 +++++---- .config/nvim/lua/plugins/lsp/init.lua | 82 +++++++++++++++++++++ .config/nvim/lua/plugins/lsp/python.lua | 34 +++++++++ home/.zshrc | 3 + 7 files changed, 184 insertions(+), 114 deletions(-) delete mode 100644 .config/nvim/after/plugin/lsp.lua create mode 100644 .config/nvim/lua/plugins/cmp.lua create mode 100644 .config/nvim/lua/plugins/lsp/init.lua create mode 100644 .config/nvim/lua/plugins/lsp/python.lua diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua deleted file mode 100644 index b295494..0000000 --- a/.config/nvim/after/plugin/lsp.lua +++ /dev/null @@ -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', 'i', 'lua vim.lsp.buf.hover()', opts) - vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) - vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) - vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) - vim.keymap.set('n', 'r', 'lua vim.lsp.buf.rename()', opts) - vim.keymap.set('n', 'f', 'lua vim.lsp.buf.format({async=true})', opts) - vim.keymap.set('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - vim.keymap.set('n', 'gl', 'lua vim.diagnostic.open_float()', opts) - vim.keymap.set('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) - vim.keymap.set('n', ']d', 'lua vim.diagnostic.goto_next()', 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({ - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - else - fallback() - end - end), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.scroll_docs(1), - [''] = cmp.mapping.scroll_docs(-1), - [''] = cmp.mapping.confirm({ select = false }), - }), - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, -}) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index f6b1390..ac3820e 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -15,3 +15,4 @@ vim.g.mapleader = ' ' -- needs to be set before lazy im require('lazy').setup('plugins') require('lennartalff') +require('plugins.lsp') diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua new file mode 100644 index 0000000..b5bc97d --- /dev/null +++ b/.config/nvim/lua/plugins/cmp.lua @@ -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({ + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.scroll_docs(1), + [''] = cmp.mapping.scroll_docs(-1), + [''] = cmp.mapping.confirm({ select = false }), + }), + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + }) + end +} diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 30306e1..1a13eb4 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -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, + }, } diff --git a/.config/nvim/lua/plugins/lsp/init.lua b/.config/nvim/lua/plugins/lsp/init.lua new file mode 100644 index 0000000..43da736 --- /dev/null +++ b/.config/nvim/lua/plugins/lsp/init.lua @@ -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', 'i', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', 'r', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set('n', 'f', 'lua vim.lsp.buf.format({async=true})', opts) + vim.keymap.set('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + vim.keymap.set('n', 'gl', 'lua vim.diagnostic.open_float()', opts) + vim.keymap.set('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) + vim.keymap.set('n', ']d', 'lua vim.diagnostic.goto_next()', 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' }, +} diff --git a/.config/nvim/lua/plugins/lsp/python.lua b/.config/nvim/lua/plugins/lsp/python.lua new file mode 100644 index 0000000..bf2086e --- /dev/null +++ b/.config/nvim/lua/plugins/lsp/python.lua @@ -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 diff --git a/home/.zshrc b/home/.zshrc index e8b06f6..7fda96b 100644 --- a/home/.zshrc +++ b/home/.zshrc @@ -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