Skip to content

Commit 8a761c6

Browse files
authored
fix: fixes error when no flutter binary was present and notifies user that we could not find the executable (#480)
1 parent 0fcb08a commit 8a761c6

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lua/flutter-tools/executable.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ local function _flutter_sdk_dart_bin(flutter_sdk)
4949
end
5050

5151
---Get paths for flutter and dart based on the binary locations
52-
---@return table<string, string>
52+
---@return table<string, string>?
5353
local function get_default_binaries()
5454
local flutter_bin = fn.resolve(fn.exepath("flutter"))
55+
if #flutter_bin <= 0 then return nil end
5556
return {
5657
flutter_bin = flutter_bin,
5758
dart_bin = fn.resolve(fn.exepath("dart")),
@@ -66,7 +67,7 @@ function M.reset_paths() _paths = nil end
6667

6768
---Execute user's lookup command and pass it to the job callback
6869
---@param lookup_cmd string
69-
---@param callback fun(p: string, t: table<string, string>?)
70+
---@param callback fun(t?: table<string, string>?)
7071
---@return table<string, string>?
7172
local function path_from_lookup_cmd(lookup_cmd, callback)
7273
local paths = {}
@@ -110,7 +111,7 @@ local function _flutter_bin_from_fvm()
110111
end
111112

112113
---Fetch the paths to the users binaries.
113-
---@param callback fun(paths: table<string, string>)
114+
---@param callback fun(paths?: table<string, string>)
114115
---@return nil
115116
function M.get(callback)
116117
if _paths then return callback(_paths) end
@@ -138,14 +139,17 @@ function M.get(callback)
138139

139140
if config.flutter_lookup_cmd then
140141
return path_from_lookup_cmd(config.flutter_lookup_cmd, function(paths)
142+
if not paths then return end
141143
_paths = paths
142144
_paths.dart_sdk = _dart_sdk_root(_paths)
143145
callback(_paths)
144146
end)
145147
end
146148

147-
if not _paths then
148-
_paths = get_default_binaries()
149+
local default_paths = get_default_binaries()
150+
151+
if not _paths and default_paths then
152+
_paths = default_paths
149153
_paths.dart_sdk = _dart_sdk_root(_paths)
150154
if _paths.flutter_sdk then _paths.dart_bin = _flutter_sdk_dart_bin(_paths.flutter_sdk) end
151155
end

lua/flutter-tools/lsp/init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local lazy = require("flutter-tools.lazy")
22
local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.utils"
33
local path = lazy.require("flutter-tools.utils.path") ---@module "flutter-tools.utils.path"
4+
local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui"
45
local color = lazy.require("flutter-tools.lsp.color") ---@module "flutter-tools.lsp.color"
56
local lsp_utils = lazy.require("flutter-tools.lsp.utils") ---@module "flutter-tools.lsp.utils"
67

@@ -216,6 +217,14 @@ local function get_server_config(user_config, callback)
216217
local executable = require("flutter-tools.executable")
217218
--- TODO: if a user specifies a command we do not need to call executable.get
218219
executable.get(function(paths)
220+
if not paths then
221+
ui.notify(
222+
"Flutter executable could not be found, please make sure that flutter_path is given"
223+
.. " or flutter_lookup_cmd is given or fvm is setup or that the flutter binary is "
224+
.. "in your path"
225+
)
226+
return
227+
end
219228
local defaults = get_defaults({ flutter_sdk = paths.flutter_sdk })
220229
local root_path = paths.dart_sdk
221230
local debug_log = create_debug_log(user_config.debug)

0 commit comments

Comments
 (0)