razor icon indicating copy to clipboard operation
razor copied to clipboard

Intellisense in razor files can't be disabled and frequently gets in the way

Open vsfeedback opened this issue 2 years ago • 3 comments

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:

image

It's literally impossible for me to just type "

foo" without the stupid intellisense popup appearing and providing a profoundly useless suggestion, and furthermore, forcing me to hit the escape key to get rid of it. I mean, I literally cannot simply type in the editor what I want as the intellisense suggestion overrides what I am typing -- even if I do absolutely nothing to confirm the ridiculous suggestion. Just type "" and the absurd suggestion it offers is completed instead.

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)

vsfeedback avatar Jul 21 '22 21:07 vsfeedback

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.

phillipmunn avatar Oct 06 '22 19:10 phillipmunn

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:

  1. 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 the HeaderTemplate property.
    • This would need a runtime issue created in https://github.com/dotnet/aspnetcore as we don't own the Razor language
  2. 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 no OutputElementHint support, but I personally think this would be a worse experience for the most part, as it would make completion quite noisy.

davidwengier avatar Oct 07 '22 05:10 davidwengier

@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

tag inside that component. When I therefore am working with that component in a different file and trying to provide content to the <HeaderTemplate> section, the Intellisense suggestions are not considering the tag and therefore is not a valid suggestion in the auto-complete list. To get that fixed requires some form of attribute hint to be added to the Razor language and then to decorate components with it. That feels like a lot of work for both you and component providers.

That still leaves me and others with a frustrating experience in the meantime.

image

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).

phillipmunn avatar Oct 07 '22 11:10 phillipmunn

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:

image

Toggling this will let you type <th>, or anything else, regardless of whether it appears in the completion list.

davidwengier avatar Nov 04 '22 04:11 davidwengier

Another report here: https://developercommunity.visualstudio.com/t/In-NET6-Blazor-server-app-VS2022-intel/10419369

davidwengier avatar Jul 20 '23 21:07 davidwengier