Skip to content

Commit 87f3c77

Browse files
committed
style: typing improvements
1 parent fef4bc7 commit 87f3c77

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

lua/null-ls/client.lua

+8-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ end
9999

100100
local M = {}
101101

102-
---@param root_dir? string The root directory of the project.
102+
---@param root_dir string? The root directory of the project.
103103
M.start_client = function(root_dir)
104104
local config = {
105105
name = "null-ls",
@@ -136,8 +136,8 @@ end
136136

137137
--- This function can be asynchronous. Use cb to run code after the buffer has been retried.
138138
---
139-
---@param bufnr? number
140-
---@param cb? fun(did_attach: boolean)
139+
---@param bufnr number?
140+
---@param cb fun(did_attach: boolean)?
141141
M.try_add = function(bufnr, cb)
142142
bufnr = bufnr or api.nvim_get_current_buf()
143143
if not should_attach(bufnr) then
@@ -191,6 +191,8 @@ M.get_offset_encoding = function()
191191
return client and client.offset_encoding or "utf-16"
192192
end
193193

194+
---@param method vim.lsp.protocol.Method|string
195+
---@param params table
194196
M.notify_client = function(method, params)
195197
if not client then
196198
log:debug(
@@ -202,10 +204,13 @@ M.notify_client = function(method, params)
202204
if vim.fn.has("nvim-0.11") == 1 then
203205
client:notify(method, params)
204206
else
207+
---@diagnostic disable-next-line: param-type-mismatch
205208
client.notify(method, params)
206209
end
207210
end
208211

212+
---@param method vim.lsp.protocol.Method|string
213+
---@return lsp.Handler handler
209214
M.resolve_handler = function(method)
210215
return client and client.handlers[method] or lsp.handlers[method]
211216
end

lua/null-ls/code-actions.lua

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ local postprocess = function(action)
1515
}
1616
end
1717

18+
---@param method vim.lsp.protocol.Method
19+
---@param handler fun(actions: table)
1820
M.handler = function(method, original_params, handler)
1921
if method == methods.lsp.CODE_ACTION then
2022
if not original_params.textDocument then

lua/null-ls/utils/cosmiconfig.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local u = require("null-ls.utils")
33
-- Create the default root_pattern for tools using cosmiconfig.
44
-- https://github.com/cosmiconfig/cosmiconfig#usage-for-end-users
55
---@param module_name string The module name.
6-
---@param pkg_json_field_name? string The field name in package.json.
6+
---@param pkg_json_field_name string? The field name in package.json.
77
return function(module_name, pkg_json_field_name)
88
local patterns = {
99
".{NAME}rc",

lua/null-ls/utils/init.lua

+6-5
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ M.table = {
203203

204204
--- if opt is a function, call it with args; otherwise, return a copy of opt
205205
---@param opt any
206-
---@vararg any args
206+
---@param ... any args
207207
---@return any
208208
M.handle_function_opt = function(opt, ...)
209209
if type(opt) == "function" then
@@ -283,7 +283,7 @@ M.path = {
283283
---@alias root_pattern_cb fun(root_dir: string|nil)
284284

285285
--- creates a callback that returns the first root matching a specified pattern
286-
---@vararg string patterns
286+
---@param ... string patterns
287287
---@return fun(startpath: string, root_pattern_cb): nil root_dir
288288
M.root_pattern_async = function(...)
289289
local patterns = util.tbl_flatten({ ... })
@@ -318,7 +318,7 @@ M.root_pattern_async = function(...)
318318
end
319319

320320
--- creates a callback that returns the first root matching a specified pattern
321-
---@vararg string patterns
321+
---@param ... string patterns
322322
---@return fun(startpath: string): string|nil root_dir
323323
M.root_pattern = function(...)
324324
local patterns = util.tbl_flatten({ ... })
@@ -331,7 +331,6 @@ M.root_pattern = function(...)
331331
-- escape wildcard characters in the path so that it is not treated like a glob
332332
path = path:gsub("([%[%]%?%*])", "\\%1")
333333
for _, pattern in ipairs(patterns) do
334-
---@diagnostic disable-next-line: param-type-mismatch
335334
for _, p in ipairs(vim.fn.glob(M.path.join(path, pattern), true, true)) do
336335
if M.path.exists(p) then
337336
return path
@@ -352,10 +351,12 @@ M.root_pattern = function(...)
352351
end
353352
end
354353

354+
---@module "null-ls.utils.make_params"
355355
M.make_params = function(...)
356356
return require("null-ls.utils.make_params")(...)
357357
end
358358

359+
---@module "null-ls.utils.cosmiconfig"
359360
M.cosmiconfig = function(...)
360361
return require("null-ls.utils.cosmiconfig")(...)
361362
end
@@ -365,7 +366,7 @@ end
365366
M.get_vcs_root = function()
366367
local cwd, err_name, err_msg = uv.cwd()
367368
assert(cwd, string.format("[Error %s]: %s", err_name, err_msg))
368-
local vcs_root = M.root_pattern(".git", ".hg", ".svn", ".bzr")(cwd)
369+
local vcs_root = M.root_pattern(".git", ".hg", ".svn", ".bzr", ".fossil", "_darcs", ".pijul")(cwd)
369370
return vcs_root
370371
end
371372

0 commit comments

Comments
 (0)