Skip to content

Commit 01f8e62

Browse files
committed
utils: use utils.has_version instead of vim.fn.has
1 parent 183b021 commit 01f8e62

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎lua/null-ls/client.lua‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ local on_init = function(new_client, initialize_result)
104104
end
105105

106106
new_client.supports_method = supports_method
107-
if vim.fn.has("nvim-0.11") == 1 then
107+
if u.has_version("0.11") then
108108
method_wrapper(new_client, vim.lsp.client, "supports_method")
109109
end
110110

@@ -237,7 +237,7 @@ M.notify_client = function(method, params)
237237
return
238238
end
239239

240-
if vim.fn.has("nvim-0.11") == 1 then
240+
if u.has_version("0.11") then
241241
client:notify(method, params)
242242
else
243243
---@diagnostic disable-next-line: param-type-mismatch

‎lua/null-ls/info.lua‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local c = require("null-ls.config")
2+
local u = require("null-ls.utils")
23
local log = require("null-ls.logger")
34
local methods = require("null-ls.methods")
45
local sources = require("null-ls.sources")
@@ -40,12 +41,12 @@ end
4041
local make_backdrop = function(backdrop)
4142
-- adapted from `lazy.nvim`
4243
local normal, has_bg
43-
if vim.fn.has("nvim-0.9.0") == 0 then
44-
normal = vim.api.nvim_get_hl_by_name("Normal", true)
45-
has_bg = normal and normal.background ~= nil
46-
else
44+
if u.has_version("0.9.0") then
4745
normal = vim.api.nvim_get_hl(0, { name = "Normal" })
4846
has_bg = normal and normal.bg ~= nil
47+
else
48+
normal = vim.api.nvim_get_hl_by_name("Normal", true)
49+
has_bg = normal and normal.background ~= nil
4950
end
5051

5152
if has_bg and backdrop and backdrop < 100 and vim.o.termguicolors then

‎lua/null-ls/utils/init.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ M.get_vcs_root = function()
371371
end
372372

373373
M.validate = function(validators)
374-
if vim.fn.has("nvim-0.11.0") ~= 1 then
374+
if not M.has_version("0.11.0") then
375375
vim.validate(validators)
376376
return
377377
end

‎test/spec/client_spec.lua‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local mock = require("luassert.mock")
33

44
local c = require("null-ls.config")
55
local methods = require("null-ls.methods")
6+
local u = require("null-ls.utils")
67
local tu = require("null-ls.utils.test")
78

89
local lsp = mock(vim.lsp, true)
@@ -111,7 +112,7 @@ describe("client", function()
111112
local supports_method
112113
before_each(function()
113114
on_init(mock_client)
114-
if vim.fn.has("nvim-0.11") == 1 then
115+
if u.has_version("0.11") then
115116
supports_method = function(method)
116117
return mock_client:supports_method(method)
117118
end
@@ -132,7 +133,7 @@ describe("client", function()
132133
assert.equals(is_supported, true)
133134
end)
134135

135-
if vim.fn.has("nvim-0.11") == 1 then
136+
if u.has_version("0.11") then
136137
it("can still use legacy . syntax", function()
137138
can_run.returns(true)
138139
local is_supported = mock_client.supports_method(methods.lsp.CODE_ACTION)
@@ -359,7 +360,7 @@ describe("client", function()
359360

360361
client.notify_client(mock_method, mock_params)
361362

362-
if vim.fn.has("nvim-0.11") == 1 then
363+
if u.has_version("0.11") then
363364
assert.stub(notify).was_called_with(mock_client, mock_method, mock_params)
364365
else
365366
assert.stub(notify).was_called_with(mock_method, mock_params)

‎test/spec/e2e_spec.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ describe("e2e", function()
649649

650650
-- https://github.com/neovim/neovim/commit/8260e4860b27a54a061bd8e2a9da23069993953a
651651
-- hover no longer supports handler
652-
if not vim.fn.has("nvim-0.11") == 1 then
652+
if not u.has_version("0.11") then
653653
describe("hover", function()
654654
local mock_handler = require("luassert.stub").new()
655655

0 commit comments

Comments
 (0)