Skip to content

Commit 532ac9e

Browse files
author
Jose Alvarez
committed
refactor!: remove 0.5.1 support
1 parent 739a98c commit 532ac9e

16 files changed

+125
-483
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ for external processes.
2424
null-ls is in **beta status**. Please see below for steps to follow if something
2525
doesn't work the way you expect (or doesn't work at all).
2626

27-
At the moment, null-is is compatible with Neovim 0.5.1 (stable) and 0.6 (head),
27+
At the moment, null-is is compatible with Neovim 0.6.0 (stable) and 0.7 (head),
2828
but some features and performance improvements are exclusive to the latest
2929
version.
3030

doc/BUILTINS.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ local sources = { null_ls.builtins.formatting.uncrustify }
13741374
##### About
13751375

13761376
Formatter for `python` files
1377+
13771378
- Supports both `textDocument/formatting` and `textDocument/rangeFormatting`.
13781379
- `textDocument/rangeFormatting` is line-based.
13791380

@@ -1973,11 +1974,9 @@ local sources = { null_ls.builtins.diagnostics.yamllint }
19731974

19741975
### Diagnostics on save
19751976

1976-
**NOTE**: These sources depend on Neovim version 0.6.0 and are not compatible
1977-
with previous versions.
1978-
1979-
These sources run **only** on save, meaning that the diagnostics you see will
1980-
not reflect changes to the buffer until you write the changes to the disk.
1977+
**NOTE**: These sources run **only** on save, meaning that the diagnostics you
1978+
see will not reflect changes to the buffer until you write the changes to the
1979+
disk.
19811980

19821981
You can configure built-in diagnostic sources to run on save by overriding
19831982
`method`:

doc/SOURCES.md

-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ Disables all sources matching `query`, preventing them from running under any
122122
conditions. See `get_source(query)` above for information about the structure of
123123
`query`.
124124

125-
On Neovim versions >= 0.6.0, this will also clear diagnostics from disabled
126-
sources (you'll have to make a change to trigger an update on lower versions).
127-
128125
## enable(query)
129126

130127
Enables all disabled sources matching `query`, allowing them to run again as

lua/null-ls/config.lua

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ local defaults = {
1919
},
2020
-- prevent double setup
2121
_setup = false,
22-
-- force using LSP handler, even when native API is available (e.g diagnostics)
23-
_use_lsp_handler = false,
2422
}
2523

2624
local config = vim.deepcopy(defaults)

lua/null-ls/diagnostics.lua

+10-33
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,13 @@ local log = require("null-ls.logger")
66

77
local api = vim.api
88

9-
local should_use_diagnostic_api = function()
10-
return vim.diagnostic and not c.get()._use_lsp_handler
11-
end
12-
139
local namespaces = {}
1410

1511
local M = {}
1612

1713
M.namespaces = namespaces
1814

1915
M.hide_source_diagnostics = function(id)
20-
if not vim.diagnostic then
21-
log:debug("unable to clear diagnostics (not available on nvim < 0.6.0)")
22-
return
23-
end
24-
2516
local ns = namespaces[id]
2617
if not ns then
2718
return
@@ -48,14 +39,10 @@ end
4839
local postprocess = function(diagnostic, _, generator)
4940
local range = convert_range(diagnostic)
5041
-- the diagnostic API requires 0-indexing, so we can repurpose the LSP range
51-
if should_use_diagnostic_api() then
52-
diagnostic.lnum = range["start"].line
53-
diagnostic.end_lnum = range["end"].line
54-
diagnostic.col = range["start"].character
55-
diagnostic.end_col = range["end"].character
56-
else
57-
diagnostic.range = range
58-
end
42+
diagnostic.lnum = range["start"].line
43+
diagnostic.end_lnum = range["end"].line
44+
diagnostic.col = range["start"].character
45+
diagnostic.end_col = range["end"].character
5946

6047
diagnostic.source = diagnostic.source or generator.opts.name or generator.opts.command or "null-ls"
6148

@@ -71,21 +58,11 @@ local postprocess = function(diagnostic, _, generator)
7158
diagnostic.message = formatted
7259
end
7360

74-
local handle_diagnostics = function(diagnostics, uri, bufnr, client_id)
75-
if should_use_diagnostic_api() then
76-
for id, by_id in pairs(diagnostics) do
77-
namespaces[id] = namespaces[id] or api.nvim_create_namespace("NULL_LS_SOURCE_" .. id)
78-
vim.diagnostic.set(namespaces[id], bufnr, by_id)
79-
end
80-
return
61+
local handle_diagnostics = function(diagnostics, bufnr)
62+
for id, by_id in pairs(diagnostics) do
63+
namespaces[id] = namespaces[id] or api.nvim_create_namespace("NULL_LS_SOURCE_" .. id)
64+
vim.diagnostic.set(namespaces[id], bufnr, by_id)
8165
end
82-
83-
local handler = u.resolve_handler(methods.lsp.PUBLISH_DIAGNOSTICS)
84-
handler(nil, { diagnostics = diagnostics, uri = uri }, {
85-
method = methods.lsp.PUBLISH_DIAGNOSTICS,
86-
client_id = client_id,
87-
bufnr = bufnr,
88-
})
8966
end
9067

9168
-- track last changedtick to only send most recent diagnostics
@@ -135,7 +112,7 @@ M.handler = function(original_params)
135112
method = methods.map[method],
136113
params = params,
137114
postprocess = postprocess,
138-
index_by_id = should_use_diagnostic_api(),
115+
index_by_id = true,
139116
callback = function(diagnostics)
140117
log:trace("received diagnostics from generators")
141118
log:trace(diagnostics)
@@ -145,7 +122,7 @@ M.handler = function(original_params)
145122
return
146123
end
147124

148-
handle_diagnostics(diagnostics, uri, bufnr, original_params.client_id)
125+
handle_diagnostics(diagnostics, bufnr)
149126
end,
150127
})
151128
end

lua/null-ls/handlers.lua

-32
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,7 @@
1-
local u = require("null-ls.utils")
21
local methods = require("null-ls.methods")
32

43
local M = {}
54

6-
function M.setup()
7-
-- code action batching is merged into master
8-
if u.has_version("0.6.0") then
9-
return
10-
end
11-
12-
M.code_action_handler = M.combine(methods.lsp.CODE_ACTION)
13-
end
14-
15-
-- this will override a handler, batch results and debounce them
16-
function M.combine(method, ms)
17-
ms = ms or 100
18-
19-
local orig = u.resolve_handler(method)
20-
local all_results = {}
21-
22-
local handler = u.debounce(ms, function()
23-
if #all_results > 0 then
24-
pcall(orig, nil, all_results)
25-
all_results = {}
26-
end
27-
end)
28-
29-
vim.lsp.handlers[method] = function(_, results)
30-
vim.list_extend(all_results, results or {})
31-
handler()
32-
end
33-
34-
return vim.lsp.handlers[method]
35-
end
36-
375
M.setup_client = function(client)
386
if client._null_ls_setup then
397
return

lua/null-ls/init.lua

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ M.config = function(user_config)
3030
c.setup(user_config or {})
3131
require("null-ls.lspconfig").setup()
3232
require("null-ls.rpc").setup()
33-
require("null-ls.handlers").setup()
3433

3534
vim.cmd("command! NullLsInfo lua require('null-ls').null_ls_info()")
3635
vim.cmd("command! NullLsLog lua vim.fn.execute('edit ' .. require('null-ls.logger').get_path())")

lua/null-ls/lspconfig.lua

-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ local should_attach = function(bufnr)
1818
end
1919

2020
local ft = api.nvim_buf_get_option(bufnr, "filetype")
21-
-- writing and immediately deleting a buffer (e.g. :wq from a git commit)
22-
-- triggers a bug on 0.5.1 which is fixed on master
23-
if ft == "gitcommit" and not u.has_version("0.6.0") then
24-
return false
25-
end
26-
2721
for _, source in ipairs(all_sources) do
2822
if sources.is_available(source, ft) then
2923
return true

lua/null-ls/rpc.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ local capabilities = {
4242
textDocumentSync = {
4343
change = 1, -- prompt LSP client to send full document text on didOpen and didChange
4444
openClose = true,
45-
save = u.has_version("0.6.0"),
45+
save = true,
4646
},
4747
}
4848

lua/null-ls/sources.lua

-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local methods = require("null-ls.methods")
22
local diagnostics = require("null-ls.diagnostics")
3-
local u = require("null-ls.utils")
43

54
local validate = vim.validate
65

@@ -197,11 +196,6 @@ M.validate_and_transform = function(source)
197196
method_map[method] = true
198197
end
199198

200-
if method_map[methods.internal.DIAGNOSTICS_ON_SAVE] and not u.has_version("0.6.0") then
201-
u.echo("WarningMsg", string.format("source %s is not supported on nvim versions < 0.6.0", name))
202-
return
203-
end
204-
205199
return {
206200
name = name,
207201
generator = generator,

lua/null-ls/utils.lua

+12-43
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ local get_line_ending = function(bufnr)
1515
end
1616

1717
local resolve_content = function(params, bufnr)
18-
if M.has_version("0.6.0") or get_line_ending(bufnr) == format_line_ending["unix"] then
19-
-- diagnostic notifications will send full buffer content on open and change
20-
-- so we can avoid unnecessary api calls
21-
if params.method == methods.lsp.DID_OPEN and params.textDocument and params.textDocument.text then
22-
return M.split_at_newline(params.bufnr, params.textDocument.text)
23-
end
24-
if
25-
params.method == methods.lsp.DID_CHANGE
26-
and params.contentChanges
27-
and params.contentChanges[1]
28-
and params.contentChanges[1].text
29-
then
30-
return M.split_at_newline(params.bufnr, params.contentChanges[1].text)
31-
end
18+
-- diagnostic notifications will send full buffer content on open and change
19+
-- so we can avoid unnecessary api calls
20+
if params.method == methods.lsp.DID_OPEN and params.textDocument and params.textDocument.text then
21+
return M.split_at_newline(params.bufnr, params.textDocument.text)
22+
end
23+
if
24+
params.method == methods.lsp.DID_CHANGE
25+
and params.contentChanges
26+
and params.contentChanges[1]
27+
and params.contentChanges[1].text
28+
then
29+
return M.split_at_newline(params.bufnr, params.contentChanges[1].text)
3230
end
3331

3432
return M.buf.content(bufnr)
@@ -227,33 +225,4 @@ M.table = {
227225
end,
228226
}
229227

230-
-- TODO: remove on 0.6.0 release
231-
function M.debounce(ms, fn)
232-
local timer = vim.loop.new_timer()
233-
return function(...)
234-
local argv = { ... }
235-
timer:start(ms, 0, function()
236-
timer:stop()
237-
vim.schedule_wrap(fn)(unpack(argv))
238-
end)
239-
end
240-
end
241-
242-
function M.throttle(ms, fn)
243-
local timer = vim.loop.new_timer()
244-
local running = false
245-
return function(...)
246-
if not running then
247-
local argv = { ... }
248-
local argc = select("#", ...)
249-
250-
timer:start(ms, 0, function()
251-
running = false
252-
pcall(vim.schedule_wrap(fn), unpack(argv, 1, argc))
253-
end)
254-
running = true
255-
end
256-
end
257-
end
258-
259228
return M

0 commit comments

Comments
 (0)