mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 05:04:28 +08:00
Add ale.has to mirror ale#Has in Lua
This commit is contained in:
@@ -4486,9 +4486,12 @@ ale#GetFilenameMappings(buffer, name) *ale#GetFilenameMappings()*
|
|||||||
See |g:ale_filename_mappings| for details on filename mapping.
|
See |g:ale_filename_mappings| for details on filename mapping.
|
||||||
|
|
||||||
|
|
||||||
|
ale.has(feature) *ale.has()*
|
||||||
ale#Has(feature) *ale#Has()*
|
ale#Has(feature) *ale#Has()*
|
||||||
|
|
||||||
Return `1` if ALE supports a given feature, like |has()| for Vim features.
|
In Vim, `ale#Has` returns `1` if ALE supports a given feature, like |has()|
|
||||||
|
for Vim features. In Lua `ale.has` returns `true` instead, and `false` if a
|
||||||
|
feature is not supported.
|
||||||
|
|
||||||
ALE versions can be checked with version strings in the format
|
ALE versions can be checked with version strings in the format
|
||||||
`ale#Has('ale-x.y.z')`, such as `ale#Has('ale-2.4.0')`.
|
`ale#Has('ale-x.y.z')`, such as `ale#Has('ale-2.4.0')`.
|
||||||
|
|||||||
@@ -55,6 +55,15 @@ ale.setup = setmetatable({
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
---Check if ALE supports a given feature.
|
||||||
|
---
|
||||||
|
---The ALE version can be checked with ale.has("ale-1.0.0"), etc.
|
||||||
|
---@param feature string The feature to test for.
|
||||||
|
---@return boolean supported If the feature is supported.
|
||||||
|
ale.has = function(feature)
|
||||||
|
return vim.fn["ale#Has"](feature) == 1
|
||||||
|
end
|
||||||
|
|
||||||
---Get an ALE variable for a buffer (first) or globally (second)
|
---Get an ALE variable for a buffer (first) or globally (second)
|
||||||
---@param buffer number The buffer number to retreive the variable for.
|
---@param buffer number The buffer number to retreive the variable for.
|
||||||
---@param variable_name string The variable to retrieve.
|
---@param variable_name string The variable to retrieve.
|
||||||
|
|||||||
27
test/lua/ale_has_spec.lua
Normal file
27
test/lua/ale_has_spec.lua
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
local eq = assert.are.same
|
||||||
|
local ale = require("ale")
|
||||||
|
|
||||||
|
describe("ale.has", function()
|
||||||
|
setup(function()
|
||||||
|
_G.vim = {
|
||||||
|
fn = {
|
||||||
|
["ale#Has"] = function(feature)
|
||||||
|
if feature == "ale-4.0.0" then
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
teardown(function()
|
||||||
|
_G.vim = nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("should return valuse from ale#Has correctly", function()
|
||||||
|
eq(true, ale.has("ale-4.0.0"))
|
||||||
|
eq(false, ale.has("ale-20.0.0"))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Reference in New Issue
Block a user