@@ -12,6 +12,7 @@ local debugger_runner = lazy.require("flutter-tools.runners.debugger_runner") --
1212local path = lazy .require (" flutter-tools.utils.path" ) --- @module " flutter-tools.utils.path"
1313local dev_log = lazy .require (" flutter-tools.log" ) --- @module " flutter-tools.log"
1414local 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"
1516
1617local M = {}
1718
@@ -189,34 +190,6 @@ local function get_device_from_args(args)
189190 end
190191end
191192
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-
220193-- @return table?
221194local function parse_yaml (str )
222195 local ok , yaml = pcall (parser .parse , str )
@@ -276,7 +249,7 @@ local function run(opts, project_conf, launch_config)
276249 project_conf .pre_run_callback (callback_args )
277250 end
278251 end
279- local cwd = get_cwd (project_conf )
252+ local cwd = config_utils . get_cwd (project_conf )
280253 -- To determinate if the project is a flutter project we need to check if the pubspec.yaml
281254 -- file has a flutter dependency in it. We need to get cwd first to pick correct pubspec.yaml file.
282255 local is_flutter_project = has_flutter_dependency_in_pubspec (cwd )
@@ -333,7 +306,7 @@ local function attach(opts)
333306 local args = opts .cli_args or opts .args or {}
334307 if not use_debugger_runner () then table.insert (args , 1 , " attach" ) end
335308
336- local cwd = get_cwd ()
309+ local cwd = config_utils . get_cwd ()
337310 ui .notify (" Attaching flutter project..." )
338311 runner = use_debugger_runner () and debugger_runner or job_runner
339312 runner :attach (paths , args , cwd , on_run_data , on_run_exit )
@@ -446,7 +419,7 @@ function M.pub_get()
446419 command = cmd ,
447420 args = { " pub" , " get" },
448421 -- stylua: ignore
449- cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
422+ cwd = lsp .get_project_root_dir () --[[ @as string]] ,
450423 })
451424 pub_get_job :after_success (vim .schedule_wrap (function (j )
452425 on_pub_get (j :result ())
@@ -482,7 +455,7 @@ function M.pub_upgrade(cmd_args)
482455 command = cmd ,
483456 args = args ,
484457 -- stylua: ignore
485- cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
458+ cwd = lsp .get_project_root_dir () --[[ @as string]] ,
486459 })
487460 pub_upgrade_job :after_success (vim .schedule_wrap (function (j )
488461 ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
@@ -590,7 +563,7 @@ function M.install()
590563 command = cmd ,
591564 args = args ,
592565 -- stylua: ignore
593- cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
566+ cwd = lsp .get_project_root_dir () --[[ @as string]] ,
594567 })
595568 install_job :after_success (vim .schedule_wrap (function (j )
596569 ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
@@ -621,7 +594,7 @@ function M.uninstall()
621594 command = cmd ,
622595 args = args ,
623596 -- stylua: ignore
624- cwd = lsp .get_lsp_root_dir () --[[ @as string]] ,
597+ cwd = lsp .get_project_root_dir () --[[ @as string]] ,
625598 })
626599 uninstall_job :after_success (vim .schedule_wrap (function (j )
627600 ui .notify (utils .join (j :result ()), nil , { timeout = notify_timeout })
0 commit comments