@@ -12,6 +12,7 @@ local debugger_runner = lazy.require("flutter-tools.runners.debugger_runner") --
12
12
local path = lazy .require (" flutter-tools.utils.path" ) --- @module " flutter-tools.utils.path"
13
13
local dev_log = lazy .require (" flutter-tools.log" ) --- @module " flutter-tools.log"
14
14
local parser = lazy .require (" flutter-tools.utils.yaml_parser" )
15
+ local config_utils = lazy .require (" flutter-tools.utils.config_utils" ) --- @module " flutter-tools.utils.config_utils"
15
16
16
17
local M = {}
17
18
@@ -189,34 +190,6 @@ local function get_device_from_args(args)
189
190
end
190
191
end
191
192
192
- local function get_absolute_path (input_path )
193
- -- Check if the provided path is an absolute path
194
- if
195
- vim .fn .isdirectory (input_path ) == 1
196
- and not input_path :match (" ^/" )
197
- and not input_path :match (" ^%a:[/\\ ]" )
198
- then
199
- -- It's a relative path, so expand it to an absolute path
200
- local absolute_path = vim .fn .fnamemodify (input_path , " :p" )
201
- return absolute_path
202
- else
203
- -- It's already an absolute path
204
- return input_path
205
- end
206
- end
207
-
208
- --- @param project_conf flutter.ProjectConfig ?
209
- local function get_cwd (project_conf )
210
- if project_conf and project_conf .cwd then
211
- local resolved_path = get_absolute_path (project_conf .cwd )
212
- if not vim .loop .fs_stat (resolved_path ) then
213
- return ui .notify (" Provided cwd does not exist: " .. resolved_path , ui .ERROR )
214
- end
215
- return resolved_path
216
- end
217
- return lsp .get_lsp_root_dir ()
218
- end
219
-
220
193
-- @return table?
221
194
local function parse_yaml (str )
222
195
local ok , yaml = pcall (parser .parse , str )
@@ -276,7 +249,7 @@ local function run(opts, project_conf, launch_config)
276
249
project_conf .pre_run_callback (callback_args )
277
250
end
278
251
end
279
- local cwd = get_cwd (project_conf )
252
+ local cwd = config_utils . get_cwd (project_conf )
280
253
-- To determinate if the project is a flutter project we need to check if the pubspec.yaml
281
254
-- file has a flutter dependency in it. We need to get cwd first to pick correct pubspec.yaml file.
282
255
local is_flutter_project = has_flutter_dependency_in_pubspec (cwd )
@@ -333,7 +306,7 @@ local function attach(opts)
333
306
local args = opts .cli_args or opts .args or {}
334
307
if not use_debugger_runner () then table.insert (args , 1 , " attach" ) end
335
308
336
- local cwd = get_cwd ()
309
+ local cwd = config_utils . get_cwd ()
337
310
ui .notify (" Attaching flutter project..." )
338
311
runner = use_debugger_runner () and debugger_runner or job_runner
339
312
runner :attach (paths , args , cwd , on_run_data , on_run_exit )
@@ -446,7 +419,7 @@ function M.pub_get()
446
419
command = cmd ,
447
420
args = { " pub" , " get" },
448
421
-- stylua: ignore
449
- cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
422
+ cwd = lsp .get_project_root_dir () --[[ @as string]] ,
450
423
})
451
424
pub_get_job :after_success (vim .schedule_wrap (function (j )
452
425
on_pub_get (j :result ())
@@ -482,7 +455,7 @@ function M.pub_upgrade(cmd_args)
482
455
command = cmd ,
483
456
args = args ,
484
457
-- stylua: ignore
485
- cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
458
+ cwd = lsp .get_project_root_dir () --[[ @as string]] ,
486
459
})
487
460
pub_upgrade_job :after_success (vim .schedule_wrap (function (j )
488
461
ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
@@ -590,7 +563,7 @@ function M.install()
590
563
command = cmd ,
591
564
args = args ,
592
565
-- stylua: ignore
593
- cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
566
+ cwd = lsp .get_project_root_dir () --[[ @as string]] ,
594
567
})
595
568
install_job :after_success (vim .schedule_wrap (function (j )
596
569
ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
@@ -621,7 +594,7 @@ function M.uninstall()
621
594
command = cmd ,
622
595
args = args ,
623
596
-- stylua: ignore
624
- cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
597
+ cwd = lsp .get_project_root_dir () --[[ @as string]] ,
625
598
})
626
599
uninstall_job :after_success (vim .schedule_wrap (function (j )
627
600
ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
0 commit comments