Skip to content

Commit f898850

Browse files
JordanH-Apadmisidlatau
authored andcommitted
feat(config): add an optional pre_run_callback attribute to setup_project
Add args to callback Add callback args to pre run callback Update setup_project_documentation Update docs to include information about args in callback Update docs to be more accurate with what is exposed in callback
1 parent 0c05044 commit f898850

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ require('flutter-tools').setup_project({
314314
API_URL = 'https://dev.example.com/api',
315315
IS_DEV = true,
316316
},
317+
pre_run_callback = nil, -- optional callback to run before the configuration
318+
-- exposes a table containing name, target, flavor and device in the arguments
317319
dart_define_from_file = 'config.json' -- the path to a JSON configuration file
318320
},
319321
{

lua/flutter-tools/commands.lua

+15-4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ local function run(opts, project_conf)
179179

180180
current_device = opts.device or get_device_from_args(args)
181181
ui.notify("Starting flutter project...")
182+
if project_conf then
183+
if project_conf.pre_run_callback then
184+
local callback_args = {
185+
name = project_conf.name,
186+
target = project_conf.target,
187+
flavor = project_conf.flavor,
188+
device = project_conf.device,
189+
}
190+
project_conf.pre_run_callback(callback_args)
191+
end
192+
end
182193
runner = use_debugger_runner() and debugger_runner or job_runner
183194
runner:run(paths, args, lsp.get_lsp_root_dir(), on_run_data, on_run_exit)
184195
end)
@@ -432,8 +443,8 @@ function M.install()
432443
install_job = Job:new({
433444
command = cmd,
434445
args = args,
435-
-- stylua: ignore
436-
cwd = lsp.get_lsp_root_dir() --[[@as string]],
446+
-- stylua: ignore
447+
cwd = lsp.get_lsp_root_dir() --[[@as string]],
437448
})
438449
install_job:after_success(vim.schedule_wrap(function(j)
439450
ui.notify(utils.join(j:result()), nil, { timeout = notify_timeout })
@@ -463,8 +474,8 @@ function M.uninstall()
463474
uninstall_job = Job:new({
464475
command = cmd,
465476
args = args,
466-
-- stylua: ignore
467-
cwd = lsp.get_lsp_root_dir() --[[@as string]],
477+
-- stylua: ignore
478+
cwd = lsp.get_lsp_root_dir() --[[@as string]],
468479
})
469480
uninstall_job:after_success(vim.schedule_wrap(function(j)
470481
ui.notify(utils.join(j:result()), nil, { timeout = notify_timeout })

lua/flutter-tools/config.lua

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.util
66
---@class flutter.ProjectConfig
77
---@field name string?
88
---@field device string
9+
---@field pre_run_callback fun(opts: {string: string})
910
---@field flavor string
1011
---@field target string
1112
---@field dart_define {[string]: string}
@@ -62,6 +63,7 @@ M.debug_levels = {
6263
local config = {
6364
flutter_path = nil,
6465
flutter_lookup_cmd = get_default_lookup(),
66+
pre_run_callback = nil,
6567
root_patterns = { ".git", "pubspec.yaml" },
6668
fvm = false,
6769
widget_guides = {

0 commit comments

Comments
 (0)