Skip to content

Commit af34737

Browse files
authored
refactor: deprecate util.validate_bufnr()
1 parent ca26309 commit af34737

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

.github/ci/lint.sh

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ _check_deprecated_in_nvim_0_11() {
5757
echo 'Use vim.iter(vim.fs.parents(fname)):find(…) instead of util.path.search_ancestors(fname,…)'
5858
exit 1
5959
fi
60+
if git grep -P 'validate_bufnr' -- 'lsp/*.lua' ; then
61+
echo
62+
echo 'Do not use util.validate_bufnr(). Nvim stdlib already treats bufnr=0 as "current buffer".'
63+
exit 1
64+
fi
6065
}
6166

6267
_check_deprecated_utils() {

lsp/clangd.lua

-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111
--- - clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html)
1212
--- specified as compile_commands.json, see https://clangd.llvm.org/installation#compile_commandsjson
1313

14-
local util = require 'lspconfig.util'
15-
1614
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
1715
local function switch_source_header(bufnr)
1816
local method_name = 'textDocument/switchSourceHeader'
19-
bufnr = util.validate_bufnr(bufnr)
2017
local client = vim.lsp.get_clients({ bufnr = bufnr, name = 'clangd' })[1]
2118
if not client then
2219
return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name))

lsp/ds_pinyin_lsp.lua

-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
---
1616
--- ```
1717

18-
local util = require 'lspconfig.util'
19-
2018
local bin_name = 'ds-pinyin-lsp'
2119
if vim.fn.has 'win32' == 1 then
2220
bin_name = bin_name .. '.exe'
2321
end
2422

2523
local function ds_pinyin_lsp_off(bufnr)
26-
bufnr = util.validate_bufnr(bufnr)
2724
local ds_pinyin_lsp_client = vim.lsp.get_clients({ bufnr = bufnr, name = 'ds_pinyin_lsp' })[1]
2825
if ds_pinyin_lsp_client then
2926
ds_pinyin_lsp_client.notify('$/turn/completion', {
@@ -35,7 +32,6 @@ local function ds_pinyin_lsp_off(bufnr)
3532
end
3633

3734
local function ds_pinyin_lsp_on(bufnr)
38-
bufnr = util.validate_bufnr(bufnr)
3935
local ds_pinyin_lsp_client = vim.lsp.get_clients({ bufnr = bufnr, name = 'ds_pinyin_lsp' })[1]
4036
if ds_pinyin_lsp_client then
4137
ds_pinyin_lsp_client.notify('$/turn/completion', {

lsp/rust_analyzer.lua

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
local util = require 'lspconfig.util'
2525

2626
local function reload_workspace(bufnr)
27-
bufnr = util.validate_bufnr(bufnr)
2827
local clients = vim.lsp.get_clients { bufnr = bufnr, name = 'rust_analyzer' }
2928
for _, client in ipairs(clients) do
3029
vim.notify 'Reloading Cargo Workspace'

lua/lspconfig/util.lua

+16-14
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@ M.default_config = {
2020
-- global on_setup hook
2121
M.on_setup = nil
2222

23-
function M.bufname_valid(bufname)
24-
if bufname:match '^/' or bufname:match '^[a-zA-Z]:' or bufname:match '^zipfile://' or bufname:match '^tarfile:' then
25-
return true
26-
end
27-
return false
28-
end
29-
30-
function M.validate_bufnr(bufnr)
31-
if nvim_eleven then
32-
validate('bufnr', bufnr, 'number')
33-
end
34-
return bufnr == 0 and api.nvim_get_current_buf() or bufnr
35-
end
36-
3723
local function escape_wildcards(path)
3824
return path:gsub('([%[%]%?%*])', '\\%1')
3925
end
@@ -374,4 +360,20 @@ function M.get_managed_clients()
374360
return clients
375361
end
376362

363+
--- @deprecated Will be removed. Do not use.
364+
function M.bufname_valid(bufname)
365+
if bufname:match '^/' or bufname:match '^[a-zA-Z]:' or bufname:match '^zipfile://' or bufname:match '^tarfile:' then
366+
return true
367+
end
368+
return false
369+
end
370+
371+
--- @deprecated Will be removed. Do not use.
372+
function M.validate_bufnr(bufnr)
373+
if nvim_eleven then
374+
validate('bufnr', bufnr, 'number')
375+
end
376+
return bufnr == 0 and api.nvim_get_current_buf() or bufnr
377+
end
378+
377379
return M

0 commit comments

Comments
 (0)