Skip to content

Proposed Fix for ReqnrollVisualStudio issue 47 #49

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 3 additions & 4 deletions Reqnroll.VisualStudio/Discovery/DiscoveryInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public DiscoveryInvoker(IProjectScope projectScope, IDiscoveryResultProvider dis

public int CreateProjectHash(ProjectSettings projectSettings, ConfigSource testAssemblySource) =>
projectSettings.GetHashCode() ^ testAssemblySource.GetHashCode();

public ConfigSource GetTestAssemblySource(ProjectSettings projectSettings) =>
projectSettings.IsReqnrollTestProject
public ConfigSource GetTestAssemblySource(ProjectSettings projectSettings) =>
projectSettings.IsReqnrollProject
? ConfigSource.TryGetConfigSource(projectSettings.OutputAssemblyPath, _fileSystem, _logger)
: ConfigSource.CreateInvalid("The project is not detected to be a Reqnroll project, therefore some Reqnroll Visual Studio Extension features are disabled.");

Expand Down Expand Up @@ -70,7 +69,7 @@ public Discovery(IDeveroomLogger logger, IDeveroomErrorListServices errorListSer

public IDiscovery AndProjectIsReqnrollProject()
{
if (_projectSettings.IsReqnrollTestProject)
if (_projectSettings.IsReqnrollProject)
return this;

_logger.LogVerbose("Non-Reqnroll test project");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,43 @@ public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetK
var project = IdeScope.GetProject(textBuffer);
bool bindingsNotYetLoaded = false;
bool projectNotYetLoaded = project == null;
if (!projectNotYetLoaded)
var asyncContextMenu = IdeScope.Actions.ShowAsyncContextMenu(PopupHeader);
Task.Run(async () =>
{
Logger.LogVerbose("Find Step Definition Usages:PreExec: project loaded");
var bindingRegistry = project.GetDiscoveryService().BindingRegistryCache;
bindingsNotYetLoaded = (bindingRegistry == null || bindingRegistry.Value == ProjectBindingRegistry.Invalid);
if (bindingsNotYetLoaded)
Logger.LogVerbose($"Find Step Definition Usages: PreExec: binding registry not available: {(bindingRegistry == null ? "null" : "invalid")}");
}
if (!projectNotYetLoaded)
{
Logger.LogVerbose("Find Step Definition Usages:PreExec: project loaded");
var bindingRegistry = project.GetDiscoveryService().BindingRegistryCache;
bindingsNotYetLoaded = (bindingRegistry == null || bindingRegistry.Value == ProjectBindingRegistry.Invalid);
if (bindingsNotYetLoaded)
{
Logger.LogVerbose($"Find Step Definition Usages: PreExec: binding registry not available: {(bindingRegistry == null ? "null" : "invalid")}");
IdeScope.Actions.ShowProblem("Unable to find step definition usages: the project is not initialized yet.");
return true;
}
}

if (project == null || !project.GetProjectSettings().IsReqnrollProject || bindingsNotYetLoaded )
{
IdeScope.Actions.ShowProblem(
"Unable to find step definition usages: the project is not detected to be a Reqnroll project or it is not initialized yet.");
return true;
}
if (project == null || !project.GetProjectSettings().IsReqnrollProject || bindingsNotYetLoaded)
{
IdeScope.Actions.ShowProblem(
"Unable to find step definition usages: the project is not detected to be a Reqnroll project.");
return true;
}

var reqnrollTestProjects = IdeScope.GetProjectsWithFeatureFiles()
.Where(p => p.GetProjectSettings().IsReqnrollTestProject)
.ToArray();
var reqnrollTestProjects = IdeScope.GetProjectsWithFeatureFiles()
.Where(p => p.GetProjectSettings().IsReqnrollTestProject)
.ToArray();

if (reqnrollTestProjects.Length == 0)
{
IdeScope.Actions.ShowProblem(
"Unable to find step definition usages: could not find any Reqnroll project with feature files.");
return true;
}
if (reqnrollTestProjects.Length == 0)
{
IdeScope.Actions.ShowProblem(
"Unable to find step definition usages: could not find any Reqnroll project with feature files.");
return true;
}

var asyncContextMenu = IdeScope.Actions.ShowAsyncContextMenu(PopupHeader);
Task.Run(
() => FindUsagesInProjectsAsync(reqnrollTestProjects, fileName, triggerPoint, asyncContextMenu,
asyncContextMenu.CancellationToken), asyncContextMenu.CancellationToken);
await FindUsagesInProjectsAsync(reqnrollTestProjects, fileName, triggerPoint, asyncContextMenu, asyncContextMenu.CancellationToken);
return true;
}, asyncContextMenu.CancellationToken);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void DoNotDiscoverWhenProjectIsNotReqnrollTestProject()
{
//arrange
using var sut = ArrangeSut();
sut.ProjectScope.StubProjectSettingsProvider.Kind = DeveroomProjectKind.ReqnrollLibProject;
sut.ProjectScope.StubProjectSettingsProvider.Kind = DeveroomProjectKind.OtherProject;

DiscoveryInvoker discoveryInvoker = sut.BuildDiscoveryInvoker();

Expand Down
Loading