Dart-Code: Document edits may be sent to analysis server in incorrect order, causing unexpected analysis errors
VS Code started giving nonsensical error messages out of the blue. They happen throughout the whole codebase, here is an example code:
group('NoteColor', () {
test(
'should be validated with colorFullOpacity',
() async {
// act
NoteColor(Color(0xffffffff));
// assert
verify(validators.colorFullOpacity(any));
},
);
});
And the analyzer doesn’t see group
but rather oup
:
I’d say it has nothing to do with the actual Dart Analyzer because running flutter analyze
didn’t find any issues.
These kinds of weird errors go away after closing and reopening the file in question.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 18 (11 by maintainers)
After analyzing my installed extensions, Laravel Blade Spacer seems to be the culprit. Their GitHub repository shows a recent refactor (2 days ago), which correlates with the issue reports. @ResoDev could you confirm (as your gist also lists named extension)?
Ah, interesting. That extension seems like it may be reversing document edits here:
https://github.com/austenc/vscode-blade-spacer/blob/ae88ae1e82719c7b9fc088b93903285ac61b283a/src/extension.ts#L35
I’m not totally sure how that would cause this (it does mutate the array in-place, but I wouldn’t expect VS Code to be re-using that array, since it’d be serialised between the UI/extension host). It may be overwriting the edits, but I couldn’t find that from the code.
It still seems like a bug here - re-ordering the edits as far as VS Code is concerned should not matter (so whatever that extension is doing is not incorrect), but us assuming they’re in the “right” (reverse) order when sending them to the Dart analysis server is incorrect.