From 446d2716e7bb83e58fb516ec27e5c7750069e98c Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Fri, 2 May 2025 16:05:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=88=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=20lazy=20nvim,=20=D0=BD=D0=B0=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=8F=D0=B4=D0=BE=D0=BA=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nvim/init.lua | 27 ++++-- nvim/lazy-lock.json | 36 ++++++++ nvim/lua/autocommands.lua | 11 ++- nvim/lua/colors.lua | 39 -------- nvim/lua/keymaps.lua | 104 ++++----------------- nvim/lua/lsp.lua | 56 ++--------- nvim/lua/options.lua | 10 +- nvim/lua/plugins.lua | 54 +++++++++++ nvim/lua/plugins/cmp.lua | 104 +++++++++++++-------- nvim/lua/plugins/columns.lua | 10 ++ nvim/lua/plugins/conform.lua | 34 +++++++ nvim/lua/plugins/dap.lua | 158 ++++++++++++++++++++++++++++++-- nvim/lua/plugins/dapui.lua | 75 +++++++++++++++ nvim/lua/plugins/format.lua | 28 ------ nvim/lua/plugins/go.lua | 12 +++ nvim/lua/plugins/goimpl.lua | 21 +++++ nvim/lua/plugins/init.lua | 99 -------------------- nvim/lua/plugins/lualine.lua | 77 ++++++++-------- nvim/lua/plugins/onedark.lua | 33 +++++++ nvim/lua/plugins/snippets.lua | 8 ++ nvim/lua/plugins/telescope.lua | 23 +++-- nvim/lua/plugins/tree.lua | 68 +++++++++----- nvim/lua/plugins/treesitter.lua | 111 ++++++++++++---------- nvim/snippets/go.json | 23 +++++ nvim/snippets/package.json | 38 ++++++++ 25 files changed, 790 insertions(+), 469 deletions(-) create mode 100644 nvim/lazy-lock.json delete mode 100644 nvim/lua/colors.lua create mode 100644 nvim/lua/plugins.lua create mode 100644 nvim/lua/plugins/columns.lua create mode 100644 nvim/lua/plugins/conform.lua create mode 100644 nvim/lua/plugins/dapui.lua delete mode 100644 nvim/lua/plugins/format.lua create mode 100644 nvim/lua/plugins/go.lua create mode 100644 nvim/lua/plugins/goimpl.lua delete mode 100644 nvim/lua/plugins/init.lua create mode 100644 nvim/lua/plugins/onedark.lua create mode 100644 nvim/lua/plugins/snippets.lua create mode 100644 nvim/snippets/go.json create mode 100644 nvim/snippets/package.json diff --git a/nvim/init.lua b/nvim/init.lua index e62059f..2f4316d 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,14 +1,23 @@ -local fn = vim.fn -local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" -if fn.empty(fn.glob(install_path)) > 0 then - packer_bootstrap = - fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }) +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end end - +vim.opt.rtp:prepend(lazypath) vim.g.mapleader = " " vim.g.maplocalleader = " " - -vim.cmd([[packadd packer.nvim]]) +vim.g.colorcolumn = 120 +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 require("options") require("plugins") @@ -16,4 +25,4 @@ require("keymaps") require("autocommands") require("lsp") require("dap") -require("colors") +require("onedark").load() diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 0000000..640d111 --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,36 @@ +{ + "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, + "cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "conform.nvim": { "branch": "master", "commit": "372fc521f8421b7830ea6db4d6ea3bae1c77548c" }, + "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, + "go.nvim": { "branch": "master", "commit": "37ec4d9be3edef64b725bfe29684e1fe019873bc" }, + "goerr-nvim": { "branch": "main", "commit": "d30ba1cab652e78dbf6a644eb4823be57e9af203" }, + "goimpl.nvim": { "branch": "main", "commit": "2548d42c4db0645dea14f27e67c4b19b7030f1cf" }, + "guihua.lua": { "branch": "master", "commit": "0cc9631914ffcbe3e474e809c610d12a75b660cf" }, + "headlines.nvim": { "branch": "master", "commit": "bf17c96a836ea27c0a7a2650ba385a7783ed322e" }, + "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, + "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "lsp_signature.nvim": { "branch": "master", "commit": "a793d02b6a5e639fa9d3f2a89a839fa688ab2d0a" }, + "lualine.nvim": { "branch": "master", "commit": "15884cee63a8c205334ab13ab1c891cd4d27101a" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, + "nvim-dap": { "branch": "master", "commit": "8df427aeba0a06c6577dc3ab82de3076964e3b8d" }, + "nvim-dap-go": { "branch": "main", "commit": "8763ced35b19c8dc526e04a70ab07c34e11ad064" }, + "nvim-dap-ui": { "branch": "master", "commit": "73a26abf4941aa27da59820fd6b028ebcdbcf932" }, + "nvim-lspconfig": { "branch": "master", "commit": "12506bdaccd94964d4fb40367e36ade1960c8947" }, + "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, + "nvim-tree.lua": { "branch": "master", "commit": "582ae48c9e43d2bcd55dfcc8e2e7a1f29065d924" }, + "nvim-treesitter": { "branch": "master", "commit": "94ea4f436d2b59c80f02e293466c374584f03b8c" }, + "nvim-treesitter-context": { "branch": "master", "commit": "6daca3ad780f045550b820f262002f35175a6c04" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "ed373482db797bbf71bdff37a15c7555a84dce47" }, + "nvim-web-devicons": { "branch": "master", "commit": "2c2b4eafce6cdd0cb165036faa17396eff18f847" }, + "onedark.nvim": { "branch": "master", "commit": "0e5512d1bebd1f08954710086f87a5caa173a924" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, + "popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" }, + "smartcolumn.nvim": { "branch": "main", "commit": "92f3773af80d674f1eb61e112dca79e2fa449fd1" }, + "telescope-file-browser.nvim": { "branch": "master", "commit": "626998e5c1b71c130d8bc6cf7abb6709b98287bb" }, + "telescope.nvim": { "branch": "master", "commit": "a4ed82509cecc56df1c7138920a1aeaf246c0ac5" }, + "vim-snippets": { "branch": "master", "commit": "f0a3184d9f90b96b044d5914625a25c554d7f301" } +} diff --git a/nvim/lua/autocommands.lua b/nvim/lua/autocommands.lua index a0a7e5e..0e95ee4 100644 --- a/nvim/lua/autocommands.lua +++ b/nvim/lua/autocommands.lua @@ -124,7 +124,16 @@ vim.api.nvim_create_autocmd({ "BufReadPost", "BufWinEnter", "WinEnter" }, { end end, }) - +vim.api.nvim_create_autocmd({ "VimEnter" }, { + callback = function(data) + local directory = vim.fn.isdirectory(data.file) == 1 + if not directory then + return + end + vim.cmd.cd(data.file) + require("nvim-tree.api").tree.open() + end, +}) -- vim.api.nvim_create_autocmd("InsertEnter", { -- pattern = "*", -- command = "set norelativenumber", diff --git a/nvim/lua/colors.lua b/nvim/lua/colors.lua deleted file mode 100644 index e5d90ef..0000000 --- a/nvim/lua/colors.lua +++ /dev/null @@ -1,39 +0,0 @@ -require("onedark").setup({ - style = "darker", - transparent = false, -- Show/hide background - term_colors = true, -- Change terminal color as per the selected theme style - ending_tildes = true, -- Show the end-of-buffer tildes. By default they are hidden - cmp_itemkind_reverse = false, -- reverse item kind highlights in cmp menu - - -- toggle theme style --- - toggle_style_key = nil, -- keybind to toggle theme style. Leave it nil to disable it, or set it to a string, for example "ts" - toggle_style_list = { "dark", "darker", "cool", "deep", "warm", "warmer", "light" }, -- List of styles to toggle between - - -- Change code style --- - -- Options are italic, bold, underline, none - -- You can configure multiple style with comma separated, For e.g., keywords = 'italic,bold' - code_style = { - comments = "italic", - keywords = "none", - functions = "none", - strings = "none", - variables = "none", - }, - - -- Lualine options -- - lualine = { - transparent = false, -- lualine center bar transparency - }, - - -- Custom Highlights -- - colors = {}, -- Override default colors - highlights = {}, -- Override highlight groups - - -- Plugins Config -- - diagnostics = { - darker = true, -- darker colors for diagnostic - undercurl = true, -- use undercurl instead of underline for diagnostics - background = true, -- use background color for virtual text - }, -}) -require("onedark").load() diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua index 7de2235..34ff6c1 100644 --- a/nvim/lua/keymaps.lua +++ b/nvim/lua/keymaps.lua @@ -19,15 +19,16 @@ map("v", "K", ":m '<-2gv=gv", { noremap = true, silent = true }) map("v", "<", "", ">gv", { noremap = true, silent = true }) --- Управление буферами -- +-- {{{ Управление буферами -- kmap("n", "bn", "bnext", { noremap = true, silent = true, desc = "Next buffer" }) kmap("n", "bp", "bprevious", { noremap = true, silent = true, desc = "Previous buffer" }) kmap("n", "bd", "bdelete", { noremap = true, silent = true, desc = "Delete buffer" }) kmap("n", "w", "wa", { noremap = true, silent = true, desc = "Save all files" }) kmap("n", "qq", "q", { noremap = true, silent = true, desc = "Exit" }) kmap("n", "vs", "vsplit", { noremap = true, silent = true, desc = "Vertical split" }) +-- }}} --- Управление вкладками -- +-- {{{ Управление вкладками -- kmap("n", "", ":tabnext", { noremap = true, silent = true, desc = "Next tab" }) kmap("n", "", ":tabprevious", { noremap = true, silent = true, desc = "Previous tab" }) kmap("n", "tn", ":tabnew", { noremap = true, silent = true, desc = "New tab" }) @@ -38,116 +39,51 @@ for i = 1, 9 do kmap("n", "", ":tabn " .. i .. "", { noremap = true, silent = true, desc = "Go to tab " .. i }) end --- Файловый менеджер -- -kmap("n", "", ":NvimTreeToggle", { noremap = true, silent = true, desc = "Toggle file tree" }) --- kmap("n", "tt", ":NvimTreeToggle", { noremap = true, silent = true, desc = "Toggle file tree" }) +-- }}} kmap("n", "tt", ":split:terminal:startinsert", { noremap = true, silent = true }) --- Поиск с Telescope -- -kmap("n", "ff", "Telescope find_files", { noremap = true, silent = true, desc = "Find files" }) -kmap("n", "fg", "Telescope live_grep", { noremap = true, silent = true, desc = "Live grep" }) -kmap("n", "fb", "Telescope buffers", { noremap = true, silent = true, desc = "Find buffers" }) -kmap("n", "fe", "Telescope file_browser", { noremap = true, silent = true, desc = "File browser" }) - --- LSP функции -- +-- {{{ LSP функции kmap("n", "e", vim.diagnostic.open_float, { noremap = true, silent = true, desc = "Show diagnostics" }) + kmap("n", "d[", vim.diagnostic.goto_prev, { noremap = true, silent = true, desc = "Previous diagnostic" }) + kmap("n", "d]", vim.diagnostic.goto_next, { noremap = true, silent = true, desc = "Next diagnostic" }) kmap("n", "gD", vim.lsp.buf.declaration, { noremap = true, silent = true, desc = "Go to declaration" }) + kmap("n", "gd", vim.lsp.buf.definition, { noremap = true, silent = true, desc = "Go to definition" }) + kmap("n", "K", vim.lsp.buf.hover, { noremap = true, silent = true, desc = "Show documentation" }) + kmap("n", "gi", vim.lsp.buf.implementation, { noremap = true, silent = true, desc = "Go to implementation" }) + kmap("n", "", vim.lsp.buf.signature_help, { noremap = true, silent = true, desc = "Signature help" }) + kmap( "n", "wa", vim.lsp.buf.add_workspace_folder, { noremap = true, silent = true, desc = "Add workspace folder" } ) + kmap( "n", "wr", vim.lsp.buf.remove_workspace_folder, { noremap = true, silent = true, desc = "Remove workspace folder" } ) + kmap("n", "wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, { noremap = true, silent = true, desc = "List workspace folders" }) + kmap("n", "D", vim.lsp.buf.type_definition, { noremap = true, silent = true, desc = "Type definition" }) -kmap("n", "rn", vim.lsp.buf.rename, { noremap = true, silent = true, desc = "Rename symbol" }) -kmap("n", "ca", vim.lsp.buf.code_action, { noremap = true, silent = true, desc = "Code actions" }) + +kmap("n", "", vim.lsp.buf.code_action, { noremap = true, silent = true, desc = "Code actions" }) + kmap("n", "gr", vim.lsp.buf.references, { noremap = true, silent = true, desc = "Find references" }) --- Отладка (DAP) -- -kmap("n", "", "lua require'dapui'.toggle()", { noremap = true, silent = true, desc = "Toggle debug UI" }) -kmap("n", "", function() - require("dap").continue() -end) -kmap("n", "", function() - require("dap").step_over() -end) -kmap("n", "", function() - require("dap").step_into() -end) -kmap("n", "", function() - require("dap").step_out() -end) -kmap( - "n", - "dt", - "lua require'dapui'.toggle()", - { noremap = true, silent = true, desc = "Toggle debug UI" } -) -kmap("n", "dc", function() - require("dap").continue() -end) -kmap("n", "so", function() - require("dap").step_over() -end) -kmap("n", "si", function() - require("dap").step_into() -end) -kmap("n", "st", function() - require("dap").step_out() -end) +kmap("n", "", vim.lsp.buf.rename, { noremap = true, silent = true, desc = "Rename symbol" }) -kmap("n", "b", function() - require("dap").toggle_breakpoint() -end) -kmap("n", "B", function() - require("dap").set_breakpoint() -end) -kmap("n", "lp", function() - require("dap").set_breakpoint(nil, nil, vim.fn.input("Log point message: ")) -end) -kmap("n", "dr", function() - require("dap").repl.open() -end) -kmap("n", "dl", function() - require("dap").run_last() -end) -kmap({ "n", "v" }, "dh", function() - require("dap.ui.widgets").hover() -end) -kmap({ "n", "v" }, "dp", function() - require("dap.ui.widgets").preview() -end) -kmap("n", "df", function() - local widgets = require("dap.ui.widgets") - widgets.centered_float(widgets.frames) -end) -kmap("n", "ds", function() - local widgets = require("dap.ui.widgets") - widgets.centered_float(widgets.scopes) -end) - --- Кастомная функция для NvimTree -- -local function change_root_to_global_cwd() - local api = require("nvim-tree.api") - local global_cwd = vim.fn.getcwd(-1, -1) - api.tree.change_root(global_cwd) -end - -kmap("n", "", change_root_to_global_cwd, { noremap = true, silent = true, desc = "Change tree root to CWD" }) +-- }}} diff --git a/nvim/lua/lsp.lua b/nvim/lua/lsp.lua index 468ea71..5f04683 100644 --- a/nvim/lua/lsp.lua +++ b/nvim/lua/lsp.lua @@ -1,48 +1,10 @@ - -local cmp = require('cmp') - -local source_mapping = { - buffer = '[Buffer]', - nvim_lsp = '[LSP]', - nvim_lua = '[Lua]', - cmp_tabnine = '[TN]', - path = '[Path]', -} - -cmp.setup({ - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - }), - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - formatting = { - format = function(entry, vim_item) - local menu = source_mapping[entry.source.name] - vim_item.menu = menu - return vim_item - end - }, - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, { - { name = 'buffer' }, - }) -}) - -- инициализация LSP для различных ЯП -local lspconfig = require('lspconfig') -local util = require('lspconfig/util') +local lspconfig = require("lspconfig") +local util = require("lspconfig/util") local function config(_config) - return vim.tbl_deep_extend('force', { - capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()), + return vim.tbl_deep_extend("force", { + capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()), }, _config or {}) end @@ -50,9 +12,9 @@ end -- https://github.com/golang/tools/blob/master/gopls/doc/vim.md#neovim-install lspconfig.gopls.setup(config({ on_attach = on_attach, - cmd = { 'gopls', 'serve' }, - filetypes = { 'go', 'go.mod' }, - root_dir = util.root_pattern('go.work', 'go.mod', '.git'), + cmd = { "gopls", "serve" }, + filetypes = { "go", "go.mod" }, + root_dir = util.root_pattern("go.work", "go.mod", ".git"), settings = { gopls = { analyses = { @@ -60,6 +22,6 @@ lspconfig.gopls.setup(config({ shadow = true, }, staticcheck = true, - } - } + }, + }, })) diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua index c6e38f4..583e638 100644 --- a/nvim/lua/options.lua +++ b/nvim/lua/options.lua @@ -1,6 +1,3 @@ -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 - local options = { backup = false, clipboard = "unnamedplus", @@ -35,9 +32,10 @@ local options = { scrolloff = 8, sidescrolloff = 8, syntax = "on", - foldmethod = "expr", - foldexpr = "nvim_treesitter#foldexpr()", - foldlevelstart = 99, + foldmethod = "marker", + foldmarker = "{{{,}}}", + --foldexpr = "nvim_treesitter#foldexpr()", + foldlevelstart = 0, foldenable = true, } diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua new file mode 100644 index 0000000..4b0b605 --- /dev/null +++ b/nvim/lua/plugins.lua @@ -0,0 +1,54 @@ +local plugins = { + { "nvim-lua/plenary.nvim" }, + { "neovim/nvim-lspconfig" }, + { "Snyssfx/goerr-nvim" }, + { + "lukas-reineke/indent-blankline.nvim", + main = "ibl", + --@module "ibl" + --@type ibl.config + config = true, + }, + { + "lukas-reineke/headlines.nvim", + dependencies = "nvim-treesitter/nvim-treesitter", + config = true, + }, + { + "mfussenegger/nvim-dap", + }, + { + "ray-x/lsp_signature.nvim", + event = "VeryLazy", + config = true, + }, + require("plugins.cmp"), + require("plugins.onedark"), + require("plugins.treesitter"), + require("plugins.tree"), + require("plugins.conform"), + require("plugins.dapui"), + require("plugins.dap"), + require("plugins.go"), + require("plugins.goimpl"), + require("plugins.lualine"), + require("plugins.telescope"), + require("plugins.columns"), +} + +require("lazy").setup(plugins, { + performance = { + rtp = { + disabled_plugins = { + "gzip", + "matchit", + "matchparen", + "netrwPlugin", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin", + }, + }, + }, +}) diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua index 923cb09..24c1c47 100644 --- a/nvim/lua/plugins/cmp.lua +++ b/nvim/lua/plugins/cmp.lua @@ -1,39 +1,69 @@ -local cmp = require'cmp' -cmp.setup{ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) - - -- For `mini.snippets` users: - -- local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert - -- insert({ body = args.body }) -- Insert at cursor - -- cmp.resubscribe({ "TextChangedI", "TextChangedP" }) - -- require("cmp.config").set_onetime({ sources = {} }) - end, +return { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "saadparwaiz1/cmp_luasnip", + { + "L3MON4D3/LuaSnip", + lazy = true, + version = "v2.*", + build = "make install_jsregexp", + opts = { + history = true, + delete_check_events = "TextChanged", + }, + dependencies = { "rafamadriz/friendly-snippets" }, + config = function() + require("plugins.snippets") + end, + }, }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'vsnip' }, -- For vsnip users. - -- { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. - }, { - { name = 'buffer' }, - }) + config = function() + local cmp = require("cmp") + local source_mapping = { + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + nvim_lua = "[Lua]", + path = "[Path]", + } + cmp.setup({ + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if require("luasnip").expand_or_jumpable() then + require("luasnip").expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + formatting = { + format = function(entry, vim_item) + vim_item.menu = source_mapping[entry.source.name] or "[Unknown]" + return vim_item + end, + }, + sources = cmp.config.sources({ + { name = "nvim_lsp", priority = 1000 }, + { name = "luasnip", priority = 750 }, + { name = "path", priority = 500 }, + }, { + { name = "buffer" }, + }), + }) + end, } diff --git a/nvim/lua/plugins/columns.lua b/nvim/lua/plugins/columns.lua new file mode 100644 index 0000000..40806e2 --- /dev/null +++ b/nvim/lua/plugins/columns.lua @@ -0,0 +1,10 @@ +return { + "m4xshen/smartcolumn.nvim", + opts = { + colorcolumn = "80", + disabled_filetypes = { "help", "text" }, + custom_colorcolumn = {}, + scope = "file", + editorconfig = true, + }, +} diff --git a/nvim/lua/plugins/conform.lua b/nvim/lua/plugins/conform.lua new file mode 100644 index 0000000..ea0fcf0 --- /dev/null +++ b/nvim/lua/plugins/conform.lua @@ -0,0 +1,34 @@ +return { + "stevearc/conform.nvim", + opts = { + formatters_by_ft = { + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + css = { "prettier" }, + html = { "prettier" }, + json = { "prettier" }, + yaml = { "prettier" }, + markdown = { "prettier" }, + graphql = { "prettier" }, + lua = { "stylua" }, + python = { "isort", "black" }, + go = { "gofmt" }, + }, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 500, + }, + }, + keys = { + { + "mp", + function() + require("conform").format({ lsp_fallback = true, async = false, timeout_ms = 500 }) + end, + desc = "Format file or range (in visual mode)", + }, + }, +} diff --git a/nvim/lua/plugins/dap.lua b/nvim/lua/plugins/dap.lua index 7c7f773..0d104d9 100644 --- a/nvim/lua/plugins/dap.lua +++ b/nvim/lua/plugins/dap.lua @@ -1,9 +1,153 @@ -require("dap-go").setup() -require("dap").adapters.go = { - type = "server", - port = "${port}", - executable = { - command = "dlv", - args = { "dap", "-l", "127.0.0.1:${port}" }, +return { + "leoluz/nvim-dap-go", + dependencies = { "mfussenegger/nvim-dap" }, + opts = true, + config = function() + local dap, dapui = require("dap"), require("dapui") + + dap.adapters.go = { + type = "server", + port = "${port}", + executable = { + command = "dlv", + args = { "dap", "-l", "127.0.0.1:${port}" }, + }, + } + dap.listeners.before.attach.dapui_config = function() + dapui.open() + end + dap.listeners.before.launch.dapui_config = function() + dapui.open() + end + dap.listeners.before.event_terminated.dapui_config = function() + dapui.close() + end + dap.listeners.before.event_exited.dapui_config = function() + dapui.close() + end + vim.api.nvim_set_hl(0, "DapBreakpoint", { ctermbg = 0, fg = "#993939", bg = "#31353f" }) + vim.api.nvim_set_hl(0, "DapLogPoint", { ctermbg = 0, fg = "#61afef", bg = "#31353f" }) + vim.api.nvim_set_hl(0, "DapStopped", { ctermbg = 0, fg = "#98c379", bg = "#31353f" }) + + vim.fn.sign_define( + "DapBreakpoint", + { text = "🐞", texthl = "DapBreakpoint", linehl = "DapBreakpoint", numhl = "DapBreakpoint" } + ) + vim.fn.sign_define( + "DapBreakpointCondition", + { text = "ﳁ", texthl = "DapBreakpoint", linehl = "DapBreakpoint", numhl = "DapBreakpoint" } + ) + vim.fn.sign_define( + "DapBreakpointRejected", + { text = "", texthl = "DapBreakpoint", linehl = "DapBreakpoint", numhl = "DapBreakpoint" } + ) + vim.fn.sign_define( + "DapLogPoint", + { text = "", texthl = "DapLogPoint", linehl = "DapLogPoint", numhl = "DapLogPoint" } + ) + vim.fn.sign_define( + "DapStopped", + { text = "", texthl = "DapStopped", linehl = "DapStopped", numhl = "DapStopped" } + ) + end, + keys = { + { + "", + function() + require("dap").continue() + end, + silent = true, + }, + { + "", + function() + require("dap").step_over() + end, + silent = true, + }, + { + "", + function() + require("dap").step_into() + end, + silent = true, + }, + { + "", + function() + require("dap").step_out() + end, + silent = true, + }, + { + "dc", + function() + require("dap").continue() + end, + silent = true, + }, + { + "so", + function() + require("dap").step_over() + end, + silent = true, + }, + { + "si", + function() + require("dap").step_into() + end, + silent = true, + }, + { + "st", + function() + require("dap").step_out() + end, + silent = true, + }, + { + "b", + function() + require("dap").toggle_breakpoint() + end, + silent = true, + }, + { + "", + function() + require("dap").toggle_breakpoint() + end, + silent = true, + }, + { + "B", + function() + require("dap").set_breakpoint() + end, + silent = true, + }, + { + "lp", + function() + require("dap").set_breakpoint(nil, nil, vim.fn.input("Log point message: ")) + end, + silent = true, + }, + { + "dr", + function() + require("dap").repl.open() + end, + silent = true, + }, + { + "dl", + function() + require("dap").run_last() + end, + silent = true, + }, }, } diff --git a/nvim/lua/plugins/dapui.lua b/nvim/lua/plugins/dapui.lua new file mode 100644 index 0000000..f5d1532 --- /dev/null +++ b/nvim/lua/plugins/dapui.lua @@ -0,0 +1,75 @@ +return { + "rcarriga/nvim-dap-ui", + dependencies = { + "mfussenegger/nvim-dap", + "nvim-neotest/nvim-nio", + }, + keys = { + { + "du", + function() + require("dapui").toggle() + end, + silent = true, + }, + { + "dh", + function() + require("dap.ui.widgets").hover() + end, + silent = true, + }, + { + "dp", + function() + require("dap.ui.widgets").preview() + end, + silent = true, + }, + { + "ds", + function() + local widgets = require("dap.ui.widgets") + widgets.centered_float(widgets.scopes) + end, + silent = true, + }, + }, + opts = { + icons = { + expanded = "▾", + collapsed = "▸", + }, + mappings = { + open = "o", + remove = "d", + edit = "e", + repl = "r", + toggle = "t", + }, + expand_lines = vim.fn.has("nvim-0.7"), + layouts = { + { + elements = { + "repl", + "breakpoints", + "scopes", + }, + size = 0.3, + position = "bottom", + }, + }, + floating = { + max_height = nil, + max_width = nil, + border = "single", + mappings = { + close = { "q", "" }, + }, + }, + windows = { indent = 1 }, + render = { + max_type_length = nil, + }, + }, +} diff --git a/nvim/lua/plugins/format.lua b/nvim/lua/plugins/format.lua deleted file mode 100644 index e226ab6..0000000 --- a/nvim/lua/plugins/format.lua +++ /dev/null @@ -1,28 +0,0 @@ -local conform = require("conform") - -conform.setup({ - formatters_by_ft = { - javascript = { "prettier" }, - typescript = { "prettier" }, - javascriptreact = { "prettier" }, - typescriptreact = { "prettier" }, - css = { "prettier" }, - html = { "prettier" }, - json = { "prettier" }, - yaml = { "prettier" }, - markdown = { "prettier" }, - graphql = { "prettier" }, - lua = { "stylua" }, - python = { "isort", "black" }, - go = { "gofmt" }, - }, - format_on_save = { - lsp_fallback = true, - async = false, - timeout_ms = 500, - }, -}) - -vim.keymap.set({ "n", "v" }, "mp", function() - conform.format({ lsp_fallback = true, async = false, timeout_ms = 500 }) -end, { desc = "Format file or range (in visual mode)" }) diff --git a/nvim/lua/plugins/go.lua b/nvim/lua/plugins/go.lua new file mode 100644 index 0000000..1078297 --- /dev/null +++ b/nvim/lua/plugins/go.lua @@ -0,0 +1,12 @@ +return { + "ray-x/go.nvim", + dependencies = { + "ray-x/guihua.lua", + "neovim/nvim-lspconfig", + "nvim-treesitter/nvim-treesitter", + }, + config = true, + event = { "CmdlineEnter" }, + ft = { "go", "gomod" }, + build = ':lua require("go.install").update_all_sync()', +} diff --git a/nvim/lua/plugins/goimpl.lua b/nvim/lua/plugins/goimpl.lua new file mode 100644 index 0000000..0b906fa --- /dev/null +++ b/nvim/lua/plugins/goimpl.lua @@ -0,0 +1,21 @@ +return { + "edolphin-ydf/goimpl.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-lua/popup.nvim", + "nvim-telescope/telescope.nvim", + "nvim-treesitter/nvim-treesitter", + }, + config = function() + require("telescope").load_extension("goimpl") + end, + keys = { + { + "im", + function() + require("telescope").extensions.goimpl.goimpl({}) + end, + desc = "Generate stub for interface on a type for golang", + }, + }, +} diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua deleted file mode 100644 index 0c3e6a5..0000000 --- a/nvim/lua/plugins/init.lua +++ /dev/null @@ -1,99 +0,0 @@ -return require("packer").startup({ - function(use) - use("wbthomason/packer.nvim") - use("nvim-lua/plenary.nvim") - use("neovim/nvim-lspconfig") - use("navarasu/onedark.nvim") - use("Snyssfx/goerr-nvim") - use({ - "lukas-reineke/indent-blankline.nvim", - config = function() - require("ibl").setup() - end, - }) - use({ - "rcarriga/nvim-dap-ui", - requires = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" }, - }) - use({ - "leoluz/nvim-dap-go", - requires = { "mfussenegger/nvim-dap" }, - config = function() - require("plugins.dap") - end, - }) - use({ - "hrsh7th/nvim-cmp", - requires = { - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-vsnip", - "hrsh7th/vim-vsnip", - }, - config = function() - require("plugins.cmp") - end, - }) - use({ - "nvim-lualine/lualine.nvim", - config = function() - require("plugins.lualine") - end, - }) - use({ - "nvim-treesitter/nvim-treesitter", - run = ":TSUpdate", - config = function() - require("plugins.treesitter") - end, - }) - use({ "nvim-telescope/telescope-file-browser.nvim" }) - use({ - "nvim-telescope/telescope.nvim", - config = function() - require("plugins.telescope") - end, - requires = "nvim-lua/plenary.nvim", - }) - use({ - "nvim-tree/nvim-tree.lua", - requires = { - "nvim-tree/nvim-web-devicons", - }, - config = function() - require("plugins.tree") - end, - }) - use({ - "stevearc/conform.nvim", - config = function() - require("plugins.format") - end, - }) - use({ - "mfussenegger/nvim-dap", - config = function() - local dap = require("dap") - -- Общие конфигурации для Go - dap.configurations.go = { - { - type = "go", - name = "Debug", - request = "launch", - program = "${file}", - showLog = true, - console = "integratedTerminal", - }, - } - end, - }) - if packer_bootstrap then - require("packer").sync() - end - end, - config = { - -- The root has to be a directory named "pack" - package_root = vim.fn.stdpath("data") .. "/site/pack", - }, -}) diff --git a/nvim/lua/plugins/lualine.lua b/nvim/lua/plugins/lualine.lua index 891b392..3be9d19 100644 --- a/nvim/lua/plugins/lualine.lua +++ b/nvim/lua/plugins/lualine.lua @@ -1,40 +1,43 @@ -require('lualine').setup { - options = { - icons_enabled = true, - theme = 'auto', - component_separators = { left = '', right = ''}, - section_separators = { left = '', right = ''}, - disabled_filetypes = { - statusline = {}, - winbar = {}, +return { + "nvim-lualine/lualine.nvim", + opts = { + options = { + icons_enabled = true, + theme = "auto", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + }, }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = false, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - } + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {}, }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', 'diagnostics'}, - lualine_c = {'filename'}, - lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_y = {'progress'}, - lualine_z = {'location'} - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {'filename'}, - lualine_x = {'location'}, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {} } diff --git a/nvim/lua/plugins/onedark.lua b/nvim/lua/plugins/onedark.lua new file mode 100644 index 0000000..f4c4aca --- /dev/null +++ b/nvim/lua/plugins/onedark.lua @@ -0,0 +1,33 @@ +return { + "navarasu/onedark.nvim", + opts = { + style = "darker", + transparent = false, -- Show/hide background + term_colors = true, -- Change terminal color as per the selected theme style + ending_tildes = true, -- Show the end-of-buffer tildes. By default they are hidden + cmp_itemkind_reverse = false, -- reverse item kind highlights in cmp menu + toggle_style_key = nil, -- keybind to toggle theme style. Leave it nil to disable it, or set it to a string, for example "ts" + toggle_style_list = { "dark", "darker", "cool", "deep", "warm", "warmer", "light" }, -- List of styles to toggle between + + code_style = { + comments = "italic", + keywords = "none", + functions = "none", + strings = "none", + variables = "none", + }, + + lualine = { + transparent = false, -- lualine center bar transparency + }, + + colors = {}, -- Override default colors + highlights = {}, -- Override highlight groups + + diagnostics = { + darker = true, -- darker colors for diagnostic + undercurl = true, -- use undercurl instead of underline for diagnostics + background = true, -- use background color for virtual text + }, + }, +} diff --git a/nvim/lua/plugins/snippets.lua b/nvim/lua/plugins/snippets.lua new file mode 100644 index 0000000..bf40e7c --- /dev/null +++ b/nvim/lua/plugins/snippets.lua @@ -0,0 +1,8 @@ +require("luasnip").config.setup({ + history = true, + update_events = "TextChanged,TextChangedI", +}) +require("luasnip.loaders.from_vscode").lazy_load() +require("luasnip.loaders.from_vscode").lazy_load({ + paths = { vim.fn.stdpath("config") .. "/snippets" }, +}) diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua index 9595d51..2348275 100644 --- a/nvim/lua/plugins/telescope.lua +++ b/nvim/lua/plugins/telescope.lua @@ -1,10 +1,19 @@ -require("telescope").setup({ - pickers = { - buffers = { - initial_mode = "normal", +return { + "nvim-telescope/telescope.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = { + pickers = { + buffers = { + initial_mode = "normal", + }, + }, + defaults = { + file_ignore_patterns = { "vendor", "node_modules" }, }, }, - defaults = { - file_ignore_patterns = { "vendor", "node_modules" }, + keys = { + { "ff", "Telescope find_files", noremap = true, silent = true, desc = "Find files" }, + { "fg", "Telescope live_grep", noremap = true, silent = true, desc = "Live grep" }, + { "fb", "Telescope buffers", noremap = true, silent = true, desc = "Find buffers" }, }, -}) +} diff --git a/nvim/lua/plugins/tree.lua b/nvim/lua/plugins/tree.lua index 320849b..4807024 100644 --- a/nvim/lua/plugins/tree.lua +++ b/nvim/lua/plugins/tree.lua @@ -1,27 +1,51 @@ -require("nvim-tree").setup({ - sort = { - sorter = "case_sensitive", +return { + "nvim-tree/nvim-tree.lua", + dependencies = { + "nvim-tree/nvim-web-devicons", }, - view = { - width = 30, - }, - git = { - enable = true, - }, - renderer = { - group_empty = true, - highlight_git = true, - icons = { - show = { - git = true, + opts = { + hijack_directories = { + enable = true, -- Перехватывать открытие директорий + auto_open = true, -- Автоматически открывать при старте + }, + sort = { + sorter = "case_sensitive", + }, + view = { + width = 30, + }, + git = { + enable = true, + }, + renderer = { + group_empty = true, + highlight_git = true, + icons = { + show = { + git = true, + }, }, }, + filters = { + dotfiles = false, + }, + update_focused_file = { + enable = true, + update_root = false, + }, }, - filters = { - dotfiles = false, + keys = { + { + "", + function() + local api = require("nvim-tree.api") + local global_cwd = vim.fn.getcwd(-1, -1) + api.tree.change_root(global_cwd) + end, + noremap = true, + silent = true, + desc = "Change tree root to CWD", + }, + { "", ":NvimTreeToggle", noremap = true, silent = true, desc = "Toggle file tree" }, }, - update_focused_file = { - enable = true, - update_root = false, - }, -}) +} diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index 623e808..f6127d7 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -1,47 +1,66 @@ -require("nvim-treesitter.configs").setup({ - highlight = { enable = true }, - ensure_installed = { - "c", - "lua", - "python", - "bash", - "go", - "html", - "css", - "javascript", - "typescript", - "git_config", - "git_rebase", - "gitattributes", - "gitcommit", - "gitignore", - "gomod", - "gosum", - "gotmpl", - "gowork", - "hjson", - "ini", - "json", - "json5", - "jsonnet", - "latex", - "make", - "markdown", - "markdown_inline", - "nginx", - "proto", - "rust", - "templ", - "todotxt", - "toml", - "tsx", - "typescript", - "vim", - "vimdoc", - "xml", - "yaml", - "sql", - "ssh_config", +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + opts = { + highlight = { enable = true }, + ensure_installed = { + "c", + "lua", + "python", + "bash", + "go", + "html", + "css", + "javascript", + "typescript", + "git_config", + "git_rebase", + "gitattributes", + "gitcommit", + "gitignore", + "gomod", + "gosum", + "gotmpl", + "gowork", + "hjson", + "ini", + "json", + "json5", + "jsonnet", + "latex", + "make", + "markdown", + "markdown_inline", + "nginx", + "proto", + "rust", + "templ", + "todotxt", + "toml", + "tsx", + "typescript", + "vim", + "vimdoc", + "xml", + "yaml", + "sql", + "ssh_config", + }, + ignore_install = { "gdhsader", "phpdoc" }, + indent = { enable = true }, + auto_install = true, + sync_install = false, + textobjects = { select = { enable = true, lookahead = true } }, }, - ignore_install = { "gdhsader", "phpdoc" }, -}) + dependencies = { + { "nvim-treesitter/nvim-treesitter-textobjects" }, + { + "nvim-treesitter/nvim-treesitter-context", + opts = { + enable = true, + mode = "topline", + line_numbers = true, + }, + }, + }, +} diff --git a/nvim/snippets/go.json b/nvim/snippets/go.json new file mode 100644 index 0000000..73b79b6 --- /dev/null +++ b/nvim/snippets/go.json @@ -0,0 +1,23 @@ +{ + "package line": { + "body": ["package ${TM_DIRECTORY/.+\\/(.+)$/${1:/downcase}/}", "", "$0"], + "description": "package header", + "prefix": "pkg" + }, + "structure constructor": { + "body": [ + "// New$1 returns new $1.", + "func New${1:type}(${2}) *$1 {", + "\t$3", + "\treturn &$1{$4}", + "}" + ], + "description": "constructor for structure type", + "prefix": "construct" + }, + "if err := ...; err != nil": { + "prefix": "iferr", + "body": "if err := ${1}; err != nil {\n\t${2:return ${3:nil, }${4:err}}\n}", + "description": "Snippet for if err := ...; err != nil" + } +} diff --git a/nvim/snippets/package.json b/nvim/snippets/package.json new file mode 100644 index 0000000..efb2b49 --- /dev/null +++ b/nvim/snippets/package.json @@ -0,0 +1,38 @@ +{ + "name": "gotools", + "displayName": "Golang Tools", + "description": "Tools for productive work", + "version": "0.1.5", + "engines": { + "vscode": "^1.80.0" + }, + "publisher": "neonxp", + "license": "GPL-3.0-or-later", + "author": { + "name": "Alexander NeonXP Kiryukhin", + "email": "a.kiryukhin@mail.ru", + "url": "https://neonxp.ru/" + }, + "repository": { + "type": "git", + "url": "https://github.com/neonxp/GoTools" + }, + "icon": "icon.png", + "categories": [ + "Programming Languages", + "Snippets", + "Other" + ], + "keywords": [ + "go", + "golang" + ], + "contributes": { + "snippets": [ + { + "language": "go", + "path": "./go.json" + } + ] + } +}