Skip to content

Commit

Permalink
Fix for hanging on project creation... hopefully (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwhitfield authored Nov 24, 2022
1 parent 83a268d commit 0b40d25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Unitverse/Helper/ReferencesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ public static void AddNugetPackagesAndProjectReferences(IUnitTestGeneratorPackag
ThreadHelper.ThrowIfNotOnUIThread();
var logger = new AggregateLogger();

package.JoinableTaskFactory.Run(async () =>
var projectGuid = source.GetProjectId();

_ = package.JoinableTaskFactory.RunAsync(async () =>
{
await WaitableActionHelper.RunWaitableActionAsync(package, logger, "Creating test project", async logMessage =>
{
logMessage("Waiting for project initialization...");

var operationProgressStatusService = package.GetService(typeof(SVsOperationProgressStatusService)) as IVsOperationProgressStatusService;
var operationProgressStatusService = package.GetService(typeof(SVsOperationProgressStatusService)) as IVsOperationProgressStatusService2;
Assumes.Present(operationProgressStatusService);
var stageStatus = operationProgressStatusService.GetStageStatus(CommonOperationProgressStageIds.Intellisense);
var stageStatus = operationProgressStatusService.GetProjectStageStatus(projectGuid, CommonOperationProgressStageIds.Intellisense, true);

await package.JoinableTaskFactory.RunAsync(stageStatus.WaitForCompletionAsync);
await stageStatus.WaitForCompletionAsync();

await package.JoinableTaskFactory.SwitchToMainThreadAsync();

Expand Down
23 changes: 23 additions & 0 deletions src/Unitverse/Helper/VsProjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Unitverse.Helper
using System.Linq;
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Unitverse.Core.Helpers;
Expand Down Expand Up @@ -68,6 +69,28 @@ public static string SafeFileName(this Project project)
return projectFileName;
}

public static Guid GetProjectId(this Project project)
{
ThreadHelper.ThrowIfNotOnUIThread();

var solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
IVsHierarchy hierarchy;

solution.GetProjectOfUniqueName(project.FullName, out hierarchy);

if (hierarchy != null)
{
hierarchy.GetGuidProperty(
VSConstants.VSITEMID_ROOT,
(int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
out var projectGuid);

return projectGuid;
}

return Guid.Empty;
}

private static IEnumerable<Project> FindProjects(IEnumerable<Project> currentProjects)
{
ThreadHelper.ThrowIfNotOnUIThread();
Expand Down

0 comments on commit 0b40d25

Please sign in to comment.