@@ -17,7 +17,7 @@ local M = {}
1717--- @field qf_window_size ? integer
1818--- @field qf_window_pos ? string
1919--- @field skip_picker_for_single_result ? boolean
20- --- @field db_build_cmd_args ? table
20+ --- @field db_build_cmd ? table
2121--- @field statusline_indicator ? string | nil
2222--- @field project_rooter ? CsProjectRooterConfig
2323M .opts = {
@@ -27,7 +27,7 @@ M.opts = {
2727 qf_window_size = 5 ,
2828 qf_window_pos = " bottom" ,
2929 skip_picker_for_single_result = false ,
30- db_build_cmd_args = { " -bqkv" },
30+ db_build_cmd = { script = " default " , args = { " -bqkv" } },
3131 statusline_indicator = nil ,
3232 project_rooter = {
3333 enable = false ,
@@ -273,63 +273,6 @@ M.cstag = function(symbol)
273273 return RC .NO_RESULTS
274274end
275275
276- M .db_build_output = function (err , data )
277- if err then
278- print (" cscope: [build] err: " .. err )
279- end
280- if data then
281- print (" cscope: [build] out: " .. data )
282- end
283- end
284-
285- M .db_build = function ()
286- local stdout = vim .loop .new_pipe (false )
287- local stderr = vim .loop .new_pipe (false )
288- local db_build_cmd_args = vim .tbl_deep_extend (" force" , M .opts .db_build_cmd_args , {})
289- local cur_path = vim .fn .getcwd ()
290- local db_conn = db .primary_conn () -- TODO: extend support to all db conns
291- local db_file = db_conn .file
292- local db_root = utils .get_path_parent (db_file )
293-
294- if vim .g .cscope_maps_statusline_indicator then
295- log .warn (" db build is already in progress" )
296- return
297- end
298-
299- if M .opts .exec == " cscope" then
300- table.insert (db_build_cmd_args , " -f" )
301- table.insert (db_build_cmd_args , db_file )
302- end
303-
304- vim .cmd (" cd " .. db_root )
305-
306- local handle = nil
307- vim .g .cscope_maps_statusline_indicator = M .opts .statusline_indicator or M .opts .exec
308- handle = vim .loop .spawn (
309- M .opts .exec ,
310- {
311- args = db_build_cmd_args ,
312- stdio = { nil , stdout , stderr },
313- },
314- vim .schedule_wrap (function (code , _ ) -- on exit
315- stdout :read_stop ()
316- stderr :read_stop ()
317- stdout :close ()
318- stderr :close ()
319- handle :close ()
320- if code == 0 then
321- log .info (" database built successfully" )
322- else
323- log .warn (" database build failed" )
324- end
325- vim .g .cscope_maps_statusline_indicator = nil
326- vim .cmd (" cd " .. cur_path )
327- end )
328- )
329- vim .loop .read_start (stdout , M .db_build_output )
330- vim .loop .read_start (stderr , M .db_build_output )
331- end
332-
333276M .db_update = function (op , files )
334277 if op == " a" then
335278 for _ , f in ipairs (files ) do
@@ -402,7 +345,7 @@ M.run = function(args)
402345
403346 local op = args [2 ]:sub (1 , 1 )
404347 if op == " b" then
405- M . db_build ( )
348+ db . build ( M . opts )
406349 elseif op == " a" or op == " r" then
407350 -- collect all args
408351 local files = {}
@@ -574,6 +517,21 @@ M.setup = function(opts)
574517 end
575518 end
576519
520+ if vim .fn .executable (M .opts .db_build_cmd .script ) ~= 1 then
521+ log .warn (" db_build script is not found. Using default" )
522+ M .opts .db_build_cmd .script = " default"
523+ end
524+
525+ if M .opts .db_build_cmd_args then
526+ M .opts .db_build_cmd .args = M .opts .db_build_cmd_args
527+ log .warn (
528+ string.format (
529+ [[ db_build_cmd_args is deprecated. Use 'db_build_cmd = { args = %s }']] ,
530+ vim .inspect (M .opts .db_build_cmd_args )
531+ )
532+ )
533+ end
534+
577535 -- if project rooter is enabled,
578536 -- 1. get root of project and update primary conn
579537 -- 2. if change_cwd is enabled, change into it (?)
0 commit comments