-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Assist: create field in struct definition #4563
Comments
Yup, we need this. cc @TimoFreiberg who implemented similar feature for functions. In general, I feel like this shouldn't really be an assist, but a quick-fix for a diagnostic about unreoslved reference. And we should probably have a separate |
Marking both medium and hard:
|
Sounds like a good plan 👍 I also think this needs some infrastructure. |
Yup, so assists and quick fixes are indeed similar things, but annoying different things. Both are code transformation. QuickFixes are responses for diagnostics. That is, on every change we compute the full set of errors, and than for some errors we produce quick fixes. QuickFixes also can make use of information collected when detecting errors (see, for example, downcasting here). Assists are just contextual helpers. They are not computed for the whole file, they are always computed at the specified cursor position. They also don't need to fix anything, they can just be potentially useful transformations. I guess, my original though was that QuickFixes are computed eagerly on change, while assists are computed lazily for cursor position. Now that I think about it, I wonder if it makes sense to compute fixes lazily as well? We can compute them like quick-fixes, but, instead of the current cursor position, we can stuff current diagnostics into the assist context. |
4851: Add quickfix to add a struct field r=TimoFreiberg a=TimoFreiberg Related to #4563 I created a quickfix for record literals first because the NoSuchField diagnostic was already there. To offer that quickfix for FieldExprs with unknown fields I'd need to add a new diagnostic (or create a `NoSuchField` diagnostic for those cases) I think it'd make sense to make this a snippet completion (to select the generated type), but this would require changing the `Analysis` API and I'd like some feedback before I touch that. Co-authored-by: Timo Freiberg <timo.freiberg@gmail.com>
Hey, I would like to claim this issue. I have it partly working. I don't know how to make the caret go to the line that was added so that the user can specify the type? 2024-03-04.19-12-16.mp4@rustbot claim |
You want to look into how r-a handles |
It'd be cool if rust-analyzer could jump to creating a new field when I reference a field which doesn't exist.
Before:
After:
It'd be cool if rust-analyzer could figure out the type rust expects
opt3
to be, and autocomplete that (selecting it after), but I think that's optional. That would be a completion like this:Before:
After:
My main experience using this has been with IntelliJ's Java support.
Before:
After:
Let me know if there's anything else I can do to support this feature request.
The text was updated successfully, but these errors were encountered: