70 lines
1.6 KiB
Lua
70 lines
1.6 KiB
Lua
local build = {}
|
|
|
|
function build.dir(opts)
|
|
print(vim.inspect(opts))
|
|
local num_fargs = table.maxn(opts.fargs)
|
|
local dir = nil
|
|
|
|
if num_fargs == 0 then -- Find build directories
|
|
local dirs = build.list_dirs()
|
|
local num_dirs = table.maxn(dirs)
|
|
|
|
if num_dirs == 0 then
|
|
vim.cmd.echoerr('no build directories found')
|
|
elseif num_dirs == 1 then
|
|
-- One build directory found, use it
|
|
dir = dirs[1]
|
|
else
|
|
-- Multiple build directories found, select one
|
|
require("telescope.pickers.multi") {
|
|
prompt_title = "Select from the list",
|
|
results_title = "Options",
|
|
sorting_strategy = "ascending",
|
|
layout_strategy = "vertical",
|
|
winblend = 10,
|
|
border = true,
|
|
previewer = false, -- Set to true if you want a preview window
|
|
results = dir,
|
|
}
|
|
end
|
|
|
|
end
|
|
|
|
if not dir then
|
|
return
|
|
end
|
|
|
|
-- TODO: Set build directory
|
|
-- TODO: Post-process compile_commands.json with compdb
|
|
end
|
|
|
|
function build.run(opts)
|
|
print(vim.inspect(opts))
|
|
end
|
|
|
|
function build.list_dirs()
|
|
local dirs = vim.fn.globpath('.', 'build*')
|
|
dirs = vim.fn.substitute(dirs, '\\.\\/', '', 'g')
|
|
return vim.fn.split(dirs)
|
|
end
|
|
|
|
function build.list_targets()
|
|
return {}
|
|
end
|
|
|
|
function build.create_commands()
|
|
local buffer = vim.api.nvim_get_current_buf()
|
|
|
|
-- Create :BuildDir command
|
|
vim.api.nvim_buf_create_user_command(buffer, 'BuildDir', build.dir, {
|
|
bang = true, nargs = '?', complete = build.list_dirs,
|
|
})
|
|
|
|
-- Create :Build command
|
|
vim.api.nvim_buf_create_user_command(buffer, 'Build', build.run, {
|
|
bang = true, nargs = '*', complete = build.list_targets,
|
|
})
|
|
end
|
|
|
|
return build
|