Skip to content

Commit 11b926b

Browse files
committed
feat: add first sketch of CommandTOptions type alias
1 parent 256775e commit 11b926b

File tree

3 files changed

+79
-36
lines changed

3 files changed

+79
-36
lines changed

lua/wincent/commandt/private/options/schema.lua

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,50 @@
44
local is_table = require('wincent.commandt.private.is_table')
55
local types = require('wincent.commandt.private.options.types')
66

7+
---@alias CommandTOptions {
8+
--- always_show_dot_files?: boolean,
9+
--- finders?: table<string, {
10+
--- candidates?: (fun(): string[]) | string[],
11+
--- mode?: ModeOption,
12+
--- on_close?: fun(),
13+
--- on_directory?: fun(),
14+
--- options?: fun(),
15+
--- command?: fun() | string,
16+
--- fallback?: boolean,
17+
--- max_files?: (fun(): number) | number,
18+
--- open?: fun(),
19+
--- }>,
20+
--- height?: number,
21+
--- ignore_case?: boolean | fun(),
22+
--- mappings?: MappingsOption,
23+
--- margin?: number,
24+
--- match_listing?: {
25+
--- border?: BorderOption,
26+
--- icons?: boolean | fun(),
27+
--- truncate?: TruncateOption,
28+
--- },
29+
--- never_show_dot_files?: boolean,
30+
--- order?: OrderOption,
31+
--- position?: PositionOption,
32+
--- prompt?: {
33+
--- border?: BorderOption,
34+
--- },
35+
--- open?: fun(),
36+
--- root_markers?: string[],
37+
--- scanners?: {
38+
--- fd?: { max_files?: number },
39+
--- find?: { max_files?: number },
40+
--- file?: { max_files?: number },
41+
--- git?: { max_files?: number, submodules?: boolean, untracked?: boolean },
42+
--- rg?: { max_files?: number },
43+
--- tag?: { include_filenames?: boolean },
44+
--- },
45+
--- selection_highlight?: string,
46+
--- smart_case?: boolean | fun(),
47+
--- threads?: number,
48+
--- traverse?: TraverseOption,
49+
---}
50+
751
local schema = {
852
kind = 'table',
953
keys = {
@@ -25,15 +69,7 @@ local schema = {
2569
},
2670
optional = true,
2771
},
28-
mode = {
29-
kind = {
30-
one_of = {
31-
'file',
32-
'virtual',
33-
},
34-
},
35-
optional = true,
36-
},
72+
mode = types.mode,
3773
on_close = {
3874
kind = 'function',
3975
optional = true,
@@ -118,7 +154,7 @@ local schema = {
118154
},
119155
},
120156
never_show_dot_files = { kind = 'boolean' },
121-
order = { kind = { one_of = { 'forward', 'reverse' } } },
157+
order = types.order,
122158
position = types.position,
123159
prompt = {
124160
kind = 'table',
@@ -211,7 +247,7 @@ local schema = {
211247
kind = 'number',
212248
optional = true,
213249
},
214-
traverse = { kind = { one_of = { 'file', 'pwd', 'none' } } },
250+
traverse = types.traverse,
215251
},
216252
meta = function(t)
217253
if t.always_show_dot_files == true and t.never_show_dot_files == true then

lua/wincent/commandt/private/options/types.lua

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,36 @@ local border = {
2727
},
2828
}
2929

30+
---@alias MappingsOption {
31+
--- i?: table<string, string>,
32+
--- n?: table<string, string>
33+
---}
34+
local mappings = {
35+
kind = 'table',
36+
keys = {
37+
i = {
38+
kind = 'table',
39+
values = { kind = 'string' },
40+
},
41+
n = {
42+
kind = 'table',
43+
values = { kind = 'string' },
44+
},
45+
},
46+
}
47+
48+
---@alias ModeOption 'file' | 'virtual'
49+
local mode = { kind = { one_of = { 'file', 'virtual' } }, optional = true }
50+
51+
---@alias OrderOption 'forward' | 'reverse'
52+
local order = { kind = { one_of = { 'forward', 'reverse' } } }
53+
3054
---@alias PositionOption 'bottom' | 'center' | 'top'
3155
local position = { kind = { one_of = { 'bottom', 'center', 'top' } } }
3256

57+
---@alias TraverseOption 'file' | 'pwd' | 'none'
58+
local traverse = { kind = { one_of = { 'file', 'pwd', 'none' } } }
59+
3360
---@alias TruncateOption
3461
---| 'beginning'
3562
---| 'middle'
@@ -50,24 +77,6 @@ local truncate = {
5077
},
5178
}
5279

53-
---@alias MappingsOption {
54-
--- i?: table<string, string>,
55-
--- n?: table<string, string>
56-
---}
57-
local mappings = {
58-
kind = 'table',
59-
keys = {
60-
i = {
61-
kind = 'table',
62-
values = { kind = 'string' },
63-
},
64-
n = {
65-
kind = 'table',
66-
values = { kind = 'string' },
67-
},
68-
},
69-
}
70-
7180
return {
7281
border = border,
7382
height = {
@@ -89,6 +98,9 @@ return {
8998
end
9099
end,
91100
},
101+
mode = mode,
102+
order = order,
92103
position = position,
104+
traverse = traverse,
93105
truncate = truncate,
94106
}

lua/wincent/commandt/private/ui.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local MatchListing = require('wincent.commandt.private.match_listing')
77
local Prompt = require('wincent.commandt.private.prompt')
88
local Settings = require('wincent.commandt.private.settings')
99
local validate = require('wincent.commandt.private.validate')
10+
local types = require('wincent.commandt.private.options.types')
1011

1112
-- Reverses `list` in place.
1213
local reverse = function(list)
@@ -95,13 +96,7 @@ end
9596
local schema = {
9697
kind = 'table',
9798
keys = {
98-
mode = { kind = {
99-
one_of = {
100-
'file',
101-
'virtual',
102-
},
103-
optional = true,
104-
} },
99+
mode = types.mode,
105100
name = { kind = 'string' },
106101
on_close = { kind = 'function', optional = true },
107102
on_open = { kind = 'function', optional = true },

0 commit comments

Comments
 (0)