diff options
Diffstat (limited to 'nvim')
-rw-r--r-- | nvim/.config/nvim/after/ftplugin/dashboard.lua | 9 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/dap/adapters.lua | 36 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/dap/configs.lua | 83 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/utils.lua | 77 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/utils/dap.lua | 187 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua | 210 |
6 files changed, 0 insertions, 602 deletions
diff --git a/nvim/.config/nvim/after/ftplugin/dashboard.lua b/nvim/.config/nvim/after/ftplugin/dashboard.lua deleted file mode 100644 index 019d8ef..0000000 --- a/nvim/.config/nvim/after/ftplugin/dashboard.lua +++ /dev/null @@ -1,9 +0,0 @@ -vim.keymap.set("n", "<leader>sr", U.session.read, { - buffer = 0, - desc = "read session", -}) - -vim.keymap.set("n", "<C-n>", U.dashboard.next_fortune, { - buffer = 0, - desc = "next fortune", -}) diff --git a/nvim/.config/nvim/lua/tobyvin/dap/adapters.lua b/nvim/.config/nvim/lua/tobyvin/dap/adapters.lua deleted file mode 100644 index 7e2d5fc..0000000 --- a/nvim/.config/nvim/lua/tobyvin/dap/adapters.lua +++ /dev/null @@ -1,36 +0,0 @@ -local M = { - nlua = function(callback, config) - callback({ type = "server", host = config.host, port = config.port }) - end, - lldb = { - type = "executable", - command = "/usr/bin/lldb-vscode", - name = "lldb", - }, - gdb = { - type = "executable", - command = "gdb", - args = { "-i", "dap" }, - }, - codelldb = { - type = "server", - port = "${port}", - host = "127.0.0.1", - executable = { - command = vim.fn.exepath("codelldb"), - args = { - "--liblldb", - (vim.fn.resolve(vim.fn.exepath("codelldb")):gsub("/codelldb$", "/extension/lldb/lib/liblldb.so")), - "--port", - "${port}", - }, - }, - enrich_config = function(config, on_config) - if config["cargo"] ~= nil then - on_config(U.dap.cargo_inspector(config)) - end - end, - }, -} - -return M diff --git a/nvim/.config/nvim/lua/tobyvin/dap/configs.lua b/nvim/.config/nvim/lua/tobyvin/dap/configs.lua deleted file mode 100644 index 44f2035..0000000 --- a/nvim/.config/nvim/lua/tobyvin/dap/configs.lua +++ /dev/null @@ -1,83 +0,0 @@ -local M = { - lua = { - { - name = "Attach to running Neovim instance", - type = "nlua", - request = "attach", - host = function() - local host - vim.ui.input({ prompt = "Host: ", default = "127.0.0.1" }, function(input) - host = input - end) - return host - end, - port = function() - local host - vim.ui.input({ prompt = "Port: ", default = "7777" }, function(input) - host = input - end) - return host - end, - }, - }, - c = { - { - name = "Launch", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input({ - prompt = "Path to executable: ", - text = vim.fn.getcwd() .. "/", - completion = "file", - }) - end, - cwd = "${workspaceFolder}", - stopOnEntry = false, - runInTerminal = false, - }, - }, - cpp = { - { - name = "Launch", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input({ - prompt = "Path to executable: ", - text = vim.fn.getcwd() .. "/", - completion = "file", - }) - end, - cwd = "${workspaceFolder}", - stopOnEntry = false, - runInTerminal = false, - }, - }, - rust = { - { - name = "build", - type = "codelldb", - request = "launch", - cargo = { - args = { "build" }, - }, - cwd = "${workspaceFolder}", - stopOnEntry = false, - terminal = "console", - }, - { - name = "test --lib", - type = "codelldb", - request = "launch", - cargo = { - args = { "test", "--no-run", "--lib" }, - }, - cwd = "${workspaceFolder}", - stopOnEntry = false, - terminal = "console", - }, - }, -} - -return M diff --git a/nvim/.config/nvim/lua/tobyvin/utils.lua b/nvim/.config/nvim/lua/tobyvin/utils.lua index ddbb5c2..8d304ac 100644 --- a/nvim/.config/nvim/lua/tobyvin/utils.lua +++ b/nvim/.config/nvim/lua/tobyvin/utils.lua @@ -1,28 +1,11 @@ local M = { buf = require("tobyvin.utils.buf"), - dap = require("tobyvin.utils.dap"), - dashboard = require("tobyvin.utils.dashboard"), fs = require("tobyvin.utils.fs"), lsp = require("tobyvin.utils.lsp"), session = require("tobyvin.utils.session"), ui = require("tobyvin.utils.ui"), } -function M.inspect(v) - print(vim.inspect(v)) - return v -end - -function M.lazy_require(modname) - return setmetatable({}, { - __index = function(_, k) - return function(...) - return require(modname)[k](...) - end - end, - }) -end - ---@param ms integer ---@param fn function function M.debounce(ms, fn) @@ -36,64 +19,4 @@ function M.debounce(ms, fn) end end -function M.system(...) - local s = vim.system(...) - --- @param obj vim.SystemObj - --- @param cmd string[] - --- @param opts vim.SystemOpts|nil) - --- @param on_exit function|nil - ---@diagnostic disable-next-line: inject-field - s.pipe = function(obj, cmd, opts, on_exit) - opts = vim.tbl_extend("keep", opts or {}, { stdin = obj:wait().stdout }) - return M.system(cmd, opts, on_exit) - end - - --- @param obj vim.SystemObj - --- @param cmd string[] - --- @param opts vim.SystemOpts|nil) - --- @param on_exit function|nil - ---@diagnostic disable-next-line: inject-field - s.try_pipe = function(obj, cmd, opts, on_exit) - if vim.fn.executable(cmd[1]) ~= 1 then - cmd = { "cat" } - end - ---@diagnostic disable-next-line: undefined-field - return obj:pipe(cmd, opts, on_exit) - end - - return s -end - ----Merges two or more highlights groups into a new highlight group. ---- ----**Note**: This will overwrite any existing group named <name>. If you would like to both merge ----*and* overwrite a group, specify it both as <name>, as well as in the list of groups to merge. ---- ----E.g. extend_hl(ns, "Normal", "Normal", "Special", { fg = "#333333" }, { other_ns, "Specific" }) ----@param ns integer Namespace ----@param name string name of new hightlight group. ---If you want to groups into an existing group, add <name> to the list of groups to merge.* ----@param ... string|table|{ [1]: integer, [2]: string|table } Two or more highlight group names, anonymous highlight definitions, or tuples in the form of { namespace, name|definition } -function M.extend_hl(ns, name, ...) - local hl = {} - - for _, arg in pairs({ ... }) do - local hl_name_or_val, hl_ns, hl_val - if type(arg) ~= "string" and vim.islist(arg) then - hl_ns, hl_name_or_val = arg[1], arg[2] - else - hl_ns, hl_name_or_val = ns, arg - end - - if type(hl_name_or_val) == "string" then - hl_val = vim.api.nvim_get_hl(hl_ns, { name = hl_name_or_val, link = false }) - else - hl_val = hl_name_or_val - end - - hl = vim.tbl_extend("keep", hl, hl_val) - end - - vim.api.nvim_set_hl(ns, name, hl) -end - return M diff --git a/nvim/.config/nvim/lua/tobyvin/utils/dap.lua b/nvim/.config/nvim/lua/tobyvin/utils/dap.lua deleted file mode 100644 index 69a7bb2..0000000 --- a/nvim/.config/nvim/lua/tobyvin/utils/dap.lua +++ /dev/null @@ -1,187 +0,0 @@ -local M = {} - -function M.cargo_inspector(config) - local final_config = vim.deepcopy(config) - - -- Create a buffer to receive compiler progress messages - local compiler_msg_buf = vim.api.nvim_create_buf(false, true) - vim.bo[compiler_msg_buf].buftype = "nofile" - - -- And a floating window in the corner to display those messages - local window_width = math.max(#final_config.name + 1, 50) - local window_height = 12 - local compiler_msg_window = vim.api.nvim_open_win(compiler_msg_buf, false, { - relative = "editor", - width = window_width, - height = window_height, - col = vim.wo.columns:get() - window_width - 1, - row = vim.wo.lines:get() - window_height - 1, - border = "rounded", - style = "minimal", - }) - - -- Let the user know what's going on - ---@diagnostic disable-next-line: param-type-mismatch - vim.fn.appendbufline(compiler_msg_buf, "$", "Compiling: ") - ---@diagnostic disable-next-line: param-type-mismatch - vim.fn.appendbufline(compiler_msg_buf, "$", final_config.name) - ---@diagnostic disable-next-line: param-type-mismatch - vim.fn.appendbufline(compiler_msg_buf, "$", string.rep("=", window_width - 1)) - - -- Instruct cargo to emit compiler metadata as JSON - local message_format = "--message-format=json" - if final_config.cargo.args ~= nil then - table.insert(final_config.cargo.args, message_format) - else - final_config.cargo.args = { message_format } - end - - -- Build final `cargo` command to be executed - local cargo_cmd = { "cargo" } - for _, value in pairs(final_config.cargo.args) do - table.insert(cargo_cmd, value) - end - - -- Run `cargo`, retaining buffered `stdout` for later processing, - -- and emitting compiler messages to to a window - local compiler_metadata = {} - local cargo_job = vim.fn.jobstart(cargo_cmd, { - clear_env = false, - env = final_config.cargo.env, - cwd = final_config.cwd, - - -- Cargo emits compiler metadata to `stdout` - stdout_buffered = true, - on_stdout = function(_, data) - compiler_metadata = data - end, - - -- Cargo emits compiler messages to `stderr` - on_stderr = function(_, data) - local complete_line = "" - - -- `data` might contain partial lines, glue data together until - -- the stream indicates the line is complete with an empty string - for _, partial_line in ipairs(data) do - if string.len(partial_line) ~= 0 then - complete_line = complete_line .. partial_line - end - end - - if vim.api.nvim_buf_is_valid(compiler_msg_buf) then - ---@diagnostic disable-next-line: param-type-mismatch - vim.fn.appendbufline(compiler_msg_buf, "$", complete_line) - vim.api.nvim_win_set_cursor(compiler_msg_window, { vim.api.nvim_buf_line_count(compiler_msg_buf), 1 }) - vim.cmd("redraw") - end - end, - - on_exit = function(_, exit_code) - -- Cleanup the compile message window and buffer - if vim.api.nvim_win_is_valid(compiler_msg_window) then - vim.api.nvim_win_close(compiler_msg_window, true) - end - - if vim.api.nvim_buf_is_valid(compiler_msg_buf) then - vim.api.nvim_buf_delete(compiler_msg_buf, { force = true }) - end - - -- If compiling succeeed, send the compile metadata off for processing - -- and add the resulting executable name to the `program` field of the final config - if exit_code == 0 then - local executable_name = M.parse_cargo_metadata(compiler_metadata) - if executable_name ~= nil then - final_config.program = executable_name - else - vim.notify( - "Cargo could not find an executable for debug configuration:\n\n\t" .. final_config.name, - vim.log.levels.ERROR - ) - end - else - vim.notify( - "Cargo failed to compile debug configuration:\n\n\t" .. final_config.name, - vim.log.levels.ERROR - ) - end - end, - }) - - -- Get the rust compiler's commit hash for the source map - local rust_hash = "" - local rust_hash_stdout = {} - local rust_hash_job = vim.fn.jobstart({ "rustc", "--version", "--verbose" }, { - clear_env = false, - stdout_buffered = true, - on_stdout = function(_, data) - rust_hash_stdout = data - end, - on_exit = function() - for _, line in pairs(rust_hash_stdout) do - local start, finish = string.find(line, "commit-hash: ", 1, true) - - if start ~= nil then - rust_hash = string.sub(line, finish + 1) - end - end - end, - }) - - -- Get the location of the rust toolchain's source code for the source map - local rust_source_path = "" - local rust_source_job = vim.fn.jobstart({ "rustc", "--print", "sysroot" }, { - clear_env = false, - stdout_buffered = true, - on_stdout = function(_, data) - rust_source_path = data[1] - end, - }) - - -- Wait until compiling and parsing are done - -- This blocks the UI (except for the :redraw above) and I haven't figured - -- out how to avoid it, yet - -- Regardless, not much point in debugging if the binary isn't ready yet - vim.fn.jobwait({ cargo_job, rust_hash_job, rust_source_job }) - - -- Enable visualization of built in Rust datatypes - final_config.sourceLanguages = { "rust" } - - -- Build sourcemap to rust's source code so we can step into stdlib - rust_hash = "/rustc/" .. rust_hash .. "/" - rust_source_path = rust_source_path .. "/lib/rustlib/src/rust/" - if final_config.sourceMap == nil then - final_config["sourceMap"] = {} - end - final_config.sourceMap[rust_hash] = rust_source_path - - -- Cargo section is no longer needed - final_config.cargo = nil - - return final_config -end - --- After extracting cargo's compiler metadata with the cargo inspector --- parse it to find the binary to debug -function M.parse_cargo_metadata(cargo_metadata) - -- Iterate backwards through the metadata list since the binary - -- we're interested will be near the end (usually second to last) - for i = 1, #cargo_metadata do - local json_table = cargo_metadata[#cargo_metadata + 1 - i] - - -- Some metadata lines may be blank, skip those - if string.len(json_table) ~= 0 then - -- Each matadata line is a JSON table, - -- parse it into a data structure we can work with - json_table = vim.fn.json_decode(json_table) - - -- Our binary will be the compiler artifact with an executable defined - if json_table["reason"] == "compiler-artifact" and json_table["executable"] ~= vim.NIL then - return json_table["executable"] - end - end - end - - return nil -end - -return M diff --git a/nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua b/nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua deleted file mode 100644 index 8e36186..0000000 --- a/nvim/.config/nvim/lua/tobyvin/utils/dashboard.lua +++ /dev/null @@ -1,210 +0,0 @@ ----@param lines string[] ----@return integer -local function max_len(lines) - local max = 0 - for _, line in ipairs(lines) do - max = math.max(max, vim.fn.strdisplaywidth(line)) - end - return max -end - ----@param lines string[] ----@return string[] -local function pad_horz(lines, width) - local max_line_len = max_len(lines) - local padded = {} - for _, line in ipairs(lines) do - local line_len = max_line_len - local pad_len = math.floor((width / 2) - (line_len / 2)) - table.insert(padded, string.rep(" ", pad_len) .. line) - end - return padded -end - ----@class Dashboard ----@field sections (string[] | fun():string[])[] ----@field rendered string[][] ----@field augroup integer? ----@field win integer? ----@field buf integer? -local M = { - rendered = {}, - sections = { - function() - if vim.fn.executable("fortune") ~= 1 then - return {} - end - - local obj = U.system({ "fortune", "-s" }):try_pipe({ "cowsay" }) - - return vim.split(obj:wait().stdout or "", "\n") - end, - { - " ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗ ", - " ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║ ", - " ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║ ", - " ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║ ", - " ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║ ", - " ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ", - }, - function() - if not pcall(require, "lazy") then - return {} - end - - local stats = require("lazy").stats() - local lines = { - string.format("startup: %s ms", stats.startuptime), - string.format("plugins: %s (%s loaded)", stats.count, stats.loaded), - } - - if require("lazy.status").has_updates() then - table.insert(lines, string.format("updates: %s", require("lazy.status").updates())) - end - - return lines - end, - }, -} - -function M.next_fortune(bufnr) - M.render(bufnr, 1) -end - -function M.refresh_stats(bufnr) - M.render(bufnr, 3) -end - -function M.render(bufnr, index) - bufnr = bufnr or 0 - - local opts = vim.b[bufnr].dashboard_opts - local width = vim.api.nvim_win_get_width(opts.winid) - local height = vim.api.nvim_win_get_height(opts.winid) - - local rendered = {} - local dashboard = vim.b[bufnr].dashboard or {} - - local mid_height = 0 - for i, section in pairs(M.sections) do - if dashboard[i] == nil or index == nil or index == i then - if type(section) == "table" then - dashboard[i] = pad_horz(section, width) - elseif type(section) == "function" then - dashboard[i] = pad_horz(section(), width) - end - end - - if i < (#M.sections / 2) then - mid_height = mid_height + #dashboard[i] - elseif i == math.ceil(#M.sections / 2) then - mid_height = mid_height + math.ceil(#dashboard[i] / 2) - end - - vim.list_extend(rendered, dashboard[i]) - table.insert(rendered, "") - end - - if mid_height < math.ceil(height / 3) then - for _ = 1, (math.ceil(height / 3) - mid_height) do - table.insert(rendered, 1, "") - end - end - - vim.bo[bufnr].modifiable = true - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, rendered) - vim.bo[bufnr].modifiable = false - vim.b[bufnr].dashboard = dashboard -end - -function M.initialize(opts) - local bufnr = vim.api.nvim_create_buf(false, true) - - if not opts.winid then - if opts.float then - opts.winid = vim.api.nvim_open_win(bufnr, opts.float_enter, opts.float_opts) - else - opts.winid = vim.api.nvim_get_current_win() - vim.api.nvim_win_set_buf(opts.winid, bufnr) - end - end - - vim.bo[bufnr].textwidth = 0 - vim.bo[bufnr].bufhidden = "wipe" - vim.bo[bufnr].buflisted = false - vim.bo[bufnr].matchpairs = "" - vim.bo[bufnr].swapfile = false - vim.bo[bufnr].buftype = "nofile" - vim.bo[bufnr].filetype = "dashboard" - vim.bo[bufnr].synmaxcol = 0 - - vim.iter(opts.win_opts):each(function(k, v) - vim.wo[opts.winid][0][k] = v - end) - - vim.b[bufnr].dashboard_opts = opts - - return bufnr -end - -function M.on_enter() - if vim.fn.argc() == 0 then - M.setup() - end - return true -end - -function M.setup(opts) - opts = vim.tbl_extend("keep", opts or {}, { - float = false, - float_enter = false, - float_opts = { - relative = "editor", - width = 80, - height = 50, - col = (vim.o.columns - (opts and opts.width or 80)) / 2, - row = (vim.o.lines - (opts and opts.height or 50)) / 2, - style = "minimal", - }, - win_opts = { - wrap = false, - colorcolumn = "", - foldlevel = 999, - foldcolumn = "0", - cursorcolumn = false, - cursorline = false, - number = false, - relativenumber = false, - list = false, - spell = false, - signcolumn = "no", - }, - }) - - local bufnr = M.initialize(opts) - - local augroup = vim.api.nvim_create_augroup("dashboard", { clear = true }) - vim.api.nvim_create_autocmd("User", { - group = augroup, - pattern = { "LazyVimStarted", "LazyLoad", "LazyCheck" }, - callback = function() - M.refresh_stats(bufnr) - end, - desc = "dashboard lazy stats", - }) - - vim.api.nvim_create_autocmd({ "BufHidden", "BufDelete", "BufLeave" }, { - group = augroup, - buffer = bufnr, - callback = function() - vim.api.nvim_del_augroup_by_id(augroup) - return true - end, - desc = "clear dashboard autocmds", - }) - - M.render(bufnr) - return bufnr -end - -return M |