Skip to content

Commit 33b8b7c

Browse files
committed
refactor: deal with code-smell
Instead of mashing two types together, pass them as separate params. Later on when I have time I'll improve the type annotations (currently just calling them `any`).
1 parent 200bc18 commit 33b8b7c

File tree

2 files changed

+29
-35
lines changed

2 files changed

+29
-35
lines changed

lua/wincent/commandt/finder.lua

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
local UI = require('wincent.commandt.private.ui')
55

6-
local merge = require('wincent.commandt.private.merge')
76
local popd = require('wincent.commandt.popd')
87
local pushd = require('wincent.commandt.pushd')
98
local relativize = require('wincent.commandt.private.relativize')
@@ -17,16 +16,13 @@ local function file_finder(directory)
1716
local finder = require('wincent.commandt.private.finders.file')('.', options)
1817

1918
ui = UI.new()
20-
ui:show(
21-
finder,
22-
merge(options, {
23-
name = 'file',
24-
on_open = function(result)
25-
return relativize(directory, result)
26-
end,
27-
on_close = popd,
28-
})
29-
)
19+
ui:show(finder, options, {
20+
name = 'file',
21+
on_open = function(result)
22+
return relativize(directory, result)
23+
end,
24+
on_close = popd,
25+
})
3026
end
3127

3228
local function watchman_finder(directory)
@@ -35,15 +31,12 @@ local function watchman_finder(directory)
3531
local finder = require('wincent.commandt.private.finders.watchman')(directory, options)
3632

3733
ui = UI.new()
38-
ui:show(
39-
finder,
40-
merge(options, {
41-
name = 'watchman',
42-
on_open = function(result)
43-
return relativize(directory, result)
44-
end,
45-
})
46-
)
34+
ui:show(finder, options, {
35+
name = 'watchman',
36+
on_open = function(result)
37+
return relativize(directory, result)
38+
end,
39+
})
4740
end
4841

4942
local function finder(name, directory)
@@ -92,17 +85,12 @@ local function finder(name, directory)
9285
finder.fallback = require('wincent.commandt.private.finders.fallback')(finder, directory, options)
9386
end
9487

95-
-- TODO: fix type smell here. we're merging "mode", a property that exists
96-
-- inside matcher configs, into the top level, along with "name".
9788
ui = UI.new()
98-
ui:show(
99-
finder,
100-
merge(options, {
101-
name = name,
102-
mode = mode,
103-
on_close = config.on_close,
104-
})
105-
)
89+
ui:show(finder, options, {
90+
name = name,
91+
mode = mode,
92+
on_close = config.on_close,
93+
})
10694
end
10795

10896
return finder

lua/wincent/commandt/private/ui.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,20 @@ function UI:_open(ex_command)
9191
self.on_open = nil
9292
end
9393

94-
function UI:show(finder, options)
94+
--- Display the Command-T UI, consisting of a Prompt window and a MatchListing
95+
--- window.
96+
---
97+
--- @param finder any
98+
--- @param options any Top-level Command-T options.
99+
--- @param config any `UI`-specific config.
100+
function UI:show(finder, options, config)
95101
-- TODO validate options
96102
self.current_finder = finder
97103

98104
self.current_window = vim.api.nvim_get_current_win()
99105

100-
self.on_close = options.on_close
101-
self.on_open = options.on_open
106+
self.on_close = config.on_close
107+
self.on_open = config.on_open
102108

103109
-- Temporarily override global settings.
104110
-- For now just 'hlsearch', but may add more later (see
@@ -115,7 +121,7 @@ function UI:show(finder, options)
115121
self.match_listing = MatchListing.new({
116122
border = border,
117123
height = options.height,
118-
icons = options.mode ~= 'virtual' and options.match_listing.icons or false,
124+
icons = config.mode ~= 'virtual' and options.match_listing.icons or false,
119125
margin = options.margin,
120126
position = options.position,
121127
selection_highlight = options.selection_highlight,
@@ -131,7 +137,7 @@ function UI:show(finder, options)
131137
height = options.height,
132138
mappings = options.mappings,
133139
margin = options.margin,
134-
name = options.name,
140+
name = config.name,
135141
on_change = function(query)
136142
self.results, self.candidate_count = self.current_finder.run(query)
137143
if #self.results > 0 or self.candidate_count > 0 then

0 commit comments

Comments
 (0)