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, } })