File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed
Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 3131--- @param str string
3232function 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 ()
4445end
4546
4647--- @param str string
You can’t perform that action at this time.
0 commit comments