diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index bd5814e..1e2eb08 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -54,9 +54,8 @@ local function set_current_device(device) end ---Resolve the device name from the `Launching ... on in mode` output line ----@param line string|nil +---@param line string local function update_device_from_output(line) - if not line then return end local name = line:match("^Launching .+ on (.+) in %w+ mode") if not name then return end local device = vim.tbl_extend("force", current_device or {}, { name = vim.trim(name) }) @@ -115,7 +114,9 @@ end ---Handle output from flutter run command ---@param is_err boolean if this is stdout or stderr +---@param data string? nil once the job's output stream closes local function on_run_data(is_err, data) + if not data then return end if is_err and config.dev_log.notify_errors then queue_error_notification(data) end update_device_from_output(data) dev_log.log(data) diff --git a/tests/commands_spec.lua b/tests/commands_spec.lua index ed261be..3685bf5 100644 --- a/tests/commands_spec.lua +++ b/tests/commands_spec.lua @@ -110,8 +110,19 @@ describe("commands", function() assert.is_nil(commands.current_device()) end) - it("should not crash when output line is nil", function() - assert.has_no.errors(function() commands.__update_device_from_output(nil) end) + it("should ignore the nil line sent when the run output closes", function() + local config = require("flutter-tools.config") + config.dev_log.notify_errors = true + config.dev_log.filter = function(line) return not line:match("^D/") end + + local ok, err = pcall(function() + commands.__on_run_data(false, nil) + commands.__on_run_data(true, nil) + end) + + config.dev_log.notify_errors = false + config.dev_log.filter = nil + assert.is_true(ok, err) end) it("should batch consecutive error lines into one notification", function()