dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.74k stars 3.99k forks source link

Consider having generators run automatically (when in balanced mode) when a particular SG file is open in the editor. #74031

Open CyrusNajmabadi opened 1 month ago

CyrusNajmabadi commented 1 month ago

If the user is looking at the file, that's a potential signal that we want to rerun that generator if they make changes to one of their source files.

Note: it would be good if we could just rerun that generator, not all generators.

dibarbet commented 1 month ago

(Triage) - starting with Cyrus, putting in 17.12

stephentoub commented 1 month ago

In addition to the current Balanced being a bad default for implementing and demoing a source generator, it's also a bad default for using them. This is not a good experience... I get this squiggle telling me I have an error until I save or build:

Image

sharwell commented 1 month ago

My expectation is the Balanced mode would also run generators after switching tabs in the editor. That wouldn't really help the case @stephentoub mentioned though.

stephentoub commented 1 month ago

@captainsafia

AArnott commented 4 days ago

What if 'balanced' mode only penalized the v1 generators and left incremental ones to run more frequently?

CyrusNajmabadi commented 4 days ago

What if 'balanced' mode only penalized the v1 generators and left incremental ones to run more frequently?

Incremental are still incredibly expensive. But they take things from "we're using 50GB of memory per keystroke, to like... 500MB". It's still bad, but you can throw hardware at it.

Currently, my view is that if users really need this sort of realtime experience, they can opt into it. But the vast majority of users don't need to be penalized when the vast majority of their edits have no SG impact whatsoever. 'Balanced' puts us in the mode that most SG systems in VS have run with (where they produce on save/build). And we have the knob for the subset of users that are ok giving up perf.

stephentoub commented 4 days ago

My problem with the default is it breaks the user experience. A key aspect of the VS experience is only getting red squiggles when things are broken. You shouldn't need to save/build for red squiggles to go away.

CyrusNajmabadi commented 4 days ago

Understood. That's something we dont' love, but has to be weighed against the alternative, which is that performance across the board for all features has tanked. A key aspect of the VS experience was also being able to work fast and fluidly and scale up as needed. These two desires are in conflict, and we're opting to make the common case (where the majority of edits have no SG impact) good, while accepting that that means the uncommon edit may have a worse experience or take additional steps.

jjonescz commented 3 days ago

No idea if that's possible, but maybe the red squiggles could turn into gray squiggles when they are 'outdated' - to signal to the user that a save/build is necessary for them to refresh.

AArnott commented 3 days ago

Or maybe re-run the SG after the user pauses for a few seconds.