@@ -18,26 +18,83 @@ function M.show()
1818 local pickers = require " telescope.pickers"
1919 local finders = require " telescope.finders"
2020 local utils = require (" compiler.utils" )
21+ local utils_bau = require (" compiler.utils-bau" )
2122
2223 local buffer = vim .api .nvim_get_current_buf ()
23- local filetype = vim .api .nvim_buf_get_option (buffer , " filetype" )
24+ local filetype = vim .api .nvim_get_option_value (" filetype" , { buf = buffer })
25+
26+
27+ -- POPULATE
28+ -- ========================================================================
2429
2530 -- Programatically require the backend for the current language.
26- -- On unsupported languages, allow "Run Makefile".
2731 local language = utils .require_language (filetype )
28- if not language then language = require (" compiler.languages.make" ) end
2932
30- --- On option selected → Run action depending of the language
33+ -- On unsupported languages, default to make.
34+ if not language then language = utils .require_language (" make" ) or {} end
35+
36+ -- Also show options discovered on Makefile, Cmake... and other bau.
37+ if not language .bau_added then
38+ language .bau_added = true
39+ local bau_opts = utils_bau .get_bau_opts ()
40+
41+ -- Insert a separator on telescope for every bau.
42+ local last_bau_value = nil
43+ for _ , item in ipairs (bau_opts ) do
44+ if last_bau_value ~= item .bau then
45+ table.insert (language .options , { text = " " , value = " separator" })
46+ last_bau_value = item .bau
47+ end
48+ table.insert (language .options , item )
49+ end
50+ end
51+
52+ -- Add numbers in front of the options to display.
53+ local index_counter = 0
54+ for _ , option in ipairs (language .options ) do
55+ if option .value ~= " separator" then
56+ index_counter = index_counter + 1
57+ option .text = index_counter .. " - " .. option .text
58+ end
59+ end
60+
61+
62+ -- RUN ACTION ON SELECTED
63+ -- ========================================================================
64+
65+ --- On option selected → Run action depending of the language.
3166 local function on_option_selected (prompt_bufnr )
3267 actions .close (prompt_bufnr ) -- Close Telescope on selection
3368 local selection = state .get_selected_entry ()
3469 if selection .value == " " then return end -- Ignore separators
3570 _G .compiler_redo = selection .value -- Save redo
3671 _G .compiler_redo_filetype = filetype -- Save redo
37- if selection then language .action (selection .value ) end
72+
73+
74+ if selection then
75+ -- Do the selected option belong to a build automation utility?
76+ local bau = nil
77+ for _ , value in ipairs (language .options ) do
78+ if value .text == selection .display then
79+ bau = value .bau
80+ end
81+ end
82+
83+ -- If any → call the bau backend.
84+ -- If nil → call the language backend.
85+ if bau then
86+ bau = utils_bau .require_bau (bau )
87+ if bau then bau .action (selection .value ) end
88+ else
89+ language .action (selection .value )
90+ end
91+
92+ end
3893 end
3994
40- --- Show telescope
95+
96+ -- SHOW TELESCOPE
97+ -- ========================================================================
4198 local function open_telescope ()
4299 pickers
43100 .new ({}, {
0 commit comments