Intellisense in VS 2022
Intellisense in VS 2022 works inconsistently with RazorSlices. I saw similar behaviour when I was playing with RazorBlade, and the developer made a few changes that cleared it all up. Basically, the .cshtml files default to "C# analyzer additional file" and intellisense isn't robust, eg. it sometimes works and sometimes doesn't, no rhyme or reason that I can see:
If I switch these to "Content" then intellisense works much more reliably, but this ends up adding an entry in the project file:
And then VS 2022 gets confused and I can't see the file properties until I manually unload and reload the project, and then sometimes it preserves the "Content" setting and sometimes it reverts back to analyzer file. If I try to reset an item again, it "removes" the item from the project multiple times:
Note that none of this affects the build, it's only intellisense. Not a huge issue, but thought it worth noting the developer experience in VS 2022 in case you use Rider or something else instead.
Thanks for the issue. Could you try changing this setting in VS to see if makes any difference?
Text Editor -> C# -> Advanced -> Source generator execution (requires restart): Automatic
@naasking when you say:
intellisense isn't robust, eg. it sometimes works and sometimes doesn't, no rhyme or reason that I can see:
Do you mean IntelliSense in the .cshtml files becames flakey? Or do you mean the proxy types generated by the Razor Slices source generator aren't reliably shown in IntelliSense in .cs or .cshtml files?
If you could provide a screenshot or screen recording of the issue you're seeing that'd be very helpful.
Do you mean IntelliSense in the .cshtml files becames flakey? Or do you mean the proxy types generated by the Razor Slices source generator aren't reliably shown in IntelliSense in .cs or .cshtml files?
I think I've experienced both, but this specific ticket was about the .cshtml intellisense. The syntax highlighting didn't look right when I opened a slice, and when I defined a model and started writing markup and accessing properties, the autocomplete menus didn't reliably popup showing the field/property selections, etc. Your suggestion to modify the editor seems to be better behaved so far but I will report back on any issues, as I've only had to make a few minor changes (it might have also been a VS issue, and I recently updated to the newest release).
On slight tangent, it would be nice if ALT+F10/hot reload could work to update the templates while the program is running. Not sure if this is in scope, but since slices just generate C# code it seems like it should be possible. I can open another ticket if there's interest.
On slight tangent, it would be nice if ALT+F10/hot reload could work to update the templates while the program is running. Not sure if this is in scope, but since slices just generate C# code it seems like it should be possible. I can open another ticket if there's interest.
Hot Reload should be working to update existing slices while the app is running. Can you log an issue with more detail of what you're expecting, doing, and seeing? Be sure to look at the Hot Reload logs in the output window.
The issue happened again, where a new slice that I added created a new ItemGroup entry in the project file that "removed" the file. The other file properties are the same as other slices ("C# analyzer additional file"). This "removed" entry disables intellisense, and worse, the slice builds even though the slice references properties that are not in the model, which results in a runtime type initialization exception when Slice.Create() is called.
Fortunately, I realized that this behaviour happens every time I copy-paste an existing, working slice in the VS 2022 Solution Explorer view, so it should be easy for you to replicate.
Hot reload works great now by the way, thanks!
Fortunately, I realized that this behaviour happens every time I copy-paste an existing, working slice in the VS 2022 Solution Explorer view, so it should be easy for you to replicate.
Thanks for the repro info. I very much suspect this is an issue in VS rather than something in my source generator as I shouldn't even be able to effect the project from my code, I'm just consuming information.
I saw this same behaviour in RazorBlade which I linked in the initial post, and he made some change that corrected it. Here is the link to the issue again, which links to the PR with the fix. It looks like he created this dotnet issue for how to properly handle this.