diff --git a/README.md b/README.md index 9bb691836e985e446a34b37fdc0dc4c95ed0a013..3db5491d73813ab82bb2660e9bd58f5d579690f0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,16 @@ # Power by LazyVim 🛌 + +- [Power by LazyVim 🛌](#power-by-lazyvim-🛌) + - [💤 LazyVim](#💤-lazyvim) + - [🗺️ NeoEmbeded IDE](#🗺️-neoembeded-ide) + - [🚵 安装](#🚵-安装) + - [🧰 功能插件](#🧰-功能插件) + - [🐛 Q&A](#🐛-qa) + - [ℹ️ 其他](#ℹ️-其他) + + ## 💤 LazyVim LazyVim 是由 [💤 lazy.nvim](https://github.com/folke/lazy.nvim) 驱动的一套 Neovim 配置,可以轻松自定义和扩展您的配置。 @@ -8,6 +18,7 @@ LazyVim 是由 [💤 lazy.nvim](https://github.com/folke/lazy.nvim) 驱动的一 LazyVim 提供了两全其美的方式 - 根据需要调整配置的灵活性,以及默认预配置的便利性。 ![image](./start.png) +![image](./nvim-mcu-debug.png) 本仓库基于[LazyVim](https://github.com/LazyVim/LazyVim),尽可能不改动原生文件结果和插件配置. A starter template for [LazyVim](https://github.com/LazyVim/LazyVim). @@ -86,11 +97,17 @@ nvim ## ℹ️ 其他 - dap - - 单片机调试:在`plugins/dap.lua`中提供了一个`cpptools(cppdbg)`的dap配置示例, - 可以通过openocd进行调试,调试能力与keil仍有很大差距, 但也算具备了基础的调试能力 - - 支持单步,单行,运行,复位, 断点 - - 支持watch窗口 - - 支持栈窗口 - > 注意: 当前可能需要手动指定.elf文件位置,dap配置框架初步可用,但仍在完善阶段... - - 普通c调试:使用`codelldb` - + - 单片机调试: + - 调试特性支持: + - 支持单步,单行,运行,复位, 断点 + - 支持watch窗口 + - 支持栈窗口 + - 调试框架:cpptools+gdb+openocd + 1. overseer编译 + 2. overseer下载 + 3. dap调试 + > dap也可以下载,但重复启动将重复下载
+ > 自动在./build下查找elf文件, 注意该目录只能有一个elf文件!! + - 配置使用 + - 直接参考overseer/dap配置即可 +- 普通c调试:使用`codelldb` diff --git a/init.lua b/init.lua index 83742727244bb387bc342ae0e713d7c190c4fcfd..2514f9ed90d831793ec8b5ca4666040996d01e09 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,2 @@ -- bootstrap lazy.nvim, LazyVim and your plugins require("config.lazy") - --- require("lspconfig").clangd.setup({ --- cmd = { "clangd", "--header-insertion=never" }, --- }) diff --git a/lazy-lock.json b/lazy-lock.json index 93e96e5bbe24ec66f29f1cad0f6bba01e1c7154a..d8fbb9d2805a4f02a8a7994ca5431d882582563a 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -18,13 +18,14 @@ "dial.nvim": { "branch": "master", "commit": "750f802879c90ea51f92b68c35fa562ee575804a" }, "distant.nvim": { "branch": "v0.3", "commit": "823267cf3b77cf9a7ae28454926eabc18fec1ba0" }, "dressing.nvim": { "branch": "master", "commit": "6741f1062d3dc6e4755367a7e9b347b553623f04" }, - "flash.nvim": { "branch": "main", "commit": "3bdf1304d8d4679fa3ff88abc08ce2a1be859b60" }, + "flash.nvim": { "branch": "main", "commit": "3ea3a80a42d40f4f6b2a17c0348697a3de47931a" }, "gitsigns.nvim": { "branch": "main", "commit": "39b5b6f48bde0595ce68007ffce408c5d7ac1f79" }, "harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" }, "headlines.nvim": { "branch": "master", "commit": "618ef1b2502c565c82254ef7d5b04402194d9ce3" }, + "inc-rename.nvim": { "branch": "main", "commit": "8ba77017ca468f3029bf88ef409c2d20476ea66b" }, "indent-blankline.nvim": { "branch": "master", "commit": "65e20ab94a26d0e14acac5049b8641336819dfc7" }, "lazy.nvim": { "branch": "main", "commit": "6ca23c15f64e88e3ba26be9795343c4c7f2ee851" }, - "lazydev.nvim": { "branch": "main", "commit": "034282543960cc2292be6a5f2b6da71d126837ad" }, + "lazydev.nvim": { "branch": "main", "commit": "2d526d4a4616679caef1b0b62028e8789048d0ea" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" }, "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, @@ -34,11 +35,12 @@ "mini.ai": { "branch": "main", "commit": "45587078f323eaf41b9f701bbc04f8d1ab008979" }, "mini.animate": { "branch": "main", "commit": "320fb35460238c436407cd779f63abad98e84870" }, "mini.icons": { "branch": "main", "commit": "22566a0211ed0588f662ff7425094951be0d77e1" }, + "mini.move": { "branch": "main", "commit": "cde3747eec9bb3941296e6fa1d874e0da5a10256" }, "mini.pairs": { "branch": "main", "commit": "927d19cbdd0e752ab1c7eed87072e71d2cd6ff51" }, "mini.surround": { "branch": "main", "commit": "7098744c8d4573a4b32cb172965f6b2ba03465d2" }, "neo-tree.nvim": { "branch": "main", "commit": "206241e451c12f78969ff5ae53af45616ffc9b72" }, "neogen": { "branch": "main", "commit": "6de0add4805165317ab7d3d36b5cef48b1b865f3" }, - "noice.nvim": { "branch": "main", "commit": "cd0cd97c40fd8594bc727edab16c9e4a0e43dce0" }, + "noice.nvim": { "branch": "main", "commit": "532d26c74bd215872b4e923e5c264130f996d1af" }, "nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" }, "nvim-cmp": { "branch": "main", "commit": "a110e12d0b58eefcf5b771f533fc2cf3050680ac" }, "nvim-dap": { "branch": "master", "commit": "6f79b822997f2e8a789c6034e147d42bc6706770" }, @@ -46,6 +48,7 @@ "nvim-dap-virtual-text": { "branch": "master", "commit": "484995d573c0f0563f6a66ebdd6c67b649489615" }, "nvim-lint": { "branch": "master", "commit": "efc6fc83f0772283e064c53a8f9fb5645bde0bc0" }, "nvim-lspconfig": { "branch": "master", "commit": "cf97d2485fc3f6d4df1b79a3ea183e24c272215e" }, + "nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" }, "nvim-nio": { "branch": "master", "commit": "7969e0a8ffabdf210edd7978ec954a47a737bbcc" }, "nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" }, "nvim-spectre": { "branch": "master", "commit": "49fae98ef2bfa8342522b337892992e3495065d5" }, @@ -54,18 +57,19 @@ "nvim-ts-autotag": { "branch": "main", "commit": "ddfccbf0df1b9349c2b9e9b17f4afa8f9b6c1ed1" }, "onedark.nvim": { "branch": "master", "commit": "fae34f7c635797f4bf62fb00e7d0516efa8abe37" }, "outline.nvim": { "branch": "main", "commit": "2175b6da5b7b5be9de14fd3f54383a17f5e4609c" }, + "overseer.nvim": { "branch": "master", "commit": "433ae548434d83ab3c6afe6afc549832f7dd56f1" }, "pantran.nvim": { "branch": "main", "commit": "250b1d8e81f83e6aff061f4c75db008c684f5971" }, - "persistence.nvim": { "branch": "main", "commit": "b915cbd3d1aee6f09724cef29a75929293fc0a78" }, + "persistence.nvim": { "branch": "main", "commit": "4452f973c3b246af34c16b1b8464f31cc58c25a3" }, "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, "project.nvim": { "branch": "main", "commit": "8c6bad7d22eef1b71144b401c9f74ed01526a4fb" }, "refactoring.nvim": { "branch": "master", "commit": "d07218748c48e756c27aa6859bfa6e62a3d271af" }, "solarized-osaka.nvim": { "branch": "main", "commit": "126d394c0c979a99206214a2b6b8c86e456c9c0f" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, "telescope.nvim": { "branch": "master", "commit": "bfcc7d5c6f12209139f175e6123a7b7de6d9c18a" }, - "todo-comments.nvim": { "branch": "main", "commit": "a40fa7e421a0c363f65db204f5f0ac075d3a8967" }, - "tokyonight.nvim": { "branch": "main", "commit": "1b9ea6a38651dbbc6f8afa5c4d91c019d9600b53" }, - "trouble.nvim": { "branch": "main", "commit": "b61cebb638cef1a3fe60542704bc79c4436dfc1a" }, - "ts-comments.nvim": { "branch": "main", "commit": "be4b3311ac981397c003aeaf5e8417040762c54f" }, - "which-key.nvim": { "branch": "main", "commit": "d26d82ddb91b02447964bf356b9f0b6c96c3aff8" }, + "todo-comments.nvim": { "branch": "main", "commit": "d0d72392c3b0d4c9e3002ecfc509c6b2626a22fb" }, + "tokyonight.nvim": { "branch": "main", "commit": "ee612bf60608376d877c883eca641d87da9bd486" }, + "trouble.nvim": { "branch": "main", "commit": "5273137d903a7d6035b5fc0ef503ee51e69ad0ee" }, + "ts-comments.nvim": { "branch": "main", "commit": "4680210325c86ae73f0c9e408f34ca36c36e3c9c" }, + "which-key.nvim": { "branch": "main", "commit": "744ad78220309110cd641f712eaa29b287216dfb" }, "yanky.nvim": { "branch": "main", "commit": "73215b77d22ebb179cef98e7e1235825431d10e4" } } \ No newline at end of file diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index 7bf51285c3e09bbb23069ba8e150a2f9006a32fb..d1278ba13da53a8b490ec937ea29599b2746f121 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -25,6 +25,10 @@ require("lazy").setup({ { import = "lazyvim.plugins.extras.coding.neogen" }, { import = "lazyvim.plugins.extras.editor.dial" }, { import = "lazyvim.plugins.extras.editor.outline" }, + { import = "lazyvim.plugins.extras.editor.mini-move" }, + { import = "lazyvim.plugins.extras.editor.inc-rename" }, + { import = "lazyvim.plugins.extras.editor.navic" }, + { import = "lazyvim.plugins.extras.editor.overseer" }, { import = "lazyvim.plugins.extras.editor.harpoon2" }, { import = "lazyvim.plugins.extras.editor.refactoring" }, { import = "lazyvim.plugins.extras.util.project" }, diff --git a/lua/config/options.lua b/lua/config/options.lua index e30d7b06c149fd354c20926314876280d6f1613c..e4d71a21cf8b78215874a298563f772d0520596c 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -2,7 +2,6 @@ -- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua -- Add any additional options here - vim.o.conceallevel = 0 -- 自动格式化代码 diff --git a/lua/overseer/template/user/c_build.lua b/lua/overseer/template/user/c_build.lua new file mode 100644 index 0000000000000000000000000000000000000000..b844dddcaf773ee34a40104923de279d5bd60de6 --- /dev/null +++ b/lua/overseer/template/user/c_build.lua @@ -0,0 +1,14 @@ +return { + name = "make -C build -s", + builder = function() + local pwd = vim.fn.getcwd() + return { + cmd = { "make" }, + args = { "-C", pwd .. "/build/", "-s" }, + components = { { "on_output_quickfix", open = true }, "default" }, + } + end, + condition = { + filetype = { "c" }, + }, +} diff --git a/lua/overseer/template/user/c_run.lua b/lua/overseer/template/user/c_run.lua new file mode 100644 index 0000000000000000000000000000000000000000..8dc1192f17911d7cb5bb2838fdbd2fbc3567bad9 --- /dev/null +++ b/lua/overseer/template/user/c_run.lua @@ -0,0 +1,17 @@ +return { + name = "run file", + builder = function() + local cmd = { "./build/demo" } + return { + cmd = cmd, + components = { + { "on_output_quickfix", set_diagnostics = true }, + "on_result_diagnostics", + "default", + }, + } + end, + condition = { + filetype = { "c" }, + }, +} diff --git a/lua/overseer/template/user/cmake_run.lua b/lua/overseer/template/user/cmake_run.lua new file mode 100644 index 0000000000000000000000000000000000000000..4e2f6ecaf965ceb094233a433f6cb56cbcecaa23 --- /dev/null +++ b/lua/overseer/template/user/cmake_run.lua @@ -0,0 +1,14 @@ +return { + name = "cmake .. --debug", + builder = function() + local pwd = vim.fn.getcwd() + return { + cmd = { "cmake" }, + args = { "-S", pwd, "-B", pwd .. "/build", "-D", "CMAKE_BUILD_TYPE=Debug" }, + components = { { "on_output_quickfix", open = true }, "default" }, + } + end, + condition = { + filetype = { "c", "cpp" }, + }, +} diff --git a/lua/overseer/template/user/make_clean.lua b/lua/overseer/template/user/make_clean.lua new file mode 100644 index 0000000000000000000000000000000000000000..e719734614f1064c302b327887205457c7a228d3 --- /dev/null +++ b/lua/overseer/template/user/make_clean.lua @@ -0,0 +1,14 @@ +return { + name = "make clean -C -s", + builder = function() + local pwd = vim.fn.getcwd() + return { + cmd = { "make" }, + args = { "clean", "-C", pwd .. "/build/", "-s" }, + components = { { "on_output_quickfix", open = true }, "default" }, + } + end, + condition = { + filetype = { "c" }, + }, +} diff --git a/lua/overseer/template/user/openocd_load.lua b/lua/overseer/template/user/openocd_load.lua new file mode 100644 index 0000000000000000000000000000000000000000..b711fa4f4245cab2bd1b4e2e7cc360c17e0e7b7a --- /dev/null +++ b/lua/overseer/template/user/openocd_load.lua @@ -0,0 +1,17 @@ +return { + name = "openocd server start", + builder = function() + return { + cmd = "openocd", + args = { "-f", "interface/cmsis-dap.cfg", "-f", "target/stm32f1x.cfg" }, + components = { + { "on_output_quickfix", set_diagnostics = true }, + "on_result_diagnostics", + "default", + }, + } + end, + condition = { + filetype = { "c" }, + }, +} diff --git a/lua/plugins/dap.lua b/lua/plugins/dap.lua index 4d07740854a50d1d886c59ea2a0a18cec04674f9..bdb3ba0805a8e0619c7f08fd73f1dae9b4ee41a4 100644 --- a/lua/plugins/dap.lua +++ b/lua/plugins/dap.lua @@ -1,8 +1,3 @@ --- 单片机调试需要手动修改可执行文件名,并确保工程路径正确 --- 手动方式,已添加自动方式查找elf, 需要在build目录下 --- 配置待优化 -local mcu_elf_name = "test.elf" - return { "mfussenegger/nvim-dap", optional = true, @@ -40,13 +35,13 @@ return { local cppdbg_exec_path = mason_path .. "packages/cpptools/extension/debugAdapters/bin/OpenDebugAD7" --local codelldb_exec_path = mason_path .. "packages/codelldb/extension/adapter/codelldb" --local cortex_debug_exec_path = mason_path .. "packages/cortex-debug/extension/dist/debugadapter.js" - local elf_dir = vim.fn.getcwd() .. "/build" - local elf_dir_file_table = vim.fn.readdir(elf_dir) - local elf_files = {} local elf_file_name = "" + -- 只支持一个,多个卡死.. local function find_elf_name() - elf_files = {} + local elf_dir = vim.fn.getcwd() .. "/build" + local elf_dir_file_table = vim.fn.readdir(elf_dir) + local elf_files = {} for _, file in ipairs(elf_dir_file_table) do if file:match("%.elf$") then table.insert(elf_files, elf_dir .. "/" .. file) @@ -55,7 +50,6 @@ return { if #elf_files == 1 then elf_file_name = elf_files[1] - -- print(elf_file_name) return elf_files[1] elseif #elf_files > 1 then vim.fn.inputlist(elf_files) @@ -72,6 +66,16 @@ return { return elf_file_name end + local function if_elf_valid() + local elf = get_elfname() + if elf then + return elf + else + print("cppdbg: No ELF file found in build directory") + return nil + end + end + if not dap.adapters["cppdbg"] then require("dap").adapters["cppdbg"] = { id = "cppdbg", @@ -100,71 +104,22 @@ return { cwd = "${workspaceFolder}", }, -------------------------------------MCU---------------------------------------------- + ----------------------------------------------------------------------------------- { find_elf_name(), - name = "[mcu][WorkSpaceCFG]", + name = "Debug --openocd --load", type = "cppdbg", request = "launch", - -- program = get_s(), - program = function() - local elf = get_elfname() - if elf then - return elf - else - print("cppdbg: No ELF file found in build directory") - return nil - end - end, - cwd = "${workspaceFolder}", - miMode = "gdb", - miDebuggerPath = "arm-none-eabi-gdb", -- 确保 GDB 在系统路径中 + MIMode = "gdb", miDebuggerServerAddress = "localhost:3333", - useExtendedRemote = true, + miDebuggerPath = "arm-none-eabi-gdb", + cwd = "${workspaceFolder}", + program = if_elf_valid(), - preLaunchTask = function() - os.execute("pkill openocd") - os.execute("sleep 0.1") - os.execute("openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfg > openocd.log 2>1&1") - end, - postRemoteConnectCommands = { - { - text = "monitor reset halt", - description = "mcu reset halt", - ignoreFailures = false, - }, - { - text = "load " .. get_elfname(), - description = "load elf", - ignoreFailures = false, - }, - { - text = "monitor reset init", - description = "mcu reset halt", - ignoreFailures = false, - }, - }, stopAtEntry = false, - runInTerminal = false, - externalConsole = false, - svdPath = "${workspaceFolder}/STM32F103.svd", - showDevDebugOutput = "raw", - }, - ----------------------------------------------------------------------------------- - { - name = "[mcu][stlinkv2][stm32f1x]", - type = "cppdbg", - request = "launch", - program = "${workspaceFolder}/build/" .. mcu_elf_name, -- 修改为实际的 ELF 文件路径 - -- program = function() - -- return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/build/", "file") - -- end, - cwd = "${workspaceFolder}", - miMode = "gdb", - miDebuggerPath = "arm-none-eabi-gdb", -- 确保 GDB 在系统路径中 - miDebuggerServerAddress = "localhost:3333", postRemoteConnectCommands = { { - text = "load build/" .. mcu_elf_name, + text = "load " .. get_elfname(), }, { text = "monitor reset halt", @@ -177,32 +132,19 @@ return { ignoreFailures = true, }, }, - preLaunchTask = function() - os.execute("pkill openocd") - os.execute("openocd -f interface/stlink.cfg -f target/stm32f1x.cfg > openocd.log 2>1&1") - end, - stopAtEntry = false, - runInTerminal = false, - externalConsole = false, - svdPath = "${workspaceFolder}/STM32F103.svd", - --showDevDebugOutput = "raw", }, { - name = "[mcu][daplink][stm32f1x]", + find_elf_name(), + name = "Debug --openocd --not-load", type = "cppdbg", request = "launch", - program = "${workspaceFolder}/build/" .. mcu_elf_name, -- 修改为实际的 ELF 文件路径 - -- program = function() - -- return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/build/", "file") - -- end, - cwd = "${workspaceFolder}", - miMode = "gdb", - miDebuggerPath = "arm-none-eabi-gdb", -- 确保 GDB 在系统路径中 + MIMode = "gdb", miDebuggerServerAddress = "localhost:3333", + miDebuggerPath = "arm-none-eabi-gdb", + cwd = "${workspaceFolder}", + program = if_elf_valid(), + stopAtEntry = false, postRemoteConnectCommands = { - { - text = "load build/" .. mcu_elf_name, - }, { text = "monitor reset halt", }, @@ -214,15 +156,6 @@ return { ignoreFailures = true, }, }, - preLaunchTask = function() - os.execute("pkill openocd") - os.execute("openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfg > openocd.log 2>1&1") - end, - stopAtEntry = false, - runInTerminal = false, - externalConsole = false, - svdPath = "${workspaceFolder}/STM32F103.svd", - --showDevDebugOutput = "raw", }, } end diff --git a/lua/plugins/overseer.lua b/lua/plugins/overseer.lua new file mode 100644 index 0000000000000000000000000000000000000000..ff6be941eadad54aff4f72739e9079bf30c07912 --- /dev/null +++ b/lua/plugins/overseer.lua @@ -0,0 +1,73 @@ +return { + "stevearc/overseer.nvim", + cmd = { + "OverseerOpen", + "OverseerClose", + "OverseerToggle", + "OverseerSaveBundle", + "OverseerLoadBundle", + "OverseerDeleteBundle", + "OverseerRunCmd", + "OverseerRun", + "OverseerInfo", + "OverseerBuild", + "OverseerQuickAction", + "OverseerTaskAction", + "OverseerClearCache", + }, + config = function() + local overseer = require("overseer") + overseer.setup({ + dap = false, + templates = { + "builtin", + "user.c_build", + "user.c_run", + "user.cmake_run", + "user.make_clean", + "user.openocd_load", + }, + task_list = { + bindings = { + [""] = false, + [""] = false, + [""] = false, + [""] = false, + }, + }, + form = { + win_opts = { + winblend = 0, + }, + }, + confirm = { + win_opts = { + winblend = 0, + }, + }, + task_win = { + win_opts = { + winblend = 0, + }, + }, + }) + + -- overseer.add_template_hook({ + -- module = "^make$", + -- }, function(task_defn, util) + -- util.add_component(task_defn, { "on_output_quickfix", open_on_exit = "failure" }) + -- util.add_component(task_defn, "on_complete_notify") + -- util.add_component(task_defn, { "display_duration", detail_level = 1 }) + -- end) + end, + -- stylua: ignore + keys = { + { "ow", "OverseerToggle", desc = "Task list" }, + { "oo", "OverseerRun", desc = "Run task" }, + { "oq", "OverseerQuickAction", desc = "Action recent task" }, + { "oi", "OverseerInfo", desc = "Overseer Info" }, + { "ob", "OverseerBuild", desc = "Task builder" }, + { "ot", "OverseerTaskAction", desc = "Task action" }, + { "oc", "OverseerClearCache", desc = "Clear cache" }, + }, +} diff --git a/nvim-mcu-debug.png b/nvim-mcu-debug.png new file mode 100644 index 0000000000000000000000000000000000000000..8fc848319fc077451e58ec667024983acb2d5b85 Binary files /dev/null and b/nvim-mcu-debug.png differ diff --git a/start.png b/start.png index ffd7ca9150c5168513199bf6b86bc19fa99b41db..dfaa56b7d6d18512b1a94da06d7ee734bcd0bbf2 100644 Binary files a/start.png and b/start.png differ