From 71a534b0a76bea5b08618bd7ff900f736e304d15 Mon Sep 17 00:00:00 2001 From: wrapperup Date: Sun, 26 Jan 2025 16:34:52 -0500 Subject: [PATCH] raddbg ipc stuff --- init.lua | 30 --------- lua/wrap/init.lua | 42 ++++++++++++ lua/wrap/lazy.lua | 51 ++++++--------- lua/wrap/lsp.lua | 45 ++++++++----- lua/wrap/raddbg.lua | 155 ++++++++++++++++++++++++++++++++++++++++++++ lua/wrap/remaps.lua | 29 +++++---- 6 files changed, 262 insertions(+), 90 deletions(-) create mode 100644 lua/wrap/raddbg.lua diff --git a/init.lua b/init.lua index 249cc7b..a4a88ba 100644 --- a/init.lua +++ b/init.lua @@ -1,31 +1 @@ require("wrap") - -vim.opt.nu = true -vim.opt.relativenumber = true - -vim.opt.splitbelow = true -vim.opt.splitright = true - -vim.opt.tabstop = 4 -vim.opt.softtabstop = 4 -vim.opt.shiftwidth = 4 -vim.opt.expandtab = true - -vim.opt.smartindent = true - -vim.opt.wrap = false - -vim.opt.hlsearch = false -vim.opt.incsearch = true - -vim.opt.termguicolors = true - -vim.opt.scrolloff = 8 -vim.opt.signcolumn = "yes" -vim.opt.isfname:append("@-@") - -vim.opt.updatetime = 50 - -vim.g.netrw_browse_split = 0 -vim.g.netrw_banner = 0 -vim.g.netrw_winsize = 25 diff --git a/lua/wrap/init.lua b/lua/wrap/init.lua index c49f951..7d4c711 100644 --- a/lua/wrap/init.lua +++ b/lua/wrap/init.lua @@ -1,7 +1,39 @@ +vim.opt.nu = true +vim.opt.relativenumber = true + +vim.opt.splitbelow = true +vim.opt.splitright = true + +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true + +vim.opt.smartindent = true + +vim.opt.wrap = false + +vim.opt.hlsearch = false +vim.opt.incsearch = true + +vim.opt.termguicolors = true + +vim.opt.scrolloff = 8 +vim.opt.signcolumn = "yes" +vim.opt.isfname:append("@-@") + +vim.opt.updatetime = 50 + +vim.g.netrw_browse_split = 0 +vim.g.netrw_banner = 0 +vim.g.netrw_winsize = 25 + vim.g.b = {case_labels = 0} require("wrap.lazy") +local my_group = vim.api.nvim_create_augroup("my-group", { clear = true }) + vim.g.netrw_browse_split = 0 vim.g.netrw_banner = 0 vim.g.netrw_winsize = 25 @@ -57,7 +89,17 @@ if vim.g.neovide then vim.g.neovide_cursor_vfx_mode = "" end +vim.api.nvim_create_autocmd("TermOpen", { + group = my_group, + callback = function() + vim.wo.number = false + vim.wo.relativenumber = false + vim.wo.signcolumn = "no" + end +}) + require("wrap.remaps") require("wrap.theme") require("wrap.lsp") require("wrap.setup") +require("wrap.raddbg") diff --git a/lua/wrap/lazy.lua b/lua/wrap/lazy.lua index db73382..5592077 100644 --- a/lua/wrap/lazy.lua +++ b/lua/wrap/lazy.lua @@ -11,7 +11,7 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) -require('lazy').setup({ +require("lazy").setup({ -- theme { "rose-pine/neovim", @@ -30,7 +30,7 @@ require('lazy').setup({ end, }) - vim.cmd('colorscheme rose-pine') + vim.cmd("colorscheme rose-pine") end }, @@ -45,7 +45,7 @@ require('lazy').setup({ end }, - { 'NMAC427/guess-indent.nvim' }, + { "NMAC427/guess-indent.nvim" }, -- syntax highlighting { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" }, @@ -57,7 +57,17 @@ require('lazy').setup({ dependencies = { "nvim-lua/plenary.nvim" } }, - { 'stevearc/oil.nvim' }, + -- the goat + { "stevearc/oil.nvim" }, + { "stevearc/conform.nvim" }, + { "stevearc/overseer.nvim" }, + { + 'stevearc/quicker.nvim', + event = "FileType qf", + ---@module "quicker" + ---@type quicker.SetupOptions + opts = {}, + }, { "kylechui/nvim-surround", @@ -65,13 +75,13 @@ require('lazy').setup({ event = "VeryLazy", }, - { 'echasnovski/mini.comment', version = false }, + { "echasnovski/mini.comment", version = false }, -- lsp { "neovim/nvim-lspconfig" }, { "hrsh7th/cmp-nvim-lsp" }, { "hrsh7th/nvim-cmp" }, - -- { "L3MON4D3/LuaSnip" }, + { "L3MON4D3/LuaSnip" }, { "williamboman/mason.nvim" }, { "williamboman/mason-lspconfig.nvim" }, @@ -129,13 +139,13 @@ require('lazy').setup({ -- status line { - 'nvim-lualine/lualine.nvim', - dependencies = { 'nvim-tree/nvim-web-devicons' }, + "nvim-lualine/lualine.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, event = "VeryLazy", }, { - 'ThePrimeagen/harpoon', + "ThePrimeagen/harpoon", event = "VeryLazy", }, @@ -146,29 +156,8 @@ require('lazy').setup({ build = function() vim.fn["mkdp#util#install"]() end, }, - -- formatting - { - 'stevearc/conform.nvim', - event = "VeryLazy", - opts = {}, - }, - - -- { - -- "nvimdev/hlsearch.nvim", - -- event = 'BufRead', - -- config = function() - -- require('hlsearch').setup() - -- end - -- }, - - { - 'stevearc/overseer.nvim', - event = "VeryLazy", - opts = {}, - }, - { - 'rluba/jai.vim', + "rluba/jai.vim", init = function () vim.g.b = {case_labels = 0} end diff --git a/lua/wrap/lsp.lua b/lua/wrap/lsp.lua index 56a5f9e..3fc464c 100644 --- a/lua/wrap/lsp.lua +++ b/lua/wrap/lsp.lua @@ -100,28 +100,14 @@ cmp.setup({ }, }) --- lsp.on_attach(function(client, bufnr) --- lsp.default_keymaps({ buffer = bufnr }) --- require "lsp_signature".on_attach({ --- floating_window = false, --- }, bufnr) --- end) --- --- lsp.set_sign_icons({ --- error = '', --- warn = '', --- hint = '', --- info = '󰋼' --- }) - -require("conform").setup({ +require("conform").setup { formatters_by_ft = { html = { "dprint" }, vto = { "dprint" }, vento = { "dprint" }, jinja = { "dprint" }, }, -}) +} require("mason").setup() @@ -141,7 +127,32 @@ lspconfig.ts_ls.setup { single_file_support = false } -lspconfig.lua_ls.setup({}) +lspconfig.lua_ls.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + 'vim', + 'require' + }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, +} lspconfig.rust_analyzer.setup { settings = { diff --git a/lua/wrap/raddbg.lua b/lua/wrap/raddbg.lua new file mode 100644 index 0000000..f2b3239 --- /dev/null +++ b/lua/wrap/raddbg.lua @@ -0,0 +1,155 @@ +local raddbg_breakpoint_group = "RaddbgBreakpointGroup" +local raddbg_breakpoint_ns = "RaddbgBreakpoint" + +local raddbg_group = vim.api.nvim_create_augroup("raddbg-group", { clear = true }) + +local function starts_with(str, start) + return string.find(str, "^" .. start) ~= nil +end + +local function to_posix_path(path) + return path:gsub("\\", "/") +end + +local function read_entire_file(file) + local f = io.open(file, "rb") + if f then + local content = f:read("*all") + f:close() + return content + end + return "" +end + + +vim.api.nvim_set_hl(0, raddbg_breakpoint_ns, { fg="#EE6969" }) +vim.fn.sign_define(raddbg_breakpoint_ns, { text="", texthl=raddbg_breakpoint_ns, linehl="", numhl="" }) + +local raddbg_root = to_posix_path(os.getenv("APPDATA") .. "\\raddbg\\") + +---@string +---@table +local function raddbg_cmd(cmd, args) + local input = { + "raddbg", + "--ipc", + cmd, + unpack(args or {}), + } + + vim.system(input) +end + +local raddbg_breakpoints = {} + +local function sync_breakpoints(file_content) + raddbg_breakpoints = {} + + -- Define a pattern to match each breakpoint block + local breakpoint_pattern = 'breakpoint:%s*{.-location:%s*%("(.-)":(%d+)%)' + + -- Iterate over all breakpoints in the file content + for location, line in string.gmatch(file_content, breakpoint_pattern) do + local combined_path = vim.fn.fnamemodify(raddbg_root .. location, ":p") + local absolute_path = vim.fn.resolve(combined_path) + + table.insert(raddbg_breakpoints, { + location = absolute_path, + line = tonumber(line) + }) + end +end + +-- local function add_breakpoint_signs(buf) +-- local signs = {} +-- +-- for k, v in pairs(raddbg_breakpoints) do +-- local id = vim.tbl_count(raddbg_breakpoints) +-- print("ok") +-- table.insert(signs, { +-- buffer = buf, +-- group = raddbg_breakpoint_ns, +-- id = id, +-- lnum = v.line, +-- name = v.location, +-- priority = 21, +-- }) +-- end +-- +-- vim.fn.sign_placelist(signs) +-- end + +local function refresh_all_breakpoint_signs() + local signs = {} + + for _, v in pairs(raddbg_breakpoints) do + local buffer = vim.fn.bufnr(v.location) + + if buffer ~= -1 then + local id = vim.tbl_count(signs) + table.insert(signs, { + id = id, + group = raddbg_breakpoint_group, + name = raddbg_breakpoint_ns, + buffer = vim.fn.bufnr(v.location), + lnum = v.line, + priority = 21, + }) + end + end + + vim.fn.sign_unplace(raddbg_breakpoint_group) + vim.fn.sign_placelist(signs) +end + +local function read_breakpoints_from_project() + local file = read_entire_file(raddbg_root .. "default.raddbg_project") + sync_breakpoints(file) + refresh_all_breakpoint_signs() +end + +local uv = vim.uv + +local fs_watcher = uv.new_fs_event() +fs_watcher:start( + raddbg_root .. "default.raddbg_project", + {}, + vim.schedule_wrap(function(_, _, events) + read_breakpoints_from_project() + end) +) + +local function raddbg_toggle_breakpoint(in_line_number) + local file_path = to_posix_path(vim.fn.expand("%:p")) + local line_number = in_line_number or vim.api.nvim_win_get_cursor(0)[1] + + raddbg_cmd("toggle_breakpoint", { file_path .. ":" .. line_number }); + raddbg_cmd("write_project_data"); +end + +local function raddbg_goto_current_file() + local file_path = to_posix_path(vim.fn.expand("%:p")) + print(file_path) + raddbg_cmd("goto_name", { file_path }); + + local line_number = vim.api.nvim_win_get_cursor(0)[1] + raddbg_cmd("goto_line", { line_number }); +end + +vim.keymap.set("n", "", ":RaddbgToggleBreakpoint", { silent = true }) + + +-- Commands + +vim.api.nvim_create_user_command("RaddbgGotoFile", function() + raddbg_goto_current_file() +end, {}) + +vim.api.nvim_create_user_command("RaddbgToggleBreakpoint", function() + raddbg_toggle_breakpoint() +end, {}) + +vim.api.nvim_create_autocmd("BufReadPost", { + pattern = "*", + callback = read_breakpoints_from_project +}) diff --git a/lua/wrap/remaps.lua b/lua/wrap/remaps.lua index 90a5346..182261c 100644 --- a/lua/wrap/remaps.lua +++ b/lua/wrap/remaps.lua @@ -30,26 +30,28 @@ vim.keymap.set("n", "[d", function() vim.diagnostic.goto_prev() end) vim.keymap.set("n", "", "cnextzz") vim.keymap.set("n", "", "cprevzz") -vim.keymap.set('n', '', function() vim.cmd.wincmd('j') end) -vim.keymap.set('n', '', function() vim.cmd.wincmd('k') end) -vim.keymap.set('n', '', function() vim.cmd.wincmd('h') end) -vim.keymap.set('n', '', function() vim.cmd.wincmd('l') end) +vim.keymap.set("n", "", function() vim.cmd.wincmd("j") end) +vim.keymap.set("n", "", function() vim.cmd.wincmd("k") end) +vim.keymap.set("n", "", function() vim.cmd.wincmd("h") end) +vim.keymap.set("n", "", function() vim.cmd.wincmd("l") end) -vim.keymap.set('n', '', ':resize +20', { noremap = true, silent = true }) -vim.keymap.set('n', '', ':resize -20', { noremap = true, silent = true }) -vim.keymap.set('n', '', ':vertical resize +20', { noremap = true, silent = true }) -vim.keymap.set('n', '', ':vertical resize -20', { noremap = true, silent = true }) +vim.keymap.set("n", "", ":resize +20", { noremap = true, silent = true }) +vim.keymap.set("n", "", ":resize -20", { noremap = true, silent = true }) +vim.keymap.set("n", "", ":vertical resize +20", { noremap = true, silent = true }) +vim.keymap.set("n", "", ":vertical resize -20", { noremap = true, silent = true }) -- Center on page scrolling vim.keymap.set("n", "", "zz") vim.keymap.set("n", "", "zz") --- idk sometimes I just hit shift and it's annoying +-- idk sometimes I just hit shift and it"s annoying vim.api.nvim_create_user_command("W", "w", { desc = "Write" }) vim.api.nvim_create_user_command("Wq", "wq", { desc = "Write quit" }) vim.api.nvim_create_user_command("Wqa", "wqa", { desc = "Write quit all" }) vim.api.nvim_create_user_command("Q", "q", { desc = "Quit" }) vim.api.nvim_create_user_command("Qa", "qa", { desc = "Quit All" }) +vim.api.nvim_create_user_command("Vs", "vs", { desc = "Vertical split" }) +vim.api.nvim_create_user_command("Sp", "sp", { desc = "Horizontal split" }) -- leader yank / paste vim.keymap.set("x", "p", [["_dP]]) @@ -57,6 +59,9 @@ vim.keymap.set("x", "p", [["_dP]]) vim.keymap.set({ "n", "v" }, "y", [["+y]]) vim.keymap.set("n", "Y", [["+Y]]) +-- Exit terminal mode like insert +vim.keymap.set("t", "", "") + ---------------------------------------------------------------------------- -- harpoon ---------------------------------------------------------------------------- @@ -85,7 +90,7 @@ vim.keymap.set("n", "pv", function() require("oil").open() end) -- telescope ---------------------------------------------------------------------------- -local builtin = require('telescope.builtin') +local builtin = require("telescope.builtin") local filetype_to_std_lib = { jai = "C:/Repos/jai/jai", @@ -125,7 +130,7 @@ end -- Overseer.nvim ---------------------------------------------------------------------------- -local overseer = require('overseer') +local overseer = require("overseer") if overseer then vim.api.nvim_create_user_command("OverseerRestartLast", function() @@ -146,7 +151,7 @@ end -- Formatting / Code Completion /Misc ---------------------------------------------------------------------------- -vim.keymap.set('i', '', function() require("cmp").complete() end) +vim.keymap.set("i", "", function() require("cmp").complete() end) vim.keymap.set("n", "", function() vim.cmd("ClangdSwitchSourceHeader") end) vim.keymap.set("n", "", function() require("conform").format({ lsp_fallback = true,