Skip to content

Commit 99ae41b

Browse files
authored
fix: Add configuration for customizing struct receiver (#3)
1 parent d25f95b commit 99ae41b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lua/go-impl/cmd.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function M.open()
1919

2020
-- Receiver
2121
local current_struct_name = helper.get_struct_at_cursor()
22-
local default_value = current_struct_name and helper.predict_abbreviation(current_struct_name) or ""
22+
local default_value = current_struct_name and config.options.receiver.predict_abbreviation(current_struct_name)
23+
or ""
2324
ui.get_receiver(default_value, function(recevier)
2425
coroutine.resume(co, recevier)
2526
end)

lua/go-impl/config.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ M.options = {
77
---@usage "snacks" - Use folke/snacks picker
88
---@usage "fzf_lua" - Use ibhagwan/fzf-lua
99
picker = nil,
10+
receiver = {
11+
---Predict the abbreviation for the current struct
12+
---@param struct_name? string The Go struct name
13+
---@return string abbreviation The predicted abbreviation
14+
predict_abbreviation = function(struct_name)
15+
if not struct_name then
16+
return ""
17+
end
18+
19+
local abbreviation = ""
20+
abbreviation = abbreviation .. string.sub(struct_name, 1, 1)
21+
for i = 2, #struct_name do
22+
local char = string.sub(struct_name, i, i)
23+
if char == string.upper(char) and char ~= string.lower(char) then
24+
abbreviation = abbreviation .. char
25+
end
26+
end
27+
return string.lower(abbreviation) .. " *" .. struct_name
28+
end,
29+
},
1030
insert = {
1131
---@type "after"|"before"|"end"
1232
---@usage "after" - insert after the receiver's struct declaration

0 commit comments

Comments
 (0)