refactor: golf core module
This commit is contained in:
4 files changed
+13
-32
No files matched your search
@@ -3,14 +3,14 @@
|
||||
A tiny lightbulb for Neovim 0.12+. Shows a sign when LSP code actions are
|
||||
available on the current line.
|
||||
|
||||
Zero config. ~50 lines of Lua.
|
||||
Zero config. ~40 lines of Lua.
|
||||
|
||||
## Features
|
||||
|
||||
- Displays a 💡 in the sign column when code actions are available
|
||||
- Clears instantly on cursor move
|
||||
- Async LSP requests with stale-response handling
|
||||
- Configurable sign text, highlight, and priority
|
||||
- Configurable sign text and highlight group
|
||||
- Works out of the box — no setup call required
|
||||
|
||||
## Requirements
|
||||
@@ -36,7 +36,6 @@ All options are optional. Call `setup()` only if you want to customize:
|
||||
require("tiny-lightbulb").setup({
|
||||
sign = "💡", -- sign column text
|
||||
hl = "DiagnosticWarn", -- highlight group
|
||||
priority = 10, -- extmark priority
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ That's it. The plugin auto-loads with defaults. To customize, call setup: >lua
|
||||
require("tiny-lightbulb").setup({
|
||||
sign = "💡",
|
||||
hl = "DiagnosticWarn",
|
||||
priority = 10,
|
||||
})
|
||||
<
|
||||
==============================================================================
|
||||
@@ -53,16 +52,14 @@ setup({opts})
|
||||
require("tiny-lightbulb").setup({
|
||||
sign = "💡", -- sign column text
|
||||
hl = "DiagnosticWarn", -- highlight group for the sign
|
||||
priority = 10, -- extmark priority
|
||||
})
|
||||
<
|
||||
Parameters: ~
|
||||
{opts} (table|nil) Configuration table
|
||||
|
||||
Fields: ~
|
||||
{sign} (string) Text shown in the sign column. Default: "💡"
|
||||
{hl} (string) Highlight group for the sign. Default: "DiagnosticWarn"
|
||||
{priority} (number) Extmark priority. Default: 10
|
||||
{sign} (string) Text shown in the sign column. Default: "💡"
|
||||
{hl} (string) Highlight group for the sign. Default: "DiagnosticWarn"
|
||||
|
||||
==============================================================================
|
||||
vim:tw=78:ts=8:ft=help:norl:
|
||||
@@ -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
|
||||
|
||||
+1
-5
@@ -5,12 +5,9 @@ local eq = MiniTest.expect.equality
|
||||
|
||||
T["setup"] = MiniTest.new_set()
|
||||
|
||||
T["setup"]["creates augroups"] = function()
|
||||
-- plugin/ auto-loaded via minimal_init, so augroups should exist
|
||||
T["setup"]["creates augroup"] = function()
|
||||
local groups = vim.api.nvim_get_autocmds({ group = "tiny-lightbulb" })
|
||||
eq(#groups > 0, true)
|
||||
local clear_groups = vim.api.nvim_get_autocmds({ group = "tiny-lightbulb-clear" })
|
||||
eq(#clear_groups > 0, true)
|
||||
end
|
||||
|
||||
T["setup"]["is idempotent"] = function()
|
||||
@@ -21,7 +18,6 @@ T["setup"]["is idempotent"] = function()
|
||||
end
|
||||
|
||||
T["setup"]["respects custom sign"] = function()
|
||||
-- Just verify it doesn't error with custom opts
|
||||
require("tiny-lightbulb").setup({ sign = "CA" })
|
||||
local groups = vim.api.nvim_get_autocmds({ group = "tiny-lightbulb" })
|
||||
eq(#groups > 0, true)
|
||||
|
||||
Reference in new issue
Block a user