Skip to content

fix: fixes error when no flutter binary was present and notifies user that we could not find the executable #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lua/flutter-tools/executable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
---@return table<string, string>?
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")),
Expand All @@ -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<string, string>?)
---@param callback fun(t?: table<string, string>?)
---@return table<string, string>?
local function path_from_lookup_cmd(lookup_cmd, callback)
local paths = {}
Expand Down Expand Up @@ -110,7 +111,7 @@ local function _flutter_bin_from_fvm()
end

---Fetch the paths to the users binaries.
---@param callback fun(paths: table<string, string>)
---@param callback fun(paths?: table<string, string>)
---@return nil
function M.get(callback)
if _paths then return callback(_paths) end
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lua/flutter-tools/lsp/init.lua
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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)
Expand Down
Loading