@@ -13,7 +13,8 @@ local function apply_action(action, client, ctx)
13
13
enriched_ctx .client_id = client .id
14
14
fn (command , ctx )
15
15
else
16
- M .execute_command (command )
16
+ local opts = require (" rust-tools" ).config .options .tools
17
+ opts .executor .execute_command (command )
17
18
end
18
19
end
19
20
end
@@ -60,9 +61,71 @@ local function on_user_choice(action, ctx)
60
61
end
61
62
end
62
63
63
- local select_code_action_results = function (results , ctx )
64
+ function M .telescope_select (picker_opts , sorter_opts )
65
+ picker_opts = picker_opts or require (" telescope.themes" ).get_cursor () -- get_dropdown
66
+ local conf = require (" telescope.config" ).values
67
+
68
+ return function (items , opts , on_choice )
69
+ opts = opts or {}
70
+ local prompt_title = opts .prompt or " Rust Code Actions"
71
+
72
+ require (" telescope.pickers" )
73
+ .new (picker_opts , {
74
+ prompt_title = prompt_title ,
75
+ finder = require (" telescope.finders" ).new_table ({
76
+ results = items , -- TODO:
77
+ entry_maker = function (entry )
78
+ local str = entry .title
79
+
80
+ return {
81
+ value = entry ,
82
+ display = str ,
83
+ ordinal = str ,
84
+ }
85
+ end ,
86
+ }),
87
+ sorter = conf .generic_sorter (sorter_opts ),
88
+ previewer = require (" telescope.previewers" ).new_buffer_previewer ({
89
+ define_preview = function (self , entry , status )
90
+ local bufnr = self .state .bufnr
91
+ local item = entry .value
92
+ vim .api .nvim_buf_set_lines (
93
+ bufnr ,
94
+ 0 ,
95
+ - 1 ,
96
+ false ,
97
+ M .code_action_submenu (item )
98
+ )
99
+ end ,
100
+ }),
101
+ attach_mappings = function (prompt_bufnr , map )
102
+ require (" telescope.actions" ).select_default :replace (function ()
103
+ require (" telescope.actions" ).close (prompt_bufnr )
104
+ local selection =
105
+ require (" telescope.actions.state" ).get_selected_entry ()
106
+ on_choice (selection .value , selection .index )
107
+ end )
108
+ return true
109
+ end ,
110
+ })
111
+ :find ()
112
+ end
113
+ end
114
+
115
+ M .code_action_submenu = function (item )
116
+ if item .actions then
117
+ vim .tbl_map (function (action )
118
+ return " ▶" .. action .title
119
+ end , item .actions )
120
+ else
121
+ return {}
122
+ end
123
+ end
124
+
125
+ M .code_actions_results_to_nested_table = function (results )
64
126
if results .error then
65
127
vim .notify (results .error , vim .log .levels .ERROR )
128
+ return
66
129
end
67
130
68
131
local action_tuples = {}
@@ -96,28 +159,41 @@ local select_code_action_results = function(results, ctx)
96
159
end
97
160
end
98
161
99
- vim .ui .select (entries , {
162
+ return entries
163
+ end
164
+
165
+ local select_code_action_results = function (results , ctx )
166
+ local entries = M .code_actions_results_to_nested_table (results )
167
+ if entries == nil then
168
+ return
169
+ end
170
+ local opts = require (" rust-tools" ).config .options .tools
171
+ local select = opts .code_action_group .selector
172
+
173
+ select (entries , {
100
174
prompt = " Code Actions:" ,
101
175
format_item = function (item )
102
176
return item .title
103
177
end ,
178
+ preview_item = function (item )
179
+ return M .code_action_submenu (item )
180
+ end ,
104
181
}, function (selected )
105
182
if not selected then
106
183
return
107
184
end
108
185
109
186
if selected .actions then
110
187
vim .schedule (function ()
111
- vim . ui . select (selected .actions , {
112
- prompt = selected .title .. " : " ,
188
+ select (selected .actions , {
189
+ prompt = selected .title ,
113
190
format_item = function (item )
114
191
return item .title
115
192
end ,
116
193
}, function (selected_group )
117
194
if not selected_group then
118
195
return
119
196
end
120
- print (vim .inspect (selected_group ))
121
197
122
198
vim .schedule (function ()
123
199
on_user_choice (selected_group , ctx )
0 commit comments