Skip to content
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

string keyword is added by IntelliSense in error when specifying HtmlAttributes for LabelFor HTML Helper #63558

Open
vsfeedback opened this issue Aug 24, 2022 · 6 comments
Assignees
Milestone

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


Whenever I add a LabelFor HTML Helper to a Razor view and hit the comma after the first parameter and then begin typing to add the htmlAttributes parameter, after I type the new keyword and then the opening brace, IntelliSense - every single time - inserts the string keyword before the curly brace. This is never the correct behaviour - htmlAttributes will always be an object.

The problem is best illustrated by the little screen capture I've attached, but the result is that, thanks to IntelliSense, I end up with the following, in which I never typed string:
@Html.LabelFor(model => model.FirstName, new string { })

This hasn't always been a problem. I feel like it's a bug that was introduced a few versions ago, but I can't say for sure when.


Original Comments

Feedback Bot on 8/4/2022, 00:10 PM:

(private comment, text removed)

Feedback Bot on 8/4/2022, 04:07 PM:

(private comment, text removed)

Andrew Hall 🤘 [MSFT] on 8/20/2022, 06:08 AM:

(private comment, text removed)


Original Solutions

(no solutions)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 24, 2022
@davidwengier
Copy link
Contributor

davidwengier commented Aug 24, 2022

User report says its a Razor file, but its with the legacy editor, which means C# projection buffers, which means Roslyn. Repros in a normal .cs file too. Essentially the user wants to use an object initializer anonymous type, but completion has preselected string after they typed new, and completing with { inserts string.

CompletionPreselection

@DoctorKrolic
Copy link
Contributor

@davidwengier Sorry for offtop, but what program did you use to create such gif with keybord pressed keys shown?

@davidwengier
Copy link
Contributor

I use ScreenToGif (https://www.screentogif.com/).

Since it's not obvious in the program how to add keystrokes, you can either:

  • add them manually after the fact by clicking the "Key Strokes" button on the "Image" toolbar
  • create an "Automated Task" in the Options screen, and add the "Key Strokes" task so that they're automatically added to every recording.

@philipstratford
Copy link

philipstratford commented Aug 24, 2022

User report says its a Razor file, but its with the legacy editor

I was the person that raised this originally on the Developer Community. I'm just curious - when you say this is the legacy editor, is that inevitable because I'm targeting .NET Framework? When our organisation (finally!) moves to .NET 6 will I automatically be using the non-legacy editor, or is that a change I need to make manually?

@davidwengier
Copy link
Contributor

davidwengier commented Aug 24, 2022

Yes, .NET Framework projects get the legacy editor, but the other target frameworks have been migrated over to the new editor, so everything should be automatic when you update your projects.

@arkalyanms arkalyanms added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 26, 2022
@arkalyanms arkalyanms added this to the 17.4 milestone Aug 26, 2022
@genlu
Copy link
Member

genlu commented Sep 7, 2022

It looks like the completion might be a bit too confident in making a default (hard) selection based on the inferred types? If so, one potential solution is to use soft-selection instead of hard-select if user hasn't typed anything in this context (i.e. object creation)

@genlu genlu modified the milestones: 17.4, 17.6 Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants