Skip to content

Commit 9122eaa

Browse files
committed
refactor: clean up config and readme
1 parent 9885e8e commit 9122eaa

File tree

4 files changed

+61
-75
lines changed

4 files changed

+61
-75
lines changed

lua/cosmic-ui/code-action/init.lua

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- big shout out to telescope
22
-- https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/builtin/lsp.lua#L144
33
local Menu = require('nui.menu')
4-
local NuiText = require('nui.text')
4+
local Text = require('nui.text')
55
local event = require('nui.utils.autocmd').event
66
local utils = require('cosmic-ui.utils')
77
local M = {}
@@ -74,7 +74,7 @@ M.code_actions = function(opts)
7474
if response.result and not vim.tbl_isempty(response.result) then
7575
local client = vim.lsp.get_client_by_id(client_id)
7676

77-
table.insert(menu_items, Menu.separator(NuiText('(' .. client.name .. ')', 'Comment')))
77+
table.insert(menu_items, Menu.separator(Text('(' .. client.name .. ')', 'Comment')))
7878

7979
for _, result in pairs(response.result) do
8080
local command_title = result.title:gsub('\r\n', '\\r\\n'):gsub('\n', '\\n')
@@ -101,25 +101,23 @@ M.code_actions = function(opts)
101101
return
102102
end
103103

104-
local popup_opts = utils.merge({
104+
local user_border = _G.CosmicUI_user_opts.code_actions.border
105+
local popup_opts = {
105106
position = {
106107
row = 1,
107108
col = 0,
108109
},
109110
relative = 'cursor',
110111
border = {
111-
highlight = 'FloatBorder',
112-
style = _G.CosmicUI_user_opts.border,
112+
highlight = user_border.highlight,
113+
style = user_border.style or _G.CosmicUI_user_opts.border_style,
113114
text = {
114-
top = NuiText('Code Actions'),
115-
top_align = 'center',
115+
top = Text(user_border.title, user_border.title_hl),
116+
top_align = user_border.title_align,
116117
},
117118
padding = { 0, 1 },
118119
},
119-
win_options = {
120-
winhighlight = 'Normal:Normal',
121-
},
122-
}, _G.CosmicUI_user_opts.code_actions.popup_opts or {})
120+
}
123121

124122
local menu = Menu(popup_opts, {
125123
lines = menu_items,
@@ -136,7 +134,8 @@ M.code_actions = function(opts)
136134
},
137135
on_change = function(item, menu)
138136
local pos = utils.index_of(result_items, item)
139-
menu.border:set_text('bottom', '(' .. tostring(pos) .. '/' .. #result_items .. ')', 'right')
137+
local text = '(' .. tostring(pos) .. '/' .. #result_items .. ')'
138+
menu.border:set_text('bottom', Text(text, user_border.bottom_hl), 'right')
140139
end,
141140
on_submit = function(item)
142141
local action = item.ctx.command

lua/cosmic-ui/init.lua

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,36 @@ local M = {}
33

44
local default_border = 'single'
55
local default_user_opts = {
6-
border = default_border,
6+
border_style = default_border,
77
rename = {
8+
border = {
9+
highlight = 'FloatBorder',
10+
style = nil,
11+
title = 'Rename',
12+
title_align = 'left',
13+
title_hl = 'FloatBorder',
14+
},
815
prompt = '> ',
9-
popup_opts = {},
16+
prompt_hl = 'Comment',
1017
},
1118
code_actions = {
12-
popup_opts = {},
19+
min_width = nil,
20+
border = {
21+
bottom_hl = 'FloatBorder',
22+
highlight = 'FloatBorder',
23+
style = nil,
24+
title = 'Code Actions',
25+
title_align = 'center',
26+
title_hl = 'FloatBorder',
27+
},
1328
},
1429
}
1530

1631
_G.CosmicUI_user_opts = {}
1732

1833
M.setup = function(user_opts)
19-
-- get default opts with borders set from user config
20-
local default_opts = utils.set_border(user_opts.border or default_border, default_user_opts)
21-
2234
-- get parsed user opts
23-
_G.CosmicUI_user_opts = utils.merge(default_opts, user_opts or {})
35+
_G.CosmicUI_user_opts = utils.merge(default_user_opts, user_opts or {})
2436
user_opts = _G.CosmicUI_user_opts
2537
end
2638

lua/cosmic-ui/rename/init.lua

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
local lsp = vim.lsp
22
local utils = require('cosmic-ui.utils')
33
local rename_handler = require('cosmic-ui.rename.handler')
4+
local Text = require('nui.text')
45

56
local function rename(popup_opts, opts)
67
local Input = require('nui.input')
78
local event = require('nui.utils.autocmd').event
89
local curr_name = vim.fn.expand('<cword>')
910

11+
local user_border = _G.CosmicUI_user_opts.rename.border
12+
local width = 25
13+
if #curr_name > width then
14+
width = #curr_name
15+
end
16+
1017
popup_opts = utils.merge({
1118
position = {
1219
row = 1,
1320
col = 0,
1421
},
1522
size = {
16-
width = 25,
23+
width = width,
1724
height = 2,
1825
},
1926
relative = 'cursor',
2027
border = {
21-
highlight = 'FloatBorder',
22-
style = _G.CosmicUI_user_opts.border,
28+
highlight = user_border.highlight,
29+
style = user_border.style or _G.CosmicUI_user_opts.border_style,
2330
text = {
24-
top = ' Rename ',
25-
top_align = 'left',
31+
top = Text(user_border.title, user_border.title_hl),
32+
top_align = user_border.title_align,
2633
},
2734
},
28-
win_options = {
29-
winhighlight = 'Normal:Normal',
30-
},
31-
}, _G.CosmicUI_user_opts.rename.popup_opts or {}, popup_opts or {})
35+
}, popup_opts or {})
3236

3337
opts = utils.merge({
34-
prompt = _G.CosmicUI_user_opts.rename.prompt,
38+
prompt = Text(_G.CosmicUI_user_opts.rename.prompt, _G.CosmicUI_user_opts.rename.prompt_hl),
3539
default_value = curr_name,
3640
on_submit = function(new_name)
3741
if not (new_name and #new_name > 0) or new_name == curr_name then
@@ -48,10 +52,6 @@ local function rename(popup_opts, opts)
4852
-- mount/open the component
4953
input:mount()
5054

51-
-- las value is length of highlight
52-
vim.api.nvim_buf_add_highlight(input.bufnr, -1, 'LspRenamePrompt', 0, 0, #opts.prompt)
53-
vim.cmd('hi link LspRenamePrompt Comment')
54-
5555
utils.default_mappings(input)
5656

5757
-- unmount component when cursor leaves buffer

readme.md

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ Cosmic-UI is a simple wrapper around specific vim functionality. Built in order
3939
})
4040
```
4141

42-
<!-- This is because `Cosmic-UI` will initialize `lsp_signature.nvim`, which must be set up after LSP server in order to properly hook into the correct LSP handler. -->
43-
4442
## ⚙️ Configuration
4543

4644
You may override any of the settings below by passing a config object to `.setup`
@@ -49,53 +47,30 @@ You may override any of the settings below by passing a config object to `.setup
4947
{
5048
-- default border to use
5149
-- 'single', 'double', 'rounded', 'solid', 'shadow'
52-
border = 'rounded',
50+
border = 'single',
5351

5452
-- rename popup settings
5553
rename = {
56-
prompt = '> ',
57-
-- same as nui popup options
58-
popup_opts = {
59-
position = {
60-
row = 1,
61-
col = 0,
62-
},
63-
size = {
64-
width = 25,
65-
height = 2,
66-
},
67-
relative = 'cursor',
68-
border = {
69-
highlight = 'FloatBorder',
70-
style = _G.CosmicUI_user_opts.border,
71-
text = {
72-
top = ' Rename ',
73-
top_align = 'left',
74-
},
75-
},
76-
win_options = {
77-
winhighlight = 'Normal:Normal',
78-
},
54+
border = {
55+
highlight = 'FloatBorder',
56+
style = 'single',
57+
title = ' Rename ',
58+
title_align = 'left',
59+
title_hl = 'FloatBorder',
7960
},
61+
prompt = '> ',
62+
prompt_hl = 'Comment',
8063
},
8164

8265
code_actions = {
83-
min_width = {},
84-
-- same as nui popup options
85-
popup_opts = {
86-
position = {
87-
row = 1,
88-
col = 0,
89-
},
90-
relative = 'cursor',
91-
border = {
92-
highlight = 'FloatBorder',
93-
text = {
94-
top = 'Code Actions',
95-
top_align = 'center',
96-
},
97-
padding = { 0, 1 },
98-
},
66+
min_width = nil,
67+
border = {
68+
bottom_hl = 'FloatBorder',
69+
highlight = 'FloatBorder',
70+
style = 'single',
71+
title = 'Code Actions',
72+
title_align = 'center',
73+
title_hl = 'FloatBorder',
9974
},
10075
}
10176
}

0 commit comments

Comments
 (0)