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

Rename automatic restore requests to be more explicit #71104

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList<Project
{
var tasks = new List<Task>();

var projectsWithUnresolvedDependencies = new ConcurrentSet<string>();
var projectsThatNeedRestore = new ConcurrentSet<string>();
foreach (var projectToLoad in projectPathsToLoadOrReload)
{
tasks.Add(Task.Run(async () =>
{
var (errorKind, preferredBuildHostKind, hasUnresolvedDependencies) = await LoadOrReloadProjectAsync(projectToLoad, buildHostProcessManager, cancellationToken);
var (errorKind, preferredBuildHostKind, projectNeedsRestore) = await LoadOrReloadProjectAsync(projectToLoad, buildHostProcessManager, cancellationToken);
if (errorKind is LSP.MessageType.Error)
{
// We should display a toast when the value of displayedToast is 0. This will also update the value to 1 meaning we won't send any more toasts.
Expand All @@ -174,23 +174,23 @@ private async ValueTask LoadOrReloadProjectsAsync(ImmutableSegmentedList<Project
}
}

if (hasUnresolvedDependencies)
if (projectNeedsRestore)
{
projectsWithUnresolvedDependencies.Add(projectToLoad.Path);
projectsThatNeedRestore.Add(projectToLoad.Path);
}
}, cancellationToken));
}

await Task.WhenAll(tasks);

if (_globalOptionService.GetOption(LanguageServerProjectSystemOptionsStorage.EnableAutomaticRestore) && projectsWithUnresolvedDependencies.Any())
if (_globalOptionService.GetOption(LanguageServerProjectSystemOptionsStorage.EnableAutomaticRestore) && projectsThatNeedRestore.Any())
{
// Tell the client to restore any projects with unresolved dependencies.
// This should eventually move entirely server side once we have a mechanism for reporting generic project load progress.
// Tracking: https://github.com/dotnet/vscode-csharp/issues/6675
//
// The request blocks to ensure we aren't trying to run a design time build at the same time as a restore.
await ProjectDependencyHelper.RestoreProjectsAsync(projectsWithUnresolvedDependencies.ToImmutableHashSet(), cancellationToken);
await ProjectDependencyHelper.RestoreProjectsAsync(projectsThatNeedRestore.ToImmutableHashSet(), cancellationToken);
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ public void Dispose()

WatchProjectAssetsFile(newProjectInfo, _fileChangeContext);

var hasUnresolvedDependencies = ProjectDependencyHelper.HasUnresolvedDependencies(newProjectInfo, _mostRecentFileInfo, logger);
var needsRestore = ProjectDependencyHelper.NeedsRestore(newProjectInfo, _mostRecentFileInfo, logger);

_mostRecentFileInfo = newProjectInfo;

Contract.ThrowIfNull(_projectSystemProject.CompilationOptions, "Compilation options cannot be null for C#/VB project");
var outputKind = _projectSystemProject.CompilationOptions.OutputKind;
return (metadataReferences, outputKind, hasUnresolvedDependencies);
return (metadataReferences, outputKind, needsRestore);

// logMessage should be a string with two placeholders; the first is the project name, the second is the number of items.
void UpdateProjectSystemProjectCollection<T>(IEnumerable<T> loadedCollection, IEnumerable<T>? oldLoadedCollection, IEqualityComparer<T> comparer, Action<T> addItem, Action<T> removeItem, string logMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace;
internal static class ProjectDependencyHelper
{
private const string UnresolvedProjectDependenciesName = "workspace/_roslyn_projectHasUnresolvedDependencies";
private const string ProjectNeedsRestoreName = "workspace/_roslyn_projectNeedsRestore";

internal static bool HasUnresolvedDependencies(ProjectFileInfo newProjectFileInfo, ProjectFileInfo? previousProjectFileInfo, ILogger logger)
internal static bool NeedsRestore(ProjectFileInfo newProjectFileInfo, ProjectFileInfo? previousProjectFileInfo, ILogger logger)
{
if (previousProjectFileInfo is null)
{
Expand All @@ -26,12 +26,6 @@ internal static bool HasUnresolvedDependencies(ProjectFileInfo newProjectFileInf
return CheckProjectAssetsForUnresolvedDependencies(newProjectFileInfo, logger);
}

if (newProjectFileInfo.TargetFramework != previousProjectFileInfo.TargetFramework)
{
// If the target framework has changed then we need to run a restore.
return true;
}

var newPackageReferences = newProjectFileInfo.PackageReferences;
var previousPackageReferences = previousProjectFileInfo.PackageReferences;

Expand Down Expand Up @@ -136,7 +130,7 @@ internal static async Task RestoreProjectsAsync(ImmutableHashSet<string> project
Contract.ThrowIfNull(LanguageServerHost.Instance, "We don't have an LSP channel yet to send this request through.");
var languageServerManager = LanguageServerHost.Instance.GetRequiredLspService<IClientLanguageServerManager>();
var unresolvedParams = new UnresolvedDependenciesParams(projectPaths.ToArray());
await languageServerManager.SendRequestAsync(UnresolvedProjectDependenciesName, unresolvedParams, cancellationToken);
await languageServerManager.SendRequestAsync(ProjectNeedsRestoreName, unresolvedParams, cancellationToken);
}

[DataContract]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public static IEnumerable<ProjectFileReference> GetProjectReferences(this MSB.Ex
public static ImmutableArray<PackageReference> GetPackageReferences(this MSB.Execution.ProjectInstance executedProject)
{
var packageReferenceItems = executedProject.GetItems(ItemNames.PackageReference);
if (packageReferenceItems == null)
{
return ImmutableArray<PackageReference>.Empty;
}

using var _ = PooledHashSet<PackageReference>.GetInstance(out var references);

foreach (var item in packageReferenceItems)
Expand Down
Loading