Skip to content

Commit 157c85c

Browse files
committed
chore: start adding some explicit type annotations
1 parent 718598f commit 157c85c

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

lua/wincent/commandt/init.lua

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ local sub = require('wincent.commandt.private.sub')
1111

1212
local commandt = {}
1313

14-
-- "Smart" open that will switch to an already open window containing the
15-
-- specified `buffer`, if one exists; otherwise, it will open a new window using
16-
-- `command` (which should be one of `edit`, `tabedit`, `split`, or `vsplit`).
14+
--- "Smart" open that will switch to an already open window containing the
15+
--- specified `buffer`, if one exists; otherwise, it will open a new window
16+
--- using `command` (which should be one of `edit`, `tabedit`, `split`, or
17+
--- `vsplit`).
18+
---
19+
--- @param buffer string
20+
--- @param command 'edit' | 'split' | 'tabedit' | 'vsplit'
21+
--- @return nil
1722
local function smart_open(buffer, command)
1823
buffer = vim.fn.fnameescape(buffer)
1924
local is_visible = require('wincent.commandt.private.buffer_visible')(buffer)
@@ -28,20 +33,30 @@ end
2833

2934
local directory_stack = {}
3035

36+
--- Push a directory onto the stack.
37+
---
38+
--- @param directory string
39+
--- @return nil
3140
local function pushd(directory)
3241
table.insert(directory_stack, vim.uv.cwd())
3342
vim.fn.chdir(directory)
3443
end
3544

45+
--- Pop a directory from the stack.
46+
---
47+
--- @return nil
3648
local function popd()
3749
local directory = table.remove(directory_stack)
3850
if directory then
3951
vim.fn.chdir(directory)
4052
end
4153
end
4254

43-
-- Common `on_directory` implementation that infers the appropriate directory if
44-
-- none is explicitly provided.
55+
--- Common `on_directory` implementation that infers the appropriate directory
56+
--- if none is explicitly provided.
57+
---
58+
--- @param directory string | nil
59+
--- @return string
4560
local function on_directory(directory)
4661
if directory == '' or directory == nil then
4762
return commandt._directory()
@@ -341,11 +356,16 @@ local function force_dot_files(options)
341356
return options
342357
end
343358

359+
--- @alias CandidatesFunction
360+
--- | fun(directory: string): string[]
361+
--- | # Function that returns a list of candidate strings
362+
344363
local default_options = {
345364
always_show_dot_files = false,
346365
finders = {
347366
-- Returns the list of paths currently loaded into buffers.
348367
buffer = {
368+
--- @type CandidatesFunction
349369
candidates = function(_directory)
350370
local handles = vim.api.nvim_list_bufs()
351371
local paths = {}

0 commit comments

Comments
 (0)