razor
razor copied to clipboard
Intellisense in razor files can't be disabled and frequently gets in the way
This issue has been moved from a ticket on Developer Community.
tl;dr: If intellisense could be disabled in .razor files, I'd be happy.
Because intellisense can't be disabled in .razor files, it's extremely frustrating to use. Here's a great example:
It's literally impossible for me to just type "
I think if nothing else, intellisense suggestions should absolutely never be automatically completed by simply typing the actual text I was actually trying to input. I should at least have to hit the enter key or the tab key or something. But the current implementation is insanely frustrating.
Original Comments
Feedback Bot on 7/13/2022, 10:50 PM:
(private comment, text removed)
Original Solutions
(no solutions)
This is the exact same problem I tried to report here. https://developercommunity.visualstudio.com/t/Razor-Intellisense-Suggestions-Prefer-Co/10124751
Unfortunately the feedback system still shows this as needing more info, despite me attaching examples of this AWFUL experience.
I cannot believe that Intellisense can't provide sensible suggestions for HTML <td>, <thead>, <tr>, <th>
elements in 2022.
Thanks for the bump @phillipmunn. Is it okay by you if I close that report as a duplicate of this issue?
The underlying problem here is that the Html language server is not suggesting <th>
as a possible tag, because it knows that <th>
tags are not valid in that location - ie, not inside a <tr>
tag. With ASP.NET Core tag helpers it was possible to specify a TagOutputHint
on a tag helper that told the compiler and tooling what Html element a component was equivalent to, and that would inform completion etc. It seems there is no equivalent of this in Blazor.
So there are a couple of ways forward with this I can think of:
- Add support for TagOutputHint in Blazor.
- This could be something like allowing
@attribute [OutputElementHint("table")]
in your table component, or perhaps more usefully allow[OutputElementHint("tr")]
or[HtmlTargetElement(ParentTag = "tr")]
on theHeaderTemplate
property. - This would need a runtime issue created in https://github.com/dotnet/aspnetcore as we don't own the Razor language
- This could be something like allowing
- Disable the "smart" completion in Razor files, and just show all tags all the time
- I suspect this would have to be behind an optionm which means it would be blocked on https://github.com/dotnet/razor-tooling/issues/6212
- We could potentially just do this for
.razor
files, given that we know there is noOutputElementHint
support, but I personally think this would be a worse experience for the most part, as it would make completion quite noisy.
@davidwengier thanks for the explanation. Happy for you to link the report from developer community to this issue and close it.
So I think I understand now that basically intellisense is not clever enough today to realise that my RenderFragment already has the
That still leaves me and others with a frustrating experience in the meantime.
Can I ask though, has anyone considered when closing a tag ">", if intellisense could not first check if the element that it's trying to auto-complete is actually already a valid html element, regardless of it not being in the suggestion list, and then simply leaving it as is? If the user has explicitly typed something, I feel like there's a balance here that the user might know what they are doing and doesn't want it changed.
Taking that same example I have shown, when I type the ">" character, it will autocomplete "AuthorizeRouteView" which is not the thing that I want to insert. I then have to delete this which is a waste of time.
I guess a setting "If I happen to be completing an already recognised HTML tag regardless of any suggestions being shown, can it just not autocomplete things" is what I would want (or for this behaviour to become a default).
It's worth noting that Visual Studio has the ability to toggle the completion mode so that no matter what is being typed, completion won't get in the way unless you deliberately select an item and hit Enter. The default keyboard shortcut for it is Ctrl+Alt+Spacebar
, or it can be toggle via the Edit menu, under Intellisense:

Toggling this will let you type <th>
, or anything else, regardless of whether it appears in the completion list.
Another report here: https://developercommunity.visualstudio.com/t/In-NET6-Blazor-server-app-VS2022-intel/10419369