Skip to content
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
13 changes: 8 additions & 5 deletions SharedProject/Core/SourceFileOpener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel.Composition;
using System.Linq;
using EnvDTE;
using EnvDTE80;
using FineCodeCoverage.Engine.Cobertura;
using Microsoft;
using Microsoft.VisualStudio.Shell;
Expand All @@ -15,6 +16,7 @@ internal class SourceFileOpener : ISourceFileOpener
private readonly IMessageBox messageBox;
private readonly ILogger logger;
private readonly IServiceProvider serviceProvider;
private readonly DTE2 dte;

[ImportingConstructor]
public SourceFileOpener(
Expand All @@ -27,6 +29,9 @@ public SourceFileOpener(
this.messageBox = messageBox;
this.logger = logger;
this.serviceProvider = serviceProvider;
ThreadHelper.ThrowIfNotOnUIThread();
dte = (DTE2)serviceProvider.GetService(typeof(DTE));
Assumes.Present(dte);
}
public async System.Threading.Tasks.Task OpenFileAsync(string assemblyName, string qualifiedClassName, int file, int line)
{
Expand All @@ -43,17 +48,15 @@ public async System.Threading.Tasks.Task OpenFileAsync(string assemblyName, stri
}

await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var Dte = (DTE)serviceProvider.GetService(typeof(DTE));
Assumes.Present(Dte);
Dte.MainWindow.Activate();
dte.MainWindow.Activate();

foreach (var sourceFile in sourceFiles)
{
Dte.ItemOperations.OpenFile(sourceFile, Constants.vsViewKindCode);
dte.ItemOperations.OpenFile(sourceFile, Constants.vsViewKindCode);

if (line != 0)
{
((TextSelection)Dte.ActiveDocument.Selection).GotoLine(line, false);
((TextSelection)dte.ActiveDocument.Selection).GotoLine(line, false);
}
}

Expand Down
68 changes: 58 additions & 10 deletions SharedProject/Core/Utilities/SolutionEvents.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using EnvDTE;
using Microsoft;
using Microsoft;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.ComponentModel.Composition;

namespace FineCodeCoverage.Core.Utilities
{
[Export(typeof(ISolutionEvents))]
public class SolutionEvents : ISolutionEvents
public class SolutionEvents : ISolutionEvents, IVsSolutionEvents
{
private Events Events;
private EnvDTE.SolutionEvents dteSolutionEvents;
public event EventHandler AfterClosing;

[ImportingConstructor]
Expand All @@ -20,11 +19,60 @@ IServiceProvider serviceProvider
)
{
ThreadHelper.ThrowIfNotOnUIThread();
var Dte = (DTE)serviceProvider.GetService(typeof(DTE));
Assumes.Present(Dte);
Events = Dte.Events;
dteSolutionEvents = Events.SolutionEvents;
dteSolutionEvents.AfterClosing += () => AfterClosing?.Invoke(this, EventArgs.Empty);
var vsSolution = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution));
Assumes.Present(vsSolution);
vsSolution.AdviseSolutionEvents(this, out uint _);
}

public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
{
return VSConstants.S_OK;
}

public int OnQueryCloseProject(IVsHierarchy pHierarchy, int fRemoving, ref int pfCancel)
{
return VSConstants.S_OK;
}

public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
{
return VSConstants.S_OK;
}

public int OnAfterLoadProject(IVsHierarchy pStubHierarchy, IVsHierarchy pRealHierarchy)
{
return VSConstants.S_OK;
}

public int OnQueryUnloadProject(IVsHierarchy pRealHierarchy, ref int pfCancel)
{
return VSConstants.S_OK;
}

public int OnBeforeUnloadProject(IVsHierarchy pRealHierarchy, IVsHierarchy pStubHierarchy)
{
return VSConstants.S_OK;
}

public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
{
return VSConstants.S_OK;
}

public int OnQueryCloseSolution(object pUnkReserved, ref int pfCancel)
{
return VSConstants.S_OK;
}

public int OnBeforeCloseSolution(object pUnkReserved)
{
return VSConstants.S_OK;
}

public int OnAfterCloseSolution(object pUnkReserved)
{
AfterClosing?.Invoke(this, new EventArgs());
return VSConstants.S_OK;
}
}
}
12 changes: 11 additions & 1 deletion SharedProject/Output/OutputToolWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ internal class OutputToolWindow : ToolWindowPane
/// </summary>
public OutputToolWindow(OutputToolWindowContext context) : base(null)
{
Initialize(context);
}

public OutputToolWindow()
{
Initialize(OutputToolWindowPackage.GetOutputToolWindowContext());
}

private void Initialize(OutputToolWindowContext context)
{
//to see if OutputToolWindow can be internal ( and thus IScriptManager )
Caption = Vsix.Name;
context.ScriptManager.FocusCallback = () =>
Expand All @@ -46,7 +56,7 @@ public OutputToolWindow(OutputToolWindowContext context) : base(null)
try
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
Content = new OutputToolWindowControl(context.ScriptManager,context.FccEngine);
Content = new OutputToolWindowControl(context.ScriptManager, context.FccEngine);
}
finally
{
Expand Down
22 changes: 15 additions & 7 deletions SharedProject/Output/OutputToolWindowPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace FineCodeCoverage.Output
[ProvideToolWindow(typeof(OutputToolWindow), Style = VsDockStyle.Tabbed, DockedHeight = 300, Window = EnvDTE.Constants.vsWindowKindOutput)]
public sealed class OutputToolWindowPackage : AsyncPackage
{
private Microsoft.VisualStudio.ComponentModelHost.IComponentModel componentModel;
private static Microsoft.VisualStudio.ComponentModelHost.IComponentModel componentModel;
/// <summary>
/// OutputToolWindowPackage GUID string.
/// </summary>
Expand All @@ -57,6 +57,19 @@ public OutputToolWindowPackage()
// initialization is the Initialize method.
}

/*
Hack necessary for debugging in 2022 !
https://developercommunity.visualstudio.com/t/vsix-tool-window-vs2022-different-instantiation-wh/1663280
*/
internal static OutputToolWindowContext GetOutputToolWindowContext()
{
return new OutputToolWindowContext
{
FccEngine = componentModel.GetService<IFCCEngine>(),
ScriptManager = componentModel.GetService<ScriptManager>()
};
}

/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
Expand All @@ -80,12 +93,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke

protected override System.Threading.Tasks.Task<object> InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken)
{
var context = new OutputToolWindowContext
{
FccEngine = componentModel.GetService<IFCCEngine>(),
ScriptManager = componentModel.GetService<ScriptManager>()
};
return System.Threading.Tasks.Task.FromResult<object>(context);
return System.Threading.Tasks.Task.FromResult<object>(GetOutputToolWindowContext());
}
public override IVsAsyncToolWindowFactory GetAsyncToolWindowFactory(Guid toolWindowType)
{
Expand Down