diff --git a/lua/flutter-tools/executable.lua b/lua/flutter-tools/executable.lua index 854cca1..8700c07 100644 --- a/lua/flutter-tools/executable.lua +++ b/lua/flutter-tools/executable.lua @@ -49,9 +49,10 @@ local function _flutter_sdk_dart_bin(flutter_sdk) end ---Get paths for flutter and dart based on the binary locations ----@return table +---@return table? local function get_default_binaries() local flutter_bin = fn.resolve(fn.exepath("flutter")) + if #flutter_bin <= 0 then return nil end return { flutter_bin = flutter_bin, dart_bin = fn.resolve(fn.exepath("dart")), @@ -66,7 +67,7 @@ function M.reset_paths() _paths = nil end ---Execute user's lookup command and pass it to the job callback ---@param lookup_cmd string ----@param callback fun(p: string, t: table?) +---@param callback fun(t?: table?) ---@return table? local function path_from_lookup_cmd(lookup_cmd, callback) local paths = {} @@ -110,7 +111,7 @@ local function _flutter_bin_from_fvm() end ---Fetch the paths to the users binaries. ----@param callback fun(paths: table) +---@param callback fun(paths?: table) ---@return nil function M.get(callback) if _paths then return callback(_paths) end @@ -138,14 +139,17 @@ function M.get(callback) if config.flutter_lookup_cmd then return path_from_lookup_cmd(config.flutter_lookup_cmd, function(paths) + if not paths then return end _paths = paths _paths.dart_sdk = _dart_sdk_root(_paths) callback(_paths) end) end - if not _paths then - _paths = get_default_binaries() + local default_paths = get_default_binaries() + + if not _paths and default_paths then + _paths = default_paths _paths.dart_sdk = _dart_sdk_root(_paths) if _paths.flutter_sdk then _paths.dart_bin = _flutter_sdk_dart_bin(_paths.flutter_sdk) end end diff --git a/lua/flutter-tools/lsp/init.lua b/lua/flutter-tools/lsp/init.lua index 9a1e894..f3a794b 100644 --- a/lua/flutter-tools/lsp/init.lua +++ b/lua/flutter-tools/lsp/init.lua @@ -1,6 +1,7 @@ local lazy = require("flutter-tools.lazy") local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.utils" local path = lazy.require("flutter-tools.utils.path") ---@module "flutter-tools.utils.path" +local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui" local color = lazy.require("flutter-tools.lsp.color") ---@module "flutter-tools.lsp.color" local lsp_utils = lazy.require("flutter-tools.lsp.utils") ---@module "flutter-tools.lsp.utils" @@ -216,6 +217,14 @@ local function get_server_config(user_config, callback) local executable = require("flutter-tools.executable") --- TODO: if a user specifies a command we do not need to call executable.get executable.get(function(paths) + if not paths then + ui.notify( + "Flutter executable could not be found, please make sure that flutter_path is given" + .. " or flutter_lookup_cmd is given or fvm is setup or that the flutter binary is " + .. "in your path" + ) + return + end local defaults = get_defaults({ flutter_sdk = paths.flutter_sdk }) local root_path = paths.dart_sdk local debug_log = create_debug_log(user_config.debug)