Skip to content

Commit c46c568

Browse files
committed
feat: add filename_generator key in config to allow user to customize filename
1 parent eba4347 commit c46c568

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lua/assistant/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---@class Assistant.Config.Core
22
---@field process_budget integer
33
---@field port integer
4+
---@field filename_generator fun(str: string): string
45

56
---@class Assistant.Config.UI
67
---@field border string

lua/assistant/core/tcp.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ local function start_server()
139139
table.insert(sources, key)
140140
end
141141

142+
local generator = config.values.core.filename_generator or utils.to_snake_case
143+
142144
picker:pick(sources, { prompt = 'source' }, function(source)
143-
local testcase_class_snake = utils.to_snake_case(data.languages.java.taskClass)
145+
local testcase_class_snake = generator(data.languages.java.taskClass)
144146
local filepath = string.format('%s/.ast/%s.json', fs.find_root() or fs.make_root(), testcase_class_snake)
145147
fs.write(filepath, chunk)
146148

lua/assistant/utils.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ end
3131
---@param str string
3232
function utils.to_snake_case(str)
3333
return str
34-
:gsub('(%s)', '_')
35-
:gsub('(%u%l)', '_%1')
36-
:gsub('(%l)(%u)', '%1_%2')
37-
:gsub('^_', '')
3834
:gsub('^%s*(.-)%s*$', '%1')
39-
:gsub('%s+', '_')
35+
:gsub('[^%w%s_]', '')
36+
:gsub('(%u+)(%u%l)', '%1_%2')
4037
:gsub('(%l)(%u)', '%1_%2')
41-
:gsub('(%l)(%d)', '%1_%2')
42-
:gsub('(%d)(%l)', '%1_%2')
43-
:gsub('(%d)(%u)', '%1_%2')
38+
:gsub('(%d)(%a)', '%1_%2')
39+
:gsub('(%a)(%d)', '%1_%2')
40+
:gsub('%s+', '_')
41+
:gsub('_+', '_')
42+
:gsub('^_', '')
43+
:gsub('_$', '')
44+
:lower()
4445
end
4546

4647
---@param str string

0 commit comments

Comments
 (0)