mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 05:04:28 +08:00
Implement ale.queue for calling ale#Queue in Lua
This commit is contained in:
10
doc/ale.txt
10
doc/ale.txt
@@ -4506,19 +4506,21 @@ ale#Pad(str) *ale#Pad()*
|
|||||||
parts of a command from variables.
|
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,
|
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.
|
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
|
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
|
An optional `linting_flag` argument can be given. If `linting_flag` is
|
||||||
`'lint_file'`, then linters where the `lint_file` option evaluates to `1`
|
`'lint_file'`, then linters where the `lint_file` option evaluates to `1`
|
||||||
will be run. Otherwise, those linters will not be run.
|
will be run. Otherwise, those linters will not be run.
|
||||||
|
|
||||||
An optional `buffer_number` argument can be given for specifying the buffer
|
An optional `buffer` argument can be given for specifying the buffer to
|
||||||
to check. The active buffer (`bufnr('')`) will be checked by default.
|
check. The active buffer (`bufnr('')`) will be checked by default.
|
||||||
|
|
||||||
*ale-cool-down*
|
*ale-cool-down*
|
||||||
If an exception is thrown when queuing/running ALE linters, ALE will enter
|
If an exception is thrown when queuing/running ALE linters, ALE will enter
|
||||||
|
|||||||
@@ -55,6 +55,21 @@ ale.setup = setmetatable({
|
|||||||
end,
|
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.
|
---Check if ALE supports a given feature.
|
||||||
---
|
---
|
||||||
---The ALE version can be checked with ale.has("ale-1.0.0"), etc.
|
---The ALE version can be checked with ale.has("ale-1.0.0"), etc.
|
||||||
|
|||||||
40
test/lua/ale_queue_spec.lua
Normal file
40
test/lua/ale_queue_spec.lua
Normal 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)
|
||||||
Reference in New Issue
Block a user