Fix "new Flutter Version" error on FlutterRun #495
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
About
This PR implements a fix for #473.
Problem
The first time a user executes any command or sub-command of the
flutterCLI tool, they are greeted with theWelcome 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 theNew Flutter Versionbanner. 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 commandFlutterRun. This interferes withnvim-daps ability to parse JsonRPC messages, which in turn causes the internal parser loop ofnvim-dapto crash, resulting in this error:Fix
My Solution
As I can't modify the code of the
nvim-dapplugin to ignore these banners, I needed to prevent them from showing up. This has been implemented with thebanner.luamodule. This new module exposes two public functions:clear_startup_banners(...)andreset_cache()Executing
clear_startup_banners(...)executes theflutterCLI 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 incommands.lua, before theDebugRunner:runorJobRunner:runmethod gets executed, which allows this plugin to inform the user of a new Flutter SDK version and theRunnerto execute without triggering any errors.Another possible Solution
To create a custom script for each platform (Windows and Unix) that executes the
flutter debug_adaptercommand and detects any banners. The scripts would then be used to register a debug adapter innvim-dap, for example: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.
$FLUTTER_SDK/bin/cache/flutter_version_check.stampfor theNew Flutter Versionbanner.$HOME/.config/flutter/tool_statefor theWelcome to Flutterbanner.