refactor: golf core module

This commit is contained in:
swaits committed 2026-04-09 14:12:24 -06:00
1 parent 0b15a01250
commit 4412c971fd
4 files changed
+13 -32

No files matched your search

+8 -19
View File
@@ -1,13 +1,9 @@
local M = {}
function M.setup(opts)
opts = vim.tbl_extend("force", {
sign = "💡",
hl = "DiagnosticWarn",
priority = 10,
}, opts or {})
opts = opts or {}
local ns = vim.api.nvim_create_namespace("tiny-lightbulb")
local group = vim.api.nvim_create_augroup("tiny-lightbulb", { clear = true })
local gen = 0
local function clear()
@@ -16,7 +12,7 @@ function M.setup(opts)
end
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
group = vim.api.nvim_create_augroup("tiny-lightbulb", { clear = true }),
group = group,
callback = function()
local buf, lnum = vim.api.nvim_get_current_buf(), vim.fn.line(".") - 1
clear()
@@ -25,21 +21,14 @@ function M.setup(opts)
end
local id = gen
vim.lsp.buf_request(buf, "textDocument/codeAction", {
textDocument = vim.lsp.util.make_text_document_params(buf),
textDocument = { uri = vim.uri_from_bufnr(buf) },
range = { start = { line = lnum, character = 0 }, ["end"] = { line = lnum, character = 0 } },
context = { diagnostics = vim.diagnostic.get(buf, { lnum = lnum }) },
}, function(err, results)
if
id == gen
and not err
and results
and #results > 0
and vim.api.nvim_buf_is_valid(buf)
then
if id == gen and not err and results and results[1] and vim.api.nvim_buf_is_valid(buf) then
vim.api.nvim_buf_set_extmark(buf, ns, lnum, 0, {
sign_text = opts.sign,
sign_hl_group = opts.hl,
priority = opts.priority,
sign_text = opts.sign or "💡",
sign_hl_group = opts.hl or "DiagnosticWarn",
})
end
end)
@@ -47,7 +36,7 @@ function M.setup(opts)
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI", "InsertEnter" }, {
group = vim.api.nvim_create_augroup("tiny-lightbulb-clear", { clear = true }),
group = group,
callback = clear,
})
end