From 8ad4fad2440c20aa19e26ade8cdb881cab7734e2 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 6 Apr 2026 19:09:34 +0200 Subject: kernel/tests: fix link issue --- .nvim.lua | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .nvim.lua (limited to '.nvim.lua') diff --git a/.nvim.lua b/.nvim.lua new file mode 100644 index 0000000..2cd34d6 --- /dev/null +++ b/.nvim.lua @@ -0,0 +1,78 @@ +local workspace_folder = vim.fn.getcwd() + +local function safe_require(module) + local ok, mod = pcall(require, module) + if not ok then return nil end + return mod +end + +-- C++ +local default_clangd_config = vim.deepcopy(vim.lsp.config["clangd"]) or {} +default_clangd_config.cmd = { + "clangd", + "--background-index", + "--clang-tidy", + "--header-insertion=iwyu", + "--completion-style=detailed", + string.format("--compile-commands-dir=%s/build", workspace_folder), + "--query-driver=**/x86_64-pc-elf-g++" +} + +vim.lsp.config("clangd", default_clangd_config) + +vim.filetype.add({ + pattern = { + [".*/kstd/include/kstd/.*"] = "cpp", + } +}) + +-- Debugging +local dap = require("dap") +local qemu_job = nil + +dap.adapters.teachos_qemu_mi = function(callback, config) + if qemu_job then + qemu_job:kill(9) + end + + local artifact_path = config.program + if not artifact_path then + vim.notify("Fatal: No artifact path resolved by CMake", vim.log.levels.ERROR) + return + end + + local elf_path = string.gsub(artifact_path, "%.sym$", ".elf") + + qemu_job = vim.system({ + "qemu-system-x86_64", + "-kernel", elf_path, + "-s", "-S", + "-nographic" + }, { text = true }) + + vim.defer_fn(function() + callback({ + type = "executable", + command = vim.fn.stdpath("data") .. "/mason/bin/OpenDebugAD7", + }) + end, 500) +end + +dap.listeners.after.event_terminated["teachos_qemu_teardown"] = function() + if qemu_job then + qemu_job:kill(9) + qemu_job = nil + end +end + +require("cmake-tools").setup({ + cmake_dap_configuration = { + name = "(gdb) QEMU MI Attach", + type = "teachos_qemu_mi", + request = "launch", + miDebuggerServerAddress = "localhost:1234", + miDebuggerPath = "x86_64-pc-elf-gdb", + stopAtEntry = true, + } +}) + -- cgit v1.2.3 From 482f431213b77b3ec72d4cfb5c77e23b34e8e68f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 7 Apr 2026 13:50:17 +0200 Subject: ide: enable debugging in neovim --- .nvim.lua | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 15 deletions(-) (limited to '.nvim.lua') diff --git a/.nvim.lua b/.nvim.lua index 2cd34d6..1cec8af 100644 --- a/.nvim.lua +++ b/.nvim.lua @@ -28,51 +28,130 @@ vim.filetype.add({ -- Debugging local dap = require("dap") -local qemu_job = nil +local qemu_job_id = nil +local qemu_bufnr = nil -dap.adapters.teachos_qemu_mi = function(callback, config) - if qemu_job then - qemu_job:kill(9) +local function resolve_build_paths(artifact_path) + local base_path = string.gsub(artifact_path, "%.[%w]+$", "") + local build_type = artifact_path:match("bin/([^/]+)/") or "Debug" + return { + iso = base_path .. ".iso", + elf = base_path .. ".elf", + sym = base_path .. ".sym", + build_type = build_type, + } +end + +local function launch_qemu(artifact_path, is_debug) + if qemu_job_id then + vim.fn.jobstop(qemu_job_id) + qemu_job_id = nil + end + + local paths = resolve_build_paths(artifact_path) + + local cmd = { + "qemu-system-x86_64", + "-m", "32M", + "-machine", "q35", + "-smp", "4,sockets=1,cores=4,threads=1", + "-display", "curses", + "-debugcon", string.format("file:%s/qemu-debugcon-%s.log", workspace_folder, paths.build_type), + "-cdrom", paths.iso + } + + if is_debug then + table.insert(cmd, 2, "-s") + table.insert(cmd, 3, "-no-reboot") + table.insert(cmd, 4, "-d") + table.insert(cmd, 5, "int,cpu_reset") end + local shell_cmd = string.format("%s 2>%s/qemu-stderr-%s.log", table.concat(cmd, " "), workspace_folder, paths.build_type) + + vim.cmd("botright vsplit") + vim.cmd("enew") + qemu_bufnr = vim.api.nvim_get_current_buf() + + vim.api.nvim_buf_set_name(qemu_bufnr, "TeachOS QEMU") + vim.opt_local.number = false + vim.opt_local.relativenumber = false + vim.opt_local.signcolumn = "no" + + qemu_job_id = vim.fn.termopen({ "bash", "-c", shell_cmd }, { + on_exit = function() + qemu_job_id = nil + end + }) + + vim.cmd("wincmd p") +end + +dap.adapters.teachos_qemu_mi = function(callback, config) local artifact_path = config.program if not artifact_path then vim.notify("Fatal: No artifact path resolved by CMake", vim.log.levels.ERROR) return end - local elf_path = string.gsub(artifact_path, "%.sym$", ".elf") + launch_qemu(artifact_path, true) - qemu_job = vim.system({ - "qemu-system-x86_64", - "-kernel", elf_path, - "-s", "-S", - "-nographic" - }, { text = true }) + local paths = resolve_build_paths(artifact_path) + config.setupCommands = { + { description = "Enable pretty-printing for gdb", text = "-enable-pretty-printing" }, + { description = "Load code", text = string.format("-file-exec-file %s", paths.elf) }, + { description = "Load symbols", text = string.format("-file-exec-and-symbols %s", paths.sym) }, + } + config.program = paths.sym vim.defer_fn(function() callback({ type = "executable", command = vim.fn.stdpath("data") .. "/mason/bin/OpenDebugAD7", + id = "cppdbg", }) end, 500) end -dap.listeners.after.event_terminated["teachos_qemu_teardown"] = function() - if qemu_job then - qemu_job:kill(9) - qemu_job = nil +local function teardown_qemu() + if qemu_job_id then + vim.fn.jobstop(qemu_job_id) + qemu_job_id = nil + end + + if qemu_bufnr and vim.api.nvim_buf_is_valid(qemu_bufnr) then + vim.api.nvim_buf_delete(qemu_bufnr, { force = true }) + qemu_bufnr = nil end end +dap.listeners.after.event_terminated["teachos_qemu_teardown"] = teardown_qemu +dap.listeners.after.event_exited["teachos_qemu_teardown"] = teardown_qemu +dap.listeners.after.disconnect["teachos_qemu_teardown"] = teardown_qemu + require("cmake-tools").setup({ cmake_dap_configuration = { name = "(gdb) QEMU MI Attach", type = "teachos_qemu_mi", request = "launch", + MIMode = "gdb", + cwd = workspace_folder, miDebuggerServerAddress = "localhost:1234", miDebuggerPath = "x86_64-pc-elf-gdb", stopAtEntry = true, } }) +vim.api.nvim_create_user_command("TeachOSRun", function() + local cmake = safe_require("cmake-tools") + if not cmake then return end + + local is_ready, target = pcall(cmake.get_launch_target_path) + if is_ready and target then + launch_qemu(target, false) + else + vim.notify("Fatal: Cannot determine CMake target path.", vim.log.levels.ERROR) + end +end, {}) + +vim.keymap.set('n', '', 'TeachOSRun', { noremap = true, desc = "Run TeachOS QEMU (No Debug)" }) -- cgit v1.2.3 From 3bf3c748eec38c776dd3c54cbb30be1d44ffb5c3 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 7 Apr 2026 14:01:18 +0200 Subject: ide: simplify overall configuration --- .nvim.lua | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to '.nvim.lua') diff --git a/.nvim.lua b/.nvim.lua index 1cec8af..ba8f78b 100644 --- a/.nvim.lua +++ b/.nvim.lua @@ -49,39 +49,19 @@ local function launch_qemu(artifact_path, is_debug) end local paths = resolve_build_paths(artifact_path) + local debug_flag = is_debug and "1" or "0" + local shell_cmd = string.format("%s/scripts/qemu-wrapper.sh '%s' '%s' '%s' '%s'", + workspace_folder, workspace_folder, paths.build_type, paths.iso, debug_flag) - local cmd = { - "qemu-system-x86_64", - "-m", "32M", - "-machine", "q35", - "-smp", "4,sockets=1,cores=4,threads=1", - "-display", "curses", - "-debugcon", string.format("file:%s/qemu-debugcon-%s.log", workspace_folder, paths.build_type), - "-cdrom", paths.iso - } - - if is_debug then - table.insert(cmd, 2, "-s") - table.insert(cmd, 3, "-no-reboot") - table.insert(cmd, 4, "-d") - table.insert(cmd, 5, "int,cpu_reset") - end - - local shell_cmd = string.format("%s 2>%s/qemu-stderr-%s.log", table.concat(cmd, " "), workspace_folder, paths.build_type) - - vim.cmd("botright vsplit") - vim.cmd("enew") + vim.cmd("botright vsplit | enew") qemu_bufnr = vim.api.nvim_get_current_buf() - - vim.api.nvim_buf_set_name(qemu_bufnr, "TeachOS QEMU") + vim.api.nvim_buf_set_name(qemu_bufnr, "TeachOS QEMU (" .. paths.build_type .. ")") vim.opt_local.number = false vim.opt_local.relativenumber = false vim.opt_local.signcolumn = "no" - qemu_job_id = vim.fn.termopen({ "bash", "-c", shell_cmd }, { - on_exit = function() - qemu_job_id = nil - end + qemu_job_id = vim.fn.termopen(shell_cmd, { + on_exit = function() qemu_job_id = nil end }) vim.cmd("wincmd p") -- cgit v1.2.3 From 0bbec5ceba0df5668ab1aedcbf2905bf599f6eba Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 8 Apr 2026 10:54:14 +0200 Subject: ide: clean up neovim configuration --- .nvim.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to '.nvim.lua') diff --git a/.nvim.lua b/.nvim.lua index ba8f78b..e8205cb 100644 --- a/.nvim.lua +++ b/.nvim.lua @@ -1,3 +1,6 @@ +vim.opt.exrc = false +vim.g.autoformat = true + local workspace_folder = vim.fn.getcwd() local function safe_require(module) @@ -20,12 +23,6 @@ default_clangd_config.cmd = { vim.lsp.config("clangd", default_clangd_config) -vim.filetype.add({ - pattern = { - [".*/kstd/include/kstd/.*"] = "cpp", - } -}) - -- Debugging local dap = require("dap") local qemu_job_id = nil @@ -110,6 +107,10 @@ dap.listeners.after.event_exited["teachos_qemu_teardown"] = teardown_qemu dap.listeners.after.disconnect["teachos_qemu_teardown"] = teardown_qemu require("cmake-tools").setup({ + cmake_compile_commands_options = { + action = "soft_link", + target = string.format("%s/build", workspace_folder), + }, cmake_dap_configuration = { name = "(gdb) QEMU MI Attach", type = "teachos_qemu_mi", -- cgit v1.2.3 From 65fe71d4c2cc4fa7b09a83671dccb5d4483f0524 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 9 Apr 2026 15:57:22 +0200 Subject: ide: update neovim configuration --- .nvim.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to '.nvim.lua') diff --git a/.nvim.lua b/.nvim.lua index e8205cb..ad007bb 100644 --- a/.nvim.lua +++ b/.nvim.lua @@ -1,5 +1,7 @@ vim.opt.exrc = false vim.g.autoformat = true +vim.g.load_doxygen_syntax = true +vim.opt.fixeol = false local workspace_folder = vim.fn.getcwd() @@ -23,6 +25,16 @@ default_clangd_config.cmd = { vim.lsp.config("clangd", default_clangd_config) +vim.filetype.add({ + pattern = { + [".*/include/kstd/.*"] = function(path, _) + if not path:match("%.[^/]+$") then + return "cpp" + end + end + } +}) + -- Debugging local dap = require("dap") local qemu_job_id = nil @@ -76,8 +88,8 @@ dap.adapters.teachos_qemu_mi = function(callback, config) local paths = resolve_build_paths(artifact_path) config.setupCommands = { { description = "Enable pretty-printing for gdb", text = "-enable-pretty-printing" }, - { description = "Load code", text = string.format("-file-exec-file %s", paths.elf) }, - { description = "Load symbols", text = string.format("-file-exec-and-symbols %s", paths.sym) }, + { description = "Load code", text = string.format("-file-exec-file %s", paths.elf) }, + { description = "Load symbols", text = string.format("-file-exec-and-symbols %s", paths.sym) }, } config.program = paths.sym @@ -108,7 +120,7 @@ dap.listeners.after.disconnect["teachos_qemu_teardown"] = teardown_qemu require("cmake-tools").setup({ cmake_compile_commands_options = { - action = "soft_link", + action = "copy", target = string.format("%s/build", workspace_folder), }, cmake_dap_configuration = { @@ -126,7 +138,6 @@ require("cmake-tools").setup({ vim.api.nvim_create_user_command("TeachOSRun", function() local cmake = safe_require("cmake-tools") if not cmake then return end - local is_ready, target = pcall(cmake.get_launch_target_path) if is_ready and target then launch_qemu(target, false) -- cgit v1.2.3 From aa332432321a902514d61c3ca30e7d9e6396e95e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 29 Apr 2026 09:19:36 +0200 Subject: ide: support nesting in neovim --- .nvim.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to '.nvim.lua') diff --git a/.nvim.lua b/.nvim.lua index ad007bb..c9a3e0a 100644 --- a/.nvim.lua +++ b/.nvim.lua @@ -35,6 +35,15 @@ vim.filetype.add({ } }) +require("neo-tree").setup({ + nesting_rules = { + ['*.hpp'] = { + pattern = "(.*).hpp", + files = { "%1.cpp" } + } + } +}) + -- Debugging local dap = require("dap") local qemu_job_id = nil -- cgit v1.2.3 From c15bae85ebffbb137647c48fccd219d334a5f8ea Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 30 Apr 2026 09:38:51 +0200 Subject: ide: clean up neovim configuration --- .nvim.lua | 85 ++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 37 deletions(-) (limited to '.nvim.lua') diff --git a/.nvim.lua b/.nvim.lua index c9a3e0a..0748af9 100644 --- a/.nvim.lua +++ b/.nvim.lua @@ -1,9 +1,11 @@ -vim.opt.exrc = false +local workspace_folder = vim.fn.getcwd() + +-- Formatting vim.g.autoformat = true -vim.g.load_doxygen_syntax = true vim.opt.fixeol = false -local workspace_folder = vim.fn.getcwd() +-- Enable Doxygen +vim.g.load_doxygen_syntax = true local function safe_require(module) local ok, mod = pcall(require, module) @@ -35,14 +37,20 @@ vim.filetype.add({ } }) -require("neo-tree").setup({ - nesting_rules = { - ['*.hpp'] = { - pattern = "(.*).hpp", - files = { "%1.cpp" } +-- File Browser +local neo_tree = safe_require("neo-tree") +if neo_tree then + local current_config = neo_tree.config or {} + local project_config = vim.tbl_deep_extend("force", current_config, { + nesting_rules = { + ['*.hpp'] = { + pattern = "(.*).hpp", + files = { "%1.cpp", "%1.test.cpp", "%1.tests.cpp" } + } } - } -}) + }) + neo_tree.setup(project_config) +end -- Debugging local dap = require("dap") @@ -127,32 +135,35 @@ dap.listeners.after.event_terminated["teachos_qemu_teardown"] = teardown_qemu dap.listeners.after.event_exited["teachos_qemu_teardown"] = teardown_qemu dap.listeners.after.disconnect["teachos_qemu_teardown"] = teardown_qemu -require("cmake-tools").setup({ - cmake_compile_commands_options = { - action = "copy", - target = string.format("%s/build", workspace_folder), - }, - cmake_dap_configuration = { - name = "(gdb) QEMU MI Attach", - type = "teachos_qemu_mi", - request = "launch", - MIMode = "gdb", - cwd = workspace_folder, - miDebuggerServerAddress = "localhost:1234", - miDebuggerPath = "x86_64-pc-elf-gdb", - stopAtEntry = true, - } -}) +local cmake_tools = safe_require("cmake-tools") +if cmake_tools then + require("cmake-tools").setup({ + cmake_compile_commands_options = { + action = "copy", + target = string.format("%s/build", workspace_folder), + }, + cmake_dap_configuration = { + name = "(gdb) QEMU MI Attach", + type = "teachos_qemu_mi", + request = "launch", + MIMode = "gdb", + cwd = workspace_folder, + miDebuggerServerAddress = "localhost:1234", + miDebuggerPath = "x86_64-pc-elf-gdb", + stopAtEntry = true, + } + }) -vim.api.nvim_create_user_command("TeachOSRun", function() - local cmake = safe_require("cmake-tools") - if not cmake then return end - local is_ready, target = pcall(cmake.get_launch_target_path) - if is_ready and target then - launch_qemu(target, false) - else - vim.notify("Fatal: Cannot determine CMake target path.", vim.log.levels.ERROR) - end -end, {}) + vim.api.nvim_create_user_command("TeachOSRun", function() + local cmake = safe_require("cmake-tools") + if not cmake then return end + local is_ready, target = pcall(cmake.get_launch_target_path) + if is_ready and target then + launch_qemu(target, false) + else + vim.notify("Fatal: Cannot determine CMake target path.", vim.log.levels.ERROR) + end + end, {}) -vim.keymap.set('n', '', 'TeachOSRun', { noremap = true, desc = "Run TeachOS QEMU (No Debug)" }) + vim.keymap.set('n', '', 'TeachOSRun', { noremap = true, desc = "Run TeachOS QEMU (No Debug)" }) +end -- cgit v1.2.3