diff --git a/doc/ale.txt b/doc/ale.txt index d3bf8224..6b72a0c7 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -4486,9 +4486,12 @@ ale#GetFilenameMappings(buffer, name) *ale#GetFilenameMappings()* See |g:ale_filename_mappings| for details on filename mapping. +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#Has('ale-x.y.z')`, such as `ale#Has('ale-2.4.0')`. diff --git a/lua/ale/init.lua b/lua/ale/init.lua index 521ef9ea..27f7a94b 100644 --- a/lua/ale/init.lua +++ b/lua/ale/init.lua @@ -55,6 +55,15 @@ ale.setup = setmetatable({ 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) ---@param buffer number The buffer number to retreive the variable for. ---@param variable_name string The variable to retrieve. diff --git a/test/lua/ale_has_spec.lua b/test/lua/ale_has_spec.lua new file mode 100644 index 00000000..e9120b28 --- /dev/null +++ b/test/lua/ale_has_spec.lua @@ -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)