1
1
local lazy = require (" flutter-tools.lazy" )
2
- local Job = require (" plenary.job" )
2
+ local Job = require (" plenary.job" ) --- @module " plenary.job "
3
3
local ui = lazy .require (" flutter-tools.ui" ) --- @module " flutter-tools.ui"
4
4
local utils = lazy .require (" flutter-tools.utils" ) --- @module " flutter-tools.utils"
5
5
local devices = lazy .require (" flutter-tools.devices" ) --- @module " flutter-tools.devices"
@@ -133,10 +133,13 @@ local function get_run_args(opts, conf)
133
133
local target = conf and conf .target
134
134
local dart_defines = conf and conf .dart_define
135
135
local dart_define_from_file = conf and conf .dart_define_from_file
136
+ local flutter_mode = conf and conf .flutter_mode
137
+ local web_port = conf and conf .web_port
136
138
local dev_url = dev_tools .get_url ()
137
139
138
140
if not use_debugger_runner () then vim .list_extend (args , { " run" }) end
139
141
if not cmd_args and device then vim .list_extend (args , { " -d" , device }) end
142
+ if web_port then vim .list_extend (args , { " --web-port" , web_port }) end
140
143
if cmd_args then vim .list_extend (args , cmd_args ) end
141
144
if flavor then vim .list_extend (args , { " --flavor" , flavor }) end
142
145
if target then vim .list_extend (args , { " --target" , target }) end
@@ -148,16 +151,33 @@ local function get_run_args(opts, conf)
148
151
vim .list_extend (args , { " --dart-define" , (" %s=%s" ):format (key , value ) })
149
152
end
150
153
end
154
+ if flutter_mode then
155
+ if flutter_mode == " profile" then
156
+ vim .list_extend (args , { " --profile" })
157
+ elseif flutter_mode == " release" then
158
+ vim .list_extend (args , { " --release" })
159
+ end -- else default to debug
160
+ end
151
161
if dev_url then vim .list_extend (args , { " --devtools-server-address" , dev_url }) end
152
162
return args
153
163
end
154
164
165
+ --- @param args string[]
166
+ --- @return Device ?
167
+ local function get_device_from_args (args )
168
+ for i = 1 , # args - 1 do
169
+ if args [i ] == " -d" then return { id = args [i + 1 ] } end
170
+ end
171
+ end
172
+
155
173
--- @param opts RunOpts
156
174
--- @param project_conf flutter.ProjectConfig ?
157
175
local function run (opts , project_conf )
158
176
opts = opts or {}
159
177
executable .get (function (paths )
160
178
local args = opts .cli_args or get_run_args (opts , project_conf )
179
+
180
+ current_device = opts .device or get_device_from_args (args )
161
181
ui .notify (" Starting flutter project..." )
162
182
runner = use_debugger_runner () and debugger_runner or job_runner
163
183
runner :run (paths , args , lsp .get_lsp_root_dir (), on_run_data , on_run_exit )
206
226
--- @param quiet boolean ?
207
227
function M .visual_debug (quiet ) send (" visual_debug" , quiet ) end
208
228
229
+ --- @param quiet boolean ?
230
+ function M .performance_overlay (quiet ) send (" performance_overlay" , quiet ) end
231
+
232
+ --- @param quiet boolean ?
233
+ function M .repaint_rainbow (quiet ) send (" repaint_rainbow" , quiet ) end
234
+
235
+ --- @param quiet boolean ?
236
+ function M .slow_animations (quiet ) send (" slow_animations" , quiet ) end
237
+
209
238
--- @param quiet boolean ?
210
239
function M .detach (quiet ) send (" detach" , quiet ) end
211
240
@@ -379,6 +408,78 @@ function M.fvm_use(sdk_name)
379
408
end
380
409
end
381
410
411
+ --- @param args string[]
412
+ --- @param project_conf flutter.ProjectConfig ?
413
+ --- @return string[]
414
+ local function set_args_from_project_config (args , project_conf )
415
+ local flavor = project_conf and project_conf .flavor
416
+ local device = project_conf and project_conf .device
417
+ if flavor then vim .list_extend (args , { " --flavor" , flavor }) end
418
+ if device then vim .list_extend (args , { " -d" , device }) end
419
+ end
420
+
421
+ --- @type Job ?
422
+ local install_job = nil
423
+
424
+ function M .install ()
425
+ if not install_job then
426
+ select_project_config (function (project_conf )
427
+ local args = { " install" }
428
+ set_args_from_project_config (args , project_conf )
429
+ ui .notify (" Installing the app..." )
430
+ executable .flutter (function (cmd )
431
+ local notify_timeout = 10000
432
+ install_job = Job :new ({
433
+ command = cmd ,
434
+ args = args ,
435
+ -- stylua: ignore
436
+ cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
437
+ })
438
+ install_job :after_success (vim .schedule_wrap (function (j )
439
+ ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
440
+ install_job = nil
441
+ end ))
442
+ install_job :after_failure (vim .schedule_wrap (function (j )
443
+ ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
444
+ install_job = nil
445
+ end ))
446
+ install_job :start ()
447
+ end )
448
+ end )
449
+ end
450
+ end
451
+
452
+ --- @type Job ?
453
+ local uninstall_job = nil
454
+
455
+ function M .uninstall ()
456
+ if not uninstall_job then
457
+ select_project_config (function (project_conf )
458
+ local args = { " install" , " --uninstall-only" }
459
+ set_args_from_project_config (args , project_conf )
460
+ ui .notify (" Uninstalling the app..." )
461
+ executable .flutter (function (cmd )
462
+ local notify_timeout = 10000
463
+ uninstall_job = Job :new ({
464
+ command = cmd ,
465
+ args = args ,
466
+ -- stylua: ignore
467
+ cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
468
+ })
469
+ uninstall_job :after_success (vim .schedule_wrap (function (j )
470
+ ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
471
+ uninstall_job = nil
472
+ end ))
473
+ uninstall_job :after_failure (vim .schedule_wrap (function (j )
474
+ ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
475
+ uninstall_job = nil
476
+ end ))
477
+ uninstall_job :start ()
478
+ end )
479
+ end )
480
+ end
481
+ end
482
+
382
483
if __TEST then
383
484
M .__run = run
384
485
M .__get_run_args = get_run_args
0 commit comments