-
Notifications
You must be signed in to change notification settings - Fork 323
Pasting code with unknown color symbol prefixes it with colorScheme.
#4757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Well that is odd. I was expecting to not be able to reproduce this, but if I create a new file with: import 'package:flutter/material.dart';
var a = ElevatedButton.styleFrom(
backgroundColor: backgroundColor,
); And then press Save (which triggers fix-all-on-save), then I see the same thing: import 'package:flutter/material.dart';
var a = ElevatedButton.styleFrom(
backgroundColor: colorScheme.background,
); I think this might be coming from a Flutter fix - there are a few that seems to migrate to "colorScheme.background" (such as flutter/flutter#110162), but at a glance, they all seem to have filters that I would expect to stop them firing here. I'll try to narrow it down. |
Looks like it's coming from this: # Changes made in https://github.com/flutter/flutter/pull/110162
- title: "Migrate to 'ColorScheme.background'"
date: 2022-08-24
element:
uris: [ 'material.dart' ]
field: 'backgroundColor'
inClass: 'ThemeData'
changes:
- kind: 'rename'
newName: 'colorScheme.foo' @bwilkerson does this seem like a bug in the data driven fixes? The fix has |
The description makes it sounds like this is happening on 'paste', but I'm guessing that this is happening on 'save'. Even so, it's not clear to me that we want this kind of fix to run on save, given that the user might be mid-thought and have a different kind of fix in mind. That said, yes, it seems like this is a bug. We know that the |
I tried to replicate it right now to see if it was triggered on paste (as I vaguely remember it), or only on save (as @bwilkerson assumes). Right now I can't replicate this, for some reason, even though I have seen it happen several times. I hit save constantly (old Eclipse habit, since it saves a history marker in Eclipse every time you do that), so I may not have remembered that it was save and not paste that did it. |
As far as I know, we're not able to perform a code change like that on 'paste', hence my guess. But however it's happening I think its a bug that we're making the transformation in this case, and maybe that we're applying transformation at this time even if it were only performing correct transformations. |
This is correct - there is no paste event in VS Code (well, it's still a proposed API so we can't use it yet). Though you can have auto-save enabled, as well as fix-all-on-save, so you could still see fixes run "just after" pasting. When reproducing this, I saw the change and thought I had also not saved.. however I then couldn't reproduce it without saving, so also assume I must have done it out of habit.
Do you mean this fix specifically, or do you think all data-driven fixes should be excluded when fixes run on-save? If it's going to do things like this, I'd agree - but if this issue was fixed, I'm less sure. If the user has chosen to fix-all-on-save, any fixes that are excluded are a potential source of confusion ("running Fix All fixes this, but setting fix-all-on-save does not"). Are these kinds of fixes (when working correctly) likely to be (or potentially) disruptive? |
I was probably reacting more to the buggy behavior than to the behavior is ought to have once the bug is fixed. |
@bwilkerson got it, thanks! I'm not very familiar with this code, but it seems to go wrong here:
I'm not sure of the impact of this bug - if it's likely low and the fix is complex, I could also commit a test marked as failing for later. Btw, while looking at this I initially found this function which I think is unused (perhaps superseded by the |
The code in element matcher is there so that if we find code of the form I don't know whether the function is being used; I'd have to search for references to it. If it is unused, then it would be good to get rid of it. |
I will take a look. |
Fixes Dart-Code/Dart-Code#4757. Change-Id: Ifd160dbafa468db6a703209a6ee6ea1566da5223 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328742 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Keerti Parthasarathy <keertip@google.com>
I have landed a fix for this. Will be in the next release of the SDK. |
Great, thanks! Closing this as fixed by dart-lang/sdk@c452dfc. |
Thanks @keertip! |
Describe the bug
Select code like this:
Paste into another class, where the field
Color backgroundColor
is not present:The
onTap
andicon
fields are pasted as-is. However,backgroundColor
gets transformed intocolorScheme.background
.This is unexpected, and frankly weird...
It may have something to do with the special rendering of colors in Dart-Code, with a color swatch thumbnail.
Please complete the following information:
The text was updated successfully, but these errors were encountered: