Skip to content
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
5 changes: 3 additions & 2 deletions lua/flutter-tools/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ local function set_current_device(device)
end

---Resolve the device name from the `Launching ... on <device> in <mode> 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) })
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions tests/commands_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading