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

Do not load generators in VS process #74444

Merged
merged 33 commits into from
Jul 23, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Jul 18, 2024

This change updates our VS workspace to eliminate the last known place where we were loading generators 'in process' in the VS host. Specifically, we would load generators 'in proc' to populate this UI:

image

Note: The files themselves were generated in our OOP process. But we still loaded the generators in-proc to get things like all the generator names.

Loading in proc is highly problematic as it limits us from being able to reload generators when they change on disk. Because VS is a .Net framework app, any attempts to reload will bork as that's just not somethign .Net framework is capable of.

By moving this computation out of process, we now compute it in our .Net Core host. There we are able to use thigns like AssemblyLoadContexts to actually load different versions of an generator independently. Note: the work to actually do that is upcoming. But this blocks the VS side that would have otherwise had significant problems.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 18, 2024
@@ -33,11 +33,11 @@ internal abstract class BaseItem :
{
public virtual event PropertyChangedEventHandler PropertyChanged { add { } remove { } }

private readonly string _name;
protected readonly string Name;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected as we use it as part of the equality contract of derived classes.

private void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more notifications, as thsi is now an immutable vlaue.


public ProjectId ProjectId { get; }
public DiagnosticDescriptor Descriptor { get; }
public ReportDiagnostic EffectiveSeverity { get; private set; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private setter removed.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review July 18, 2024 20:47
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 18, 2024 20:47

public override IContextMenuController ContextMenuController => _commandHandler.DiagnosticContextMenuController;

public override object GetBrowseObject()
=> new BrowseObject(this);

internal void UpdateEffectiveSeverity(ReportDiagnostic newEffectiveSeverity)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we no longer update these in place (it makes equality/hash semantics non-ideal, which does impact how the observable collection and virtual tree view operate).

instead, if things do change (the rare case) we rebuild the collection, with all the data immutable in it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 Will this cause the solution explorer to collapse nodes that are expanded when the children change? We've seen bugs of that form in other contexts before, so just asking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed thsi. the answer is likely 'yes'. If we feel like that's important to address, we can potentially do it by breaking out the portion of the anlaysis to determine if we think an actual change to the list happened, versus a property change to an item in the list. that said. only the item itself collapses. not the parent. so it's notthat bad imo.

/// <summary>
/// The analyzer reference that has been found. Once it's been assigned a non-null value, it'll never be assigned null again.
/// </summary>
private AnalyzerReference? _analyzerReference;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to base class. note that this comment is important. it was an invariant of this subclass that it would only set this once. We check for thsi invariant in the base class now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use [DisallowNull] for this.

private void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more notifications, as thsi is now an immutable vlaue.

CommandHandler = commandHandler;
_diagnosticAnalyzerService = diagnosticAnalyzerService;

_listener = listenerProvider.GetListener(FeatureAttribute.SourceGenerators);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_listener

nit: doesn't look like it needs to be a member

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not. if so, can remove in followup if there are no other changes i need to make.

}

return;
var identifies = await GetIdentitiesAsync().ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identifies

super nit: typo

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants