From fd9723504f65cf5db8da2f84a9c15ef6d5580fd7 Mon Sep 17 00:00:00 2001 From: hhhh hgfh Date: Sun, 12 Oct 2025 12:34:31 +0300 Subject: [PATCH] feat: complete settings for NeoVim with NvChad and C/C++ Debbuger --- .stylua.toml | 6 +++ init.lua | 40 ++++++++++++++++++++ lazy-lock.json | 34 +++++++++++++++++ lua/autocmds.lua | 1 + lua/chadrc.lua | 36 ++++++++++++++++++ lua/configs/conform.lua | 15 ++++++++ lua/configs/lazy.lua | 47 +++++++++++++++++++++++ lua/configs/lspconfig.lua | 23 ++++++++++++ lua/configs/nvim-dap.lua | 78 +++++++++++++++++++++++++++++++++++++++ lua/custom/init.lua | 7 ++++ lua/mappings.lua | 17 +++++++++ lua/options.lua | 6 +++ lua/plugins/init.lua | 51 +++++++++++++++++++++++++ 13 files changed, 361 insertions(+) create mode 100644 .stylua.toml create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/autocmds.lua create mode 100644 lua/chadrc.lua create mode 100644 lua/configs/conform.lua create mode 100644 lua/configs/lazy.lua create mode 100644 lua/configs/lspconfig.lua create mode 100644 lua/configs/nvim-dap.lua create mode 100644 lua/custom/init.lua create mode 100644 lua/mappings.lua create mode 100644 lua/options.lua create mode 100644 lua/plugins/init.lua diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..ecb6dca --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "None" diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..a6fba59 --- /dev/null +++ b/init.lua @@ -0,0 +1,40 @@ +vim.g.base46_cache = vim.fn.stdpath "data" .. "/base46/" +vim.g.mapleader = " " +vim.wo.number = true +vim.wo.relativenumber = true + +-- bootstrap lazy and all plugins +local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" + +if not vim.uv.fs_stat(lazypath) then + local repo = "https://github.com/folke/lazy.nvim.git" + vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath } +end + +vim.opt.rtp:prepend(lazypath) + +local lazy_config = require "configs.lazy" + +-- load plugins +require("lazy").setup({ + { + "NvChad/NvChad", + lazy = false, + branch = "v2.5", + import = "nvchad.plugins", + }, + + { import = "plugins" }, +}, lazy_config) + +-- load theme +dofile(vim.g.base46_cache .. "defaults") +dofile(vim.g.base46_cache .. "statusline") + +require "options" +require "autocmds" +require "custom.init" + +vim.schedule(function() + require "mappings" +end) diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..5edaeac --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,34 @@ +{ + "LuaSnip": { "branch": "master", "commit": "73813308abc2eaeff2bc0d3f2f79270c491be9d7" }, + "NvChad": { "branch": "v2.5", "commit": "f107fabe11ac8013dc3435ecd5382bee872b1584" }, + "base46": { "branch": "v3.0", "commit": "db58475d3fd2a16f9b1467d6895e3c4c195ed7dd" }, + "cmp-async-path": { "branch": "main", "commit": "0ed1492f59e730c366d261a5ad822fa37e44c325" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, + "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "conform.nvim": { "branch": "master", "commit": "fbcb4fa7f34bfea9be702ffff481a8e336ebf6ed" }, + "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, + "gitsigns.nvim": { "branch": "main", "commit": "1ee5c1fd068c81f9dd06483e639c2aa4587dc197" }, + "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, + "lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" }, + "mason-nvim-dap.nvim": { "branch": "main", "commit": "86389a3dd687cfaa647b6f44731e492970034baa" }, + "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, + "menu": { "branch": "main", "commit": "7a0a4a2896b715c066cfbe320bdc048091874cc6" }, + "minty": { "branch": "main", "commit": "aafc9e8e0afe6bf57580858a2849578d8d8db9e0" }, + "nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, + "nvim-dap": { "branch": "master", "commit": "881f7dc17c0b4204a1d844732f95539575350e5b" }, + "nvim-dap-ui": { "branch": "master", "commit": "cf91d5e2d07c72903d052f5207511bf7ecdb7122" }, + "nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" }, + "nvim-lspconfig": { "branch": "master", "commit": "ac98db2f9f06a56498ec890a96928774eae412c3" }, + "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, + "nvim-tree.lua": { "branch": "master", "commit": "e397756d2a79d74314ea4cd3efc41300e91c0ff0" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "nvim-web-devicons": { "branch": "master", "commit": "b8221e42cf7287c4dcde81f232f58d7b947c210d" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" }, + "ui": { "branch": "v3.0", "commit": "03b9718140375e7f3f5e4f3e04bc2b6c907440ec" }, + "volt": { "branch": "main", "commit": "620de1321f275ec9d80028c68d1b88b409c0c8b1" }, + "which-key.nvim": { "branch": "main", "commit": "b4177e3eaf15fe5eb8357ebac2286d488be1ed00" } +} diff --git a/lua/autocmds.lua b/lua/autocmds.lua new file mode 100644 index 0000000..d2db0bb --- /dev/null +++ b/lua/autocmds.lua @@ -0,0 +1 @@ +require "nvchad.autocmds" diff --git a/lua/chadrc.lua b/lua/chadrc.lua new file mode 100644 index 0000000..6dcaab7 --- /dev/null +++ b/lua/chadrc.lua @@ -0,0 +1,36 @@ +-- This file needs to have same structure as nvconfig.lua +-- https://github.com/NvChad/ui/blob/v3.0/lua/nvconfig.lua +-- Please read that file to know all available options :( + +---@type ChadrcConfig +local M = {} + +M.base46 = { + theme = "darcula-dark", + + -- hl_override = { + -- Comment = { italic = true }, + -- ["@comment"] = { italic = true }, + -- }, +} + +M.mason = { + opts ={ + ensure_installed = { + "lua-language-server", + "stylua", + "clangd", + "clang-format", + "codelldb" + } + } +} + +M.nvdash = { load_on_startup = true } +-- M.ui = { +-- tabufline = { +-- lazyload = false +-- } +-- } + +return M diff --git a/lua/configs/conform.lua b/lua/configs/conform.lua new file mode 100644 index 0000000..13561ed --- /dev/null +++ b/lua/configs/conform.lua @@ -0,0 +1,15 @@ +local options = { + formatters_by_ft = { + lua = { "stylua" }, + cpp = { "clang-format" }, + -- html = { "prettier" }, + }, + + -- format_on_save = { + -- -- These options will be passed to conform.format() + -- timeout_ms = 500, + -- lsp_fallback = true, + -- }, +} + +return options diff --git a/lua/configs/lazy.lua b/lua/configs/lazy.lua new file mode 100644 index 0000000..cd170bd --- /dev/null +++ b/lua/configs/lazy.lua @@ -0,0 +1,47 @@ +return { + defaults = { lazy = true }, + install = { colorscheme = { "nvchad" } }, + + ui = { + icons = { + ft = "", + lazy = "󰂠 ", + loaded = "", + not_loaded = "", + }, + }, + + performance = { + rtp = { + disabled_plugins = { + "2html_plugin", + "tohtml", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + "tutor", + "rplugin", + "syntax", + "synmenu", + "optwin", + "compiler", + "bugreport", + "ftplugin", + }, + }, + }, +} diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua new file mode 100644 index 0000000..7695ae3 --- /dev/null +++ b/lua/configs/lspconfig.lua @@ -0,0 +1,23 @@ +require("nvchad.configs.lspconfig").defaults() + +local on_attach = require("nvchad.configs.lspconfig").on_attach +local on_init = require("nvchad.configs.lspconfig").on_init +local capabilities = require("nvchad.configs.lspconfig").capabilities + +-- Новый способ настройки LSP для Neovim 0.11+ +vim.lsp.config('clangd', { + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, + cmd = { + "clangd", + "--background-index", + "--clang-tidy", + "--header-insertion=iwyu", + "--completion-style=detailed", + "--function-arg-placeholders=1", + }, + filetypes = { "c", "cpp", "objc", "objcpp" }, +}) + +vim.lsp.enable('clangd') diff --git a/lua/configs/nvim-dap.lua b/lua/configs/nvim-dap.lua new file mode 100644 index 0000000..0cb3014 --- /dev/null +++ b/lua/configs/nvim-dap.lua @@ -0,0 +1,78 @@ +local M = {} + +function M.setup() + local dap = require("dap") + local dapui = require("dapui") + + -- Настройка адаптера codelldb для C/C++ + dap.adapters.codelldb = { + type = 'server', + port = '${port}', + executable = { + command = vim.fn.stdpath("data") .. '/mason/bin/codelldb', + args = { '--port', '${port}' }, + } + } + + -- Конфигурации для C/C++ + dap.configurations.cpp = { + { + name = "Launch file", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + }, + } + + -- Используем те же конфигурации для C + dap.configurations.c = dap.configurations.cpp + + -- Настройка dap-ui :cite[1]:cite[4] + dapui.setup({ + layouts = { + { + elements = { + { id = "scopes", size = 0.33 }, + { id = "breakpoints", size = 0.17 }, + { id = "stacks", size = 0.25 }, + { id = "watches", size = 0.25 }, + }, + size = 0.33, + position = "right", + }, + { + elements = { + { id = "repl", size = 0.45 }, + { id = "console", size = 0.55 }, + }, + size = 0.27, + position = "bottom", + }, + }, + }) + + -- Автоматическое открытие/закрытие UI :cite[1]:cite[9] + dap.listeners.after.event_initialized["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 + + -- Настройка значков для точек останова :cite[1]:cite[10] + vim.fn.sign_define("DapBreakpoint", { text = "🔴", texthl = "LspDiagnosticsSignError" }) + vim.fn.sign_define("DapStopped", { text = "➡️", texthl = "LspDiagnosticsSignInformation" }) + vim.fn.sign_define("DapBreakpointRejected", { text = "❌", texthl = "LspDiagnosticsSignHint" }) +end + +return M diff --git a/lua/custom/init.lua b/lua/custom/init.lua new file mode 100644 index 0000000..b35cadd --- /dev/null +++ b/lua/custom/init.lua @@ -0,0 +1,7 @@ +-- форматирование при сохранении для C/C++ +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = { "*.c", "*.cpp", "*.h", "*.hpp" }, + callback = function() + vim.lsp.buf.format() + end, +}) diff --git a/lua/mappings.lua b/lua/mappings.lua new file mode 100644 index 0000000..95e9011 --- /dev/null +++ b/lua/mappings.lua @@ -0,0 +1,17 @@ +require "nvchad.mappings" +-- add yours here + +local map = vim.keymap.set + +map("n", ";", ":", { desc = "CMD enter command mode" }) +map("i", "jk", "") +-- map({ "n", "i", "v" }, "", " w ") + +-- Debbuger mappings +map('n', 'db', 'DapToggleBreakpoint', { desc = 'Toggle breakpoint' }) +map('n', 'dr', 'DapContinue', { desc = 'Start/continue debug' }) +map('n', 'ds', 'DapStepOver', { desc = 'Step over' }) +map('n', 'di', 'DapStepInto', { desc = 'Step into' }) +map('n', 'do', 'DapStepOut', { desc = 'Step out' }) +map('n', 'dq', 'DapTerminate', { desc = 'Stop debug' }) +map('n', 'du', 'lua require("dapui").toggle()', { desc = 'Toggle DAP UI' }) diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 0000000..738f20b --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,6 @@ +require "nvchad.options" + +-- add yours here! + +-- local o = vim.o +-- o.cursorlineopt ='both' -- to enable cursorline! diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua new file mode 100644 index 0000000..0ae3db7 --- /dev/null +++ b/lua/plugins/init.lua @@ -0,0 +1,51 @@ +return { + { + "stevearc/conform.nvim", + -- event = 'BufWritePre', -- uncomment for format on save + opts = require "configs.conform", + }, + + -- These are some examples, uncomment them if you want to see them work! + { + "neovim/nvim-lspconfig", + config = function() + require "configs.lspconfig" + end, + }, + + -- These are for C/C++ Debbuger + { + "nvim-neotest/nvim-nio", + event = "VeryLazy", + }, + { + "mfussenegger/nvim-dap", + event = "VeryLazy", + config = function () + require("configs.nvim-dap").setup() + end + }, + { + "rcarriga/nvim-dap-ui", + event = "VeryLazy", + dependencies = "mfussenegger/nvim-dap", + }, + { + "jay-babu/mason-nvim-dap.nvim", + event = "VeryLazy", + dependencies = { + "williamboman/mason.nvim", + "mfussenegger/nvim-dap", + }, + opts = { + handlers = {} + }, + }, + { + "theHamsta/nvim-dap-virtual-text", + dependencies = "mfussenegger/nvim-dap", + config = function() + require("nvim-dap-virtual-text").setup() + end, + }, +}