From 72d99537bfb37a4703da16ceb1c4da33fd1ee4da Mon Sep 17 00:00:00 2001 From: Squibid Date: Tue, 16 Sep 2025 00:34:25 -0400 Subject: [PATCH] more stuff --- after/ftplugin/java.lua | 2 +- lua/conf/autos.lua | 8 ++ lua/conf/binds.lua | 10 ++- lua/conf/opts.lua | 4 +- lua/conf/plugins/mellow.lua | 21 ++++-- lua/core/color.lua | 144 ++++++++++++++++++++++++++++++++++-- lua/core/lsp/binds.lua | 2 + lua/core/lsp/wtf.lua | 13 ++-- lua/core/misc.lua | 17 ++++- 9 files changed, 195 insertions(+), 26 deletions(-) diff --git a/after/ftplugin/java.lua b/after/ftplugin/java.lua index 82540d8..1570a21 100644 --- a/after/ftplugin/java.lua +++ b/after/ftplugin/java.lua @@ -12,7 +12,7 @@ local java_dap_install = core.mason.get_pkg_path("java-debug-adapter") -- make sure to check if things with 💀 need updating local config = { cmd = { - "java", -- 💀 + "/usr/lib/jvm/openjdk21/bin/java", -- 💀 "-jar", vim.fn.glob(vim.fs.joinpath(jdtls_install, "plugins/org.eclipse.equinox.launcher_*.jar")), "-configuration", jdtls_install.."config_linux", diff --git a/lua/conf/autos.lua b/lua/conf/autos.lua index b622141..db20920 100644 --- a/lua/conf/autos.lua +++ b/lua/conf/autos.lua @@ -30,4 +30,12 @@ auto("BufWritePre", { end }) +-- FIXME: disable for now until I can do more work and make it work better +-- auto({ "BufEnter", "CursorMoved", "CursorMovedI" }, { +-- group = bufcheck, +-- callback = function() +-- core.color.todo_comments() +-- end +-- }) + core.color.setup_termbg_sync() diff --git a/lua/conf/binds.lua b/lua/conf/binds.lua index e9f40c1..b41b7ae 100644 --- a/lua/conf/binds.lua +++ b/lua/conf/binds.lua @@ -53,10 +53,14 @@ map("i", "", "", { desc = "Trigger spell completion" }) map("n", "", lz "se spellease nospell", { desc = "Trigger spell completion" }) -- quickfix -map("n", "", "cnext", { desc = "qf next" }) -map("n", "", "cprev", { desc = "qf prev" }) +map("n", "", lz "cnextzz", { desc = "qf next" }) +map("n", "", lz "cprevzz", { desc = "qf prev" }) map("n", "", "cclose", { desc = "qf close" }) -map("n", "", "cope", { desc = "qf open" }) +map("n", "", lz(function() + local win = vim.api.nvim_get_current_win() + vim.cmd.cope() + vim.api.nvim_set_current_win(win) +end), { desc = "qf open" }) -- man pages map("n", "", "Man") diff --git a/lua/conf/opts.lua b/lua/conf/opts.lua index 1d21f20..c840783 100644 --- a/lua/conf/opts.lua +++ b/lua/conf/opts.lua @@ -35,9 +35,11 @@ vim.o.winborder = "solid" -- wild menus vim.o.ph = 20 vim.o.wic = true -vim.o.wop = "fuzzy,pum,tagfile" +vim.o.wop = "fuzzy,pum" +vim.o.wim = "noselect:lastused,full" -- completion +vim.o.cpt = ".,w,b,u,d,i" vim.o.cot = "menu,menuone,noinsert,fuzzy,popup" vim.o.cia = "kind,abbr,menu" -- waiting for https://github.com/neovim/neovim/pull/25541 to land diff --git a/lua/conf/plugins/mellow.lua b/lua/conf/plugins/mellow.lua index 1c5c76b..04c83b2 100644 --- a/lua/conf/plugins/mellow.lua +++ b/lua/conf/plugins/mellow.lua @@ -39,12 +39,23 @@ return { "mellow-theme/mellow.nvim", -- telescope styling so I can see when coding outside (real) ["TelescopeResultsNormal"] = { bg = c.bg_dark }, ["TelescopeResultsBorder"] = { link = "TelescopeResultsNormal" }, - ["TelescopeResultsTitle"] = { - bg = core.color.copyhl("TelescopeResultsNormal").background, - fg = core.color.copyhl("TelescopeResultsNormal").background - }, + ["TelescopeResultsTitle"] = { bg = c.bg, fg = c.bg }, ["TelescopePreviewNormal"] = { link = "NormalFloat" }, - ["TelescopePreviewBorder"] = { link = "TelescopePreviewNormal" } + ["TelescopePreviewBorder"] = { link = "TelescopePreviewNormal" }, + + -- add highlight groups for my todo highlighting + ["TodoTODO"] = { link = "DiagnosticHint" }, + ["TodoTODOBG"] = { fg = c.bg, bg = c.cyan, bold = true }, + ["TodoTODOSIGN"] = { fg = c.cyan, bg = c.cyan, bold = true }, + ["TodoBUG"] = { link = "DiagnosticError" }, + ["TodoBUGBG"] = { fg = c.bg, bg = c.red, bold = true }, + ["TodoBUGSIGN"] = { fg = c.red, bg = c.red, bold = true }, + ["TodoTEST"] = { link = "DiagnosticInfo" }, + ["TodoTESTBG"] = { fg = c.bg, bg = c.blue, bold = true }, + ["TodoTESTSIGN"] = { fg = c.blue, bg = c.blue, bold = true }, + ["TodoWARN"] = { link = "DiagnosticWarn" }, + ["TodoWARNBG"] = { fg = c.bg, bg = c.yellow, bold = true }, + ["TodoWARNSIGN"] = { fg = c.yellow, bg = c.yellow, bold = true }, } end end diff --git a/lua/core/color.lua b/lua/core/color.lua index c5a0251..e481d2e 100644 --- a/lua/core/color.lua +++ b/lua/core/color.lua @@ -6,19 +6,19 @@ local M = {} ---@return table function M.copyhl(hlgroup, namespace) namespace = namespace or 0 - local res = {} + local res = { + ["foreground"] = "#ff0000", + ["background"] = "#ff0000", + ["special"] = "#ff0000" + } local ok, hl = pcall(vim.api.nvim_get_hl, namespace, { name = hlgroup, create = false }) if not ok then - -- return default - return { - ["foreground"] = "#000000", - ["background"] = "#000000", - ["special"] = "#000000" - } + -- return error colors + return res end for _, key in pairs({ "foreground", "background", "special" }) do @@ -29,6 +29,136 @@ function M.copyhl(hlgroup, namespace) return res end +local todo_comments_conf = { + TODO = { + -- TODO: + -- NOTE: + -- INFO: + "TODO", "NOTE", "INFO", + hlgroup = "TodoTODO" + }, + BUG = { + -- BUG: + -- FIXME: + "BUG", "FIXME", + hlgroup = "TodoBUG" + }, + TEST = { + -- TEST: + -- PERF: + "TEST", "PERF", + hlgroup = "TodoTEST" + }, + WARN = { + -- WARN: + -- HACK: + "WARN", "HACK", + hlgroup = "TodoWARN" + } +} + +local todo_hl_ns = vim.api.nvim_create_namespace("todo_highlights") + +--- highlight todo comments in the current buffer. +--- No I won't use folke's super bloated plugin. +--- +--- TODO: make this work with coniguious comment blocks like this one. +--- currently this line won't be highlighted, but I'd like it to be +--- +--- TEST: We could make this a plugin called ts-todo-hl or smthn like that, but +--- I'd be willing to bet no one would use it cause everyone loves folke too +--- much +function M.todo_comments() + local bufnr = vim.api.nvim_win_get_buf(0) + local ok, parser = pcall(vim.treesitter.get_parser, bufnr) + if not ok or not parser then + return + end + + -- Construct the query for comments. + -- We're using treesitter so that I don't have to use external tooling. + local ok, comment_query = pcall(vim.treesitter.query.parse, + parser:lang(), + "(comment) @comment" + ) + if not ok then + return + end + + parser:parse(false, function(err, trees) + if err then + return + end + + local root = trees[1]:root() + for _, match in comment_query:iter_matches(root, bufnr, 0, -1) do + for _, nodes in pairs(match) do + for _, node in ipairs(nodes) do + if not node or node:type() ~= "comment" then + goto continue + end + local text = vim.treesitter.get_node_text(node, bufnr) + -- TODO: instead of doing everything relative to the node we at this + -- point should obtain the node start and use a for loop to iterate + -- over the lines until we're no longer in a comment. This should + -- make dealing with comment blocks easier, and working with these + -- multiline comments easier. + for _, type in pairs(todo_comments_conf) do + for _, v in ipairs(type) do + local s, e = string.find(text, v..":") + if not s or not e then + s, e = string.find(text, v.."%b():") + end + if s and e then + local s_row, s_col = node:start() + local e_row, e_col = node:end_() + + -- ensure that our string indicies are relative to the line + s = s + s_col + e = e + s_col + + ok, err = pcall(vim.api.nvim_buf_set_extmark, bufnr, todo_hl_ns, s_row, e, { + hl_mode = "replace", + hl_group = type.hlgroup, + end_col = e_col, + end_row = e_row + }) + if not ok then + print("fg", s_row, e, e_col, e_row) + print("fg", err) + end + + ok, err = pcall(vim.api.nvim_buf_set_extmark, bufnr, todo_hl_ns, s_row, s - 2, { + hl_mode = "replace", + hl_group = type.hlgroup.."BG", + end_col = e - 1, + end_row = s_row + }) + if not ok then + print("bg", s_row, s - 2, e - 1, s_row) + print("bg", err) + end + + ok, err = pcall(vim.api.nvim_buf_set_extmark, bufnr, todo_hl_ns, s_row, e - 1, { + hl_mode = "replace", + hl_group = type.hlgroup.."SIGN", + end_col = e, + end_row = s_row + }) + if not ok then + print("sn", s_row, e - 1, e, s_row) + print("sn", err) + end + end + end + end + ::continue:: + end + end + end + end) +end + -- Source: 'runtime/lua/vim/_defaults.lua' in Neovim source local function parse_osc11(x) local r, g, b = x:match('^\027%]11;rgb:(%x+)/(%x+)/(%x+)$') diff --git a/lua/core/lsp/binds.lua b/lua/core/lsp/binds.lua index 831f4ab..cffb4ec 100644 --- a/lua/core/lsp/binds.lua +++ b/lua/core/lsp/binds.lua @@ -8,6 +8,8 @@ local function on_list(opts) -- get to the closest reference to the cursor (likely the one gr or gd was -- called on) + -- + -- TODO: switch this to use opts.idx? local closest, distance = 1, false for i, item in ipairs(opts.items) do if item.filename and vim.fn.expand("%:p") == item.filename then diff --git a/lua/core/lsp/wtf.lua b/lua/core/lsp/wtf.lua index b92c9d5..89922be 100644 --- a/lua/core/lsp/wtf.lua +++ b/lua/core/lsp/wtf.lua @@ -26,11 +26,12 @@ auto('LspAttach', { pcall(vim.lsp.linked_editing_range.enable, true, { client_id = client.id }) end - -- enable type formatting which allows lsps to modify text while you're - -- typing for example if you insert {} in a string in python basedpyright - -- will change the string to a format string - if client:supports_method('textDocument/onTypeFormatting') then - pcall(vim.lsp.on_type_formatting.enable, true, { client_id = client.id }) - end + -- disabled for now cause I don't like it + -- -- enable type formatting which allows lsps to modify text while you're + -- -- typing for example if you insert {} in a string in python basedpyright + -- -- will change the string to a format string + -- if client:supports_method('textDocument/onTypeFormatting') then + -- pcall(vim.lsp.on_type_formatting.enable, true, { client_id = client.id }) + -- end end }) diff --git a/lua/core/misc.lua b/lua/core/misc.lua index 2936c6c..c6b7c13 100644 --- a/lua/core/misc.lua +++ b/lua/core/misc.lua @@ -52,11 +52,22 @@ end --- Make an action lazy. This is mostly useful for keybinds which do a lot and --- you want to make sure the screen doesn't flash ----@param txt string the action ----@return string lazified +---@param txt string|function the action +---@return string|function lazified ---@nodiscard function M.lz(txt) - return "se lz"..txt.."se lz!" + if type(txt) == "string" then + return "se lz"..txt.."se lz!" + elseif type(txt) == "function" then + return function() + vim.cmd.se("lz") + -- gotta make sure we can always unset lz + pcall(txt) + vim.cmd.se("lz!") + end + else + return txt + end end return M