From 74e201e92c31658eb6d7dcb56e1fdd6fdc43b2e4 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Sun, 4 May 2025 17:43:55 +0300 Subject: =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BA=D1=83=D1=87=D0=BA=D1=83=20=D0=BD=D0=B5=D0=B4=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D0=BA=D0=BE=D0=B2=20=D0=B2=20neovim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nvim/lua/plugins/cmp.lua | 116 +++++++++++++++++++++++++----------------- nvim/lua/plugins/dap.lua | 115 +++++++++++++++++++++++++++++++++++++++-- nvim/lua/plugins/dapui.lua | 4 +- nvim/lua/plugins/snippets.lua | 15 +++++- 4 files changed, 196 insertions(+), 54 deletions(-) (limited to 'nvim/lua/plugins') diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua index 24c1c47..0a7cffc 100644 --- a/nvim/lua/plugins/cmp.lua +++ b/nvim/lua/plugins/cmp.lua @@ -1,3 +1,10 @@ +local source_mapping = { + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + nvim_lua = "[Lua]", + luasnip = "[Snip]", + path = "[Path]", +} return { "hrsh7th/nvim-cmp", dependencies = { @@ -18,52 +25,69 @@ return { config = function() require("plugins.snippets") end, - }, - }, - 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 + keys = { + { + "", + function() + require("luasnip").expand() + end, + silent = true, + }, + { + "", + function() + require("luasnip").jump(1) + end, + silent = true, + }, + { + "", + function() 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, + end, + silent = true, + }, }, - sources = cmp.config.sources({ - { name = "nvim_lsp", priority = 1000 }, - { name = "luasnip", priority = 750 }, - { name = "path", priority = 500 }, - }, { - { name = "buffer" }, - }), - }) - end, + }, + }, + opts = { + -- preselect = require("cmp").PreselectMode.None, + experimental = { + ghost_text = true, + }, + + confirmation = { + default_behavior = require("cmp").ConfirmBehavior.Replace, + }, + completion = { + completeopt = "menu,menuone,noinsert,noselect", + keyword_length = 2, + }, + mapping = require("cmp").mapping.preset.insert({ + [""] = require("cmp").mapping.scroll_docs(-4), + [""] = require("cmp").mapping.scroll_docs(4), + [""] = require("cmp").mapping.complete(), + [""] = require("cmp").mapping.abort(), + [""] = require("cmp").mapping.confirm({ select = false }), + [""] = require("cmp").mapping.confirm({ select = true }), + }), + 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 = require("cmp").config.sources({ + { name = "nvim_lsp", priority = 1000 }, + { name = "luasnip", priority = 750 }, + { name = "path", priority = 500 }, + }, { + { name = "buffer" }, + }), + }, } diff --git a/nvim/lua/plugins/dap.lua b/nvim/lua/plugins/dap.lua index 0d104d9..58cc7f9 100644 --- a/nvim/lua/plugins/dap.lua +++ b/nvim/lua/plugins/dap.lua @@ -1,3 +1,103 @@ +local default_config = { + delve = { + path = "dlv", + initialize_timeout_sec = 20, + port = "${port}", + args = {}, + build_flags = "", + -- Automatically handle the issue on delve Windows versions < 1.24.0 + -- where delve needs to be run in attched mode or it will fail (actually crashes). + detached = vim.fn.has("win32") == 0, + output_mode = "remote", + }, + tests = { + verbose = false, + }, +} + +local function setup_go_configuration(dap, configs) + local common_debug_configs = { + { + type = "go", + name = "Debug", + request = "launch", + program = "${file}", + buildFlags = configs.delve.build_flags, + outputMode = configs.delve.output_mode, + }, + { + type = "go", + name = "Debug (Arguments)", + request = "launch", + program = "${file}", + args = get_arguments, + buildFlags = configs.delve.build_flags, + outputMode = configs.delve.output_mode, + }, + { + type = "go", + name = "Debug (Arguments & Build Flags)", + request = "launch", + program = "${file}", + args = get_arguments, + buildFlags = get_build_flags, + outputMode = configs.delve.output_mode, + }, + { + type = "go", + name = "Debug Package", + request = "launch", + program = "${fileDirname}", + buildFlags = configs.delve.build_flags, + outputMode = configs.delve.output_mode, + }, + { + type = "go", + name = "Attach", + mode = "local", + request = "attach", + processId = filtered_pick_process, + buildFlags = configs.delve.build_flags, + }, + { + type = "go", + name = "Debug test", + request = "launch", + mode = "test", + program = "${file}", + buildFlags = configs.delve.build_flags, + outputMode = configs.delve.output_mode, + }, + { + type = "go", + name = "Debug test (go.mod)", + request = "launch", + mode = "test", + program = "./${relativeFileDirname}", + buildFlags = configs.delve.build_flags, + outputMode = configs.delve.output_mode, + }, + } + + if dap.configurations.go == nil then + dap.configurations.go = {} + end + + for _, config in ipairs(common_debug_configs) do + table.insert(dap.configurations.go, config) + end + + if configs == nil or configs.dap_configurations == nil then + return + end + + for _, config in ipairs(configs.dap_configurations) do + if config.type == "go" then + table.insert(dap.configurations.go, config) + end + end +end + return { "leoluz/nvim-dap-go", dependencies = { "mfussenegger/nvim-dap" }, @@ -13,6 +113,10 @@ return { args = { "dap", "-l", "127.0.0.1:${port}" }, }, } + + setup_go_configuration(dap, default_config) + + dap.defaults.fallback.terminal_win_cmd = "enew | set filetype=dap-terminal" dap.listeners.before.attach.dapui_config = function() dapui.open() end @@ -25,29 +129,30 @@ return { 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" } + { text = "!", texthl = "DapBreakpoint", linehl = "DapBreakpoint", numhl = "DapBreakpoint" } ) vim.fn.sign_define( "DapBreakpointCondition", - { text = "ﳁ", texthl = "DapBreakpoint", linehl = "DapBreakpoint", numhl = "DapBreakpoint" } + { text = "?", texthl = "DapBreakpoint", linehl = "DapBreakpoint", numhl = "DapBreakpoint" } ) vim.fn.sign_define( "DapBreakpointRejected", - { text = "", texthl = "DapBreakpoint", linehl = "DapBreakpoint", numhl = "DapBreakpoint" } + { text = "RJ", texthl = "DapBreakpoint", linehl = "DapBreakpoint", numhl = "DapBreakpoint" } ) vim.fn.sign_define( "DapLogPoint", - { text = "", texthl = "DapLogPoint", linehl = "DapLogPoint", numhl = "DapLogPoint" } + { text = "i", texthl = "DapLogPoint", linehl = "DapLogPoint", numhl = "DapLogPoint" } ) vim.fn.sign_define( "DapStopped", - { text = "", texthl = "DapStopped", linehl = "DapStopped", numhl = "DapStopped" } + { text = "→", texthl = "DapStopped", linehl = "DapStopped", numhl = "DapStopped" } ) end, keys = { diff --git a/nvim/lua/plugins/dapui.lua b/nvim/lua/plugins/dapui.lua index f5d1532..b63e2ac 100644 --- a/nvim/lua/plugins/dapui.lua +++ b/nvim/lua/plugins/dapui.lua @@ -37,8 +37,8 @@ return { }, opts = { icons = { - expanded = "▾", - collapsed = "▸", + expanded = "[-]", + collapsed = "[+]", }, mappings = { open = "o", diff --git a/nvim/lua/plugins/snippets.lua b/nvim/lua/plugins/snippets.lua index bf40e7c..f1f0f62 100644 --- a/nvim/lua/plugins/snippets.lua +++ b/nvim/lua/plugins/snippets.lua @@ -1,4 +1,16 @@ -require("luasnip").config.setup({ +local ls = require("luasnip") +local s = ls.snippet +local sn = ls.snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local fmt = require("luasnip.extras.fmt").fmt +local rep = require("luasnip.extras").rep + +ls.config.setup({ history = true, update_events = "TextChanged,TextChangedI", }) @@ -6,3 +18,4 @@ require("luasnip.loaders.from_vscode").lazy_load() require("luasnip.loaders.from_vscode").lazy_load({ paths = { vim.fn.stdpath("config") .. "/snippets" }, }) +ls.add_snippets("json", require("snippets.json")) -- cgit v1.2.3