Skip to content

Conversation

@obemu
Copy link
Contributor

@obemu obemu commented Nov 10, 2025

About

This PR implements a fix for #473.

Problem

The first time a user executes any command or sub-command of the flutter CLI tool, they are greeted with the Welcome to Flutter! banner and if their Flutter SDK is not up-to-date, or if it has been a while since the last time they executed any command, they are also greeted with the New Flutter Version banner. Both may be displayed at the same time.

These banners are always printed to STDOUT, if the conditions explained above are met, including running the Flutter debug adapter (flutter debug_adapter), which is executed when running the command FlutterRun. This interferes with nvim-daps ability to parse JsonRPC messages, which in turn causes the internal parser loop of nvim-dap to crash, resulting in this error:

.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:97: .../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:30: Content-Length not found in headers: 
┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘

  ╔════════════════════════════════════════════════════════════════════════════╗
  ║                 Welcome to Flutter! - https://flutter.dev                  ║
  ║                                                                            ║
  ║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
  ║ statistics and basic crash reports. This data is used to help improve      ║
  ║ Flutter tools over time.                                                   ║
  ║                                                                            ║
  ║ Flutter tool analytics are not sent on the very first run. To disable      ║
  ║ reporting, type 'flutter config --no-analytics'. To display the current    ║
  ║ setting, type 'flutter config'. If you opt out of analytics, an opt-out    ║
  ║ event will be sent, and then no further information will be sent by the    ║
  ║ Flutter tool.                                                              ║
  ║                                                                            ║
  ║ By downloading the Flutter SDK, you agree to the Google Terms of Service.  ║
  ║ The Google Privacy Policy describes how data is handled in this service.   ║
  ║                                                                            ║
  ║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and  ║
  ║ crash reports to Google.                                                   ║
  ║                                                                            ║
  ║ Read about data we send with crash reports:                                ║
  ║ https://flutter.dev/to/crash-reporting                                     ║
  ║                                                                            ║
  ║ See Google's privacy policy:                                               ║
  ║ https://policies.google.com/privacy                                        ║
  ║                                                                            ║
  ║ To disable animations in this tool, use                                    ║
  ║ 'flutter config --no-cli-animations'.                                      ║
  ╚════════════════════════════════════════════════════════════════════════════╝

Content-Length: 584
Content-Type: application/vscode-jsonrpc; charset=utf-8

stack traceback:
	[C]: in function 'parse_chunk'
	.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:97: in function <.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:85>
Error executing callback:
.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:97: cannot resume dead coroutine
stack traceback:
	[C]: in function 'parse_chunk'
	.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:97: in function <.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:85>
Error executing callback:
.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:97: cannot resume dead coroutine
stack traceback:
	[C]: in function 'parse_chunk'
	.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:97: in function <.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:85>
Error executing callback:
.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:97: cannot resume dead coroutine
stack traceback:
	[C]: in function 'parse_chunk'
	.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:97: in function <.../.local/share/nvim/plugged/nvim-dap/lua/dap/rpc.lua:85>

Fix

My Solution

As I can't modify the code of the nvim-dap plugin to ignore these banners, I needed to prevent them from showing up. This has been implemented with the banner.lua module. This new module exposes two public functions:

  • clear_startup_banners(...) and
  • reset_cache()

Executing clear_startup_banners(...) executes the flutter CLI tool in the background and detects any banners, after the command is done the API user receives table with flags set for each banner. This method is used in commands.lua, before the DebugRunner:run or JobRunner:run method gets executed, which allows this plugin to inform the user of a new Flutter SDK version and the Runner to execute without triggering any errors.

Another possible Solution

To create a custom script for each platform (Windows and Unix) that executes the flutter debug_adapter command and detects any banners. The scripts would then be used to register a debug adapter in nvim-dap, for example:

    ...
    dap.adapters.dart = {
      type = "executable",
      command = is_windows and custom_flutter_dap.bat or custom_flutter_dap.sh
      args = { },
    }
    ...

NOTE: I haven't tested this second solution, it is just something I thought of.

Testing

You can manually trigger the banners to be shown again by deleting certain files.

  • Delete $FLUTTER_SDK/bin/cache/flutter_version_check.stamp for the New Flutter Version banner.
  • Delete $HOME/.config/flutter/tool_state for the Welcome to Flutter banner.

This commit is basically a small code-cleanup for the `executable.lua`
module, but it mainly adds Lua Doc comments to some public functions.
Executing any `flutter` command (including `flutter debug_adapter` and
`flutter debug-adapter`) may cause the `New Flutter Version` or
`Welcome to Flutter` banner to be printed to STDOUT. This is problematic,
because it interferes with `nvim-dap`s ability to parse RPC calls (obviously,
because the banners are not formatted to look like a valid RPC call).
`nvim-dap` is unable to properly detect the `Content-Length` header of
the first RPC call (because of the banner/s) -> `error(...)` gets called
-> user receives an error when trying to run their project.

This commit intends to fix that, by detecting and clearing any banners,
before the debug adapter is started.
@obemu obemu force-pushed the feat-flutter_version_banner branch from e89fe88 to 6cc0cbb Compare November 18, 2025 08:12
@obemu
Copy link
Contributor Author

obemu commented Nov 18, 2025

@sidlatau How are we looking, do I need to change anything to get this merged?

@sidlatau
Copy link
Collaborator

Nice work, @obemu! Thank you for providing information how to trigger these banners, I tested it, works as expected.

@sidlatau sidlatau merged commit c7dfaa9 into nvim-flutter:main Nov 18, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants