Implement ale.queue for calling ale#Queue in Lua

This commit is contained in:
w0rp
2025-03-22 01:10:11 +00:00
parent 33a902f489
commit 19e1b5a9d3
3 changed files with 61 additions and 4 deletions

View File

@@ -4506,19 +4506,21 @@ ale#Pad(str) *ale#Pad()*
parts of a command from variables.
ale#Queue(delay, [linting_flag, buffer_number]) *ale#Queue()*
ale.queue(delay, [linting_flag, buffer]) *ale.queue()*
ale#Queue(delay, [linting_flag, buffer]) *ale#Queue()*
Run linters for the current buffer, based on the filetype of the buffer,
with a given `delay`. A `delay` of `0` will run the linters immediately.
The linters will always be run in the background. Calling this function
again from the same buffer
several times will reset an internal timer so ALE doesn't check buffers too
often.
An optional `linting_flag` argument can be given. If `linting_flag` is
`'lint_file'`, then linters where the `lint_file` option evaluates to `1`
will be run. Otherwise, those linters will not be run.
An optional `buffer_number` argument can be given for specifying the buffer
to check. The active buffer (`bufnr('')`) will be checked by default.
An optional `buffer` argument can be given for specifying the buffer to
check. The active buffer (`bufnr('')`) will be checked by default.
*ale-cool-down*
If an exception is thrown when queuing/running ALE linters, ALE will enter

View File

@@ -55,6 +55,21 @@ ale.setup = setmetatable({
end,
})
---Run ALE linters on a buffer after a delay.
---
---If a delay in milliseconds multiple times, the internal timer used by ALE
---will be reset, so ALE doesn't lint too often.
---
---If the `linting_flag` is not 'lint_file' then linters that require files to
---be saved will no be run.
---@param delay number Milliseconds to wait for. A delay of 0 lints immediately.
---@param linting_flag string|nil If set to 'lint_file', run all linters.
---@param buffer number|nil The buffer to check. Defaults to the current buffer.
---@return nil
ale.queue = function(delay, linting_flag, buffer)
vim.fn["ale#Queue"](delay, linting_flag, buffer)
end
---Check if ALE supports a given feature.
---
---The ALE version can be checked with ale.has("ale-1.0.0"), etc.

View File

@@ -0,0 +1,40 @@
local eq = assert.are.same
local ale = require("ale")
describe("ale.queue", function()
local queue_calls
setup(function()
_G.vim = {
fn = {
["ale#Queue"] = function(...)
table.insert(queue_calls, {...})
end,
},
}
end)
teardown(function()
_G.vim = nil
end)
before_each(function()
queue_calls = {}
end)
it("should call ale#Queue with the right arguments", function()
ale.queue(0)
ale.queue(0, "")
ale.queue(123, "lint_file")
ale.queue(0, "", 42)
ale.queue(123, "lint_file", 42)
eq({
{0, nil, nil},
{0, "", nil},
{123, "lint_file", nil},
{0, "", 42},
{123, "lint_file", 42},
}, queue_calls)
end)
end)