Skip to content

Commit

Permalink
Further improvement for several entities. Starting to move to IVsUpda…
Browse files Browse the repository at this point in the history
…teSolutionEvents
  • Loading branch information
StefanKert committed Jan 14, 2019
1 parent 3a680f8 commit 0b1f15d
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 248 deletions.
1 change: 1 addition & 0 deletions src/BuildVision.Contracts/BuildVision.Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
Expand Down
154 changes: 97 additions & 57 deletions src/BuildVision.Contracts/ErrorItem.cs
Original file line number Diff line number Diff line change
@@ -1,87 +1,127 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Build.Framework;

namespace BuildVision.Contracts
{
public class ErrorItem
{
public const string DefaultSortPropertyName = "Number";
private readonly List<string> _invalidFileNames = new List<string> { "CSC", "MSBUILD", "LINK" };
public class ErrorItem
{
public const string DefaultSortPropertyName = "Number";
private readonly List<string> _invalidFileNames = new List<string> { "CSC", "MSBUILD", "LINK" };

public bool CanNavigateTo { get; set; }
public bool CanNavigateTo { get; set; }

public int? Number { get; set; }
public int? Number { get; set; }

public ErrorLevel Level { get; set; }
public ErrorLevel Level { get; set; }

public string Code { get; set; }
public string Code { get; set; }

public string File { get; set; }
public string File { get; set; }

public string FileName
{
get
{
try
{
return Path.GetFileName(File);
}
catch (ArgumentException)
public string FileName
{
return File;
get
{
try
{
return Path.GetFileName(File);
}
catch (ArgumentException)
{
return File;
}
}
}
}
}

public string ProjectFile { get; set; }
public string ProjectFile { get; set; }

public int LineNumber { get; set; }
public int ColumnNumber { get; set; }
public int LineNumber { get; set; }
public int ColumnNumber { get; set; }

public int EndLineNumber { get; set; }
public int EndLineNumber { get; set; }

public int EndColumnNumber { get; set; }
public int EndColumnNumber { get; set; }

public string Subcategory { get; set; }
public string Subcategory { get; set; }

public string Message { get; set; }
public string Message { get; set; }

public Action GoToError { get; }
public Action GoToError { get; }

public ErrorItem(ErrorLevel errorLevel, Action<ErrorItem> goToError)
{
Level = errorLevel;
GoToError = () => goToError(this);
}
public ErrorItem(ErrorLevel errorLevel, Action<ErrorItem> goToError)
{
Level = errorLevel;
GoToError = () => goToError(this);
}

public ErrorItem() { }
public ErrorItem() { }

// 1. EnvDTE.TextSelection.MoveToLineAndOffset requires line and offset numbers beginning at one.
// BuildErrorEventArgs.LineNumber and BuildErrorEventArgs.ColumnNumber may be uninitialized.
// 2. BuildErrorEventArgs.EndLineNumber and BuildErrorEventArgs.EndColumnNumber may be uninitialized,
// regardless of BuildErrorEventArgs.LineNumber and BuildErrorEventArgs.ColumnNumber.
public void VerifyValues()
{
if (_invalidFileNames.Contains(File) && LineNumber == 0 && ColumnNumber == 0)
{
CanNavigateTo = false;
return;
}

if (LineNumber < 1)
LineNumber = 1;
public void Init(BuildErrorEventArgs e)
{
Code = e.Code;
File = e.File;
ProjectFile = e.ProjectFile;
LineNumber = e.LineNumber;
ColumnNumber = e.ColumnNumber;
EndLineNumber = e.EndLineNumber;
EndColumnNumber = e.EndColumnNumber;
Subcategory = e.Subcategory;
Message = e.Message;
}

public void Init(BuildWarningEventArgs e)
{
Code = e.Code;
File = e.File;
ProjectFile = e.ProjectFile;
LineNumber = e.LineNumber;
ColumnNumber = e.ColumnNumber;
EndLineNumber = e.EndLineNumber;
EndColumnNumber = e.EndColumnNumber;
Subcategory = e.Subcategory;
Message = e.Message;
}

public void Init(BuildMessageEventArgs e)
{
Code = e.Code;
File = e.File;
ProjectFile = e.ProjectFile;
LineNumber = e.LineNumber;
ColumnNumber = e.ColumnNumber;
EndLineNumber = e.EndLineNumber;
EndColumnNumber = e.EndColumnNumber;
Subcategory = e.Subcategory;
Message = e.Message;
}
// 1. EnvDTE.TextSelection.MoveToLineAndOffset requires line and offset numbers beginning at one.
// BuildErrorEventArgs.LineNumber and BuildErrorEventArgs.ColumnNumber may be uninitialized.
// 2. BuildErrorEventArgs.EndLineNumber and BuildErrorEventArgs.EndColumnNumber may be uninitialized,
// regardless of BuildErrorEventArgs.LineNumber and BuildErrorEventArgs.ColumnNumber.
public void VerifyValues()
{
if (_invalidFileNames.Contains(File) && LineNumber == 0 && ColumnNumber == 0)
{
CanNavigateTo = false;
return;
}

if (ColumnNumber < 1)
ColumnNumber = 1;
if (LineNumber < 1)
LineNumber = 1;

if (EndLineNumber == 0 && EndColumnNumber == 0)
{
EndLineNumber = LineNumber;
EndColumnNumber = ColumnNumber;
}
if (ColumnNumber < 1)
ColumnNumber = 1;

CanNavigateTo = true;
if (EndLineNumber == 0 && EndColumnNumber == 0)
{
EndLineNumber = LineNumber;
EndColumnNumber = ColumnNumber;
}

CanNavigateTo = true;
}
}
}
}
1 change: 1 addition & 0 deletions src/BuildVision/BuildVision.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Core\ServiceProviderExports.cs" />
<Compile Include="Core\ServiceProviderPackage.cs" />
<Compile Include="Core\Services.cs" />
<Compile Include="Core\SolutionBuildEvents.cs" />
<Compile Include="Core\StatusBarNotificationService.cs" />
<Compile Include="Helpers\BuildEventContextExtensions.cs" />
<Compile Include="Helpers\BuildMessageEventArgsExtensions.cs" />
Expand Down
78 changes: 22 additions & 56 deletions src/BuildVision/Core/BuildVisionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Windows;
using BuildVision.Common;
using BuildVision.Contracts;
using BuildVision.Tool;
using BuildVision.Tool.Building;
using BuildVision.Tool.Models;
Expand Down Expand Up @@ -43,21 +44,22 @@ namespace BuildVision.Core
[ProvideBindingPath]
[ProvideBindingPath(SubPath = "Lib")]
// TODO: Add ProvideProfileAttribute for each DialogPage and implement IVsUserSettings, IVsUserSettingsQuery.
[ProvideProfile(typeof(GeneralSettingsDialogPage), SettingsCategoryName, "General Options", 0, 0, true)]
[ProvideProfile(typeof(GeneralSettingsDialogPage), PackageSettingsProvider.settingsCategoryName, "General Options", 0, 0, true)]
// TODO: ProvideOptionPage keywords.
[ProvideOptionPage(typeof(GeneralSettingsDialogPage), "BuildVision", "General", 0, 0, true)]
[ProvideOptionPage(typeof(WindowSettingsDialogPage), "BuildVision", "Tool Window", 0, 0, true)]
[ProvideOptionPage(typeof(GridSettingsDialogPage), "BuildVision", "Projects Grid", 0, 0, true)]
[ProvideOptionPage(typeof(BuildMessagesSettingsDialogPage), "BuildVision", "Build Messages", 0, 0, true)]
[ProvideOptionPage(typeof(ProjectItemSettingsDialogPage), "BuildVision", "Project Item", 0, 0, true)]
public sealed partial class BuildVisionPackage : AsyncPackage, IPackageContext, IVsUpdateSolutionEvents2
public sealed partial class BuildVisionPackage : AsyncPackage, IPackageContext
{
private DTE _dte;
private SolutionEvents _solutionEvents;
private BuildVisionPaneViewModel _viewModel;
private IVsSolutionBuildManager2 _solutionBuildManager;
private uint _updateSolutionEventsCookie;

private readonly Guid _parsingErrorsLoggerId = new Guid("{64822131-DC4D-4087-B292-61F7E06A7B39}");
private BuildOutputLogger _buildLogger;
private IVsSolution2 _vsSolution;

public ControlSettings ControlSettings { get; set; }
Expand All @@ -84,7 +86,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
_solutionBuildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
if (_solutionBuildManager != null)
{
_solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateSolutionEventsCookie);
_solutionBuildManager.AdviseUpdateSolutionEvents(new SolutionBuildEvents(), out _updateSolutionEventsCookie);
}

_solutionEvents = _dte.Events.SolutionEvents;
Expand All @@ -96,10 +98,22 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
//_viewModel = BuildVisionPane.GetViewModel(toolWindow);
//ViewModelHelper.UpdateSolution(_dte.Solution, _viewModel.SolutionItem);
//var buildContext = new BuildContext(packageContext, _dte, _dte.Events.BuildEvents, _dte.Events.WindowEvents, _dte.Events.CommandEvents, viewModel);

_dte.Events.BuildEvents.OnBuildBegin += (scope, args) => { RegisterLogger(); };
}

private void RegisterLogger()
{
var result = BuildOutputLogger.Register(_parsingErrorsLoggerId, Microsoft.Build.Framework.LoggerVerbosity.Quiet, out _buildLogger);
if (result == RegisterLoggerResult.AlreadyExists)
{
_buildLogger.Projects?.Clear();
}
}

private void SolutionEvents_Opened()
{
ThreadHelper.ThrowIfNotOnUIThread();
SetVsSolution();

ViewModelHelper.UpdateSolution(_dte.Solution, _viewModel.SolutionItem);
Expand All @@ -108,19 +122,16 @@ private void SolutionEvents_Opened()

private void SetVsSolution()
{
ThreadHelper.ThrowIfNotOnUIThread();
if (_vsSolution == null)
_vsSolution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2;
}

private Project GetProject(IVsHierarchy pHierProj)
{
object objProj;
pHierProj.GetProperty(VSConstants.VSITEMID_ROOT, (int) __VSHPROPID.VSHPROPID_ExtObject, out objProj);
return objProj as Project;
}

private void SolutionEvents_AfterClosing()
{
ThreadHelper.ThrowIfNotOnUIThread();
SetVsSolution();

_viewModel.TextCurrentState = Resources.BuildDoneText_BuildNotStarted;
_viewModel.ImageCurrentState = VectorResources.TryGet(BuildImages.BuildActionResourcesUri, "StandBy");
_viewModel.ImageCurrentStateResult = null;
Expand Down Expand Up @@ -167,50 +178,5 @@ public async Task ExecuteCommandAsync(string commandName)
await JoinableTaskFactory.SwitchToMainThreadAsync(DisposalToken);
_dte.ExecuteCommand(commandName);
}

public int UpdateSolution_Begin(ref int pfCancelUpdate)
{
Console.WriteLine($"UpdateSolution_Begin");
return 0;
}

public int UpdateSolution_Done(int fSucceeded, int fModified, int fCancelCommand)
{
Console.WriteLine($"UpdateSolution_Done: fSucceeded {fSucceeded}, fModified {fModified}, fCancelCommand {fCancelCommand}");
return 0;
}

public int UpdateSolution_StartUpdate(ref int pfCancelUpdate)
{
Console.WriteLine($"UpdateSolution_StartUpdate");
return 0;
}

public int UpdateSolution_Cancel()
{
Console.WriteLine($"UpdateSolution_Cancel");
return 0;
}

public int OnActiveProjectCfgChange(IVsHierarchy pIVsHierarchy)
{
var proj = GetProject(pIVsHierarchy);
Console.WriteLine($"OnActiveProjectCfgChange {proj.UniqueName}");
return 0;
}

public int UpdateProjectCfg_Begin(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, ref int pfCancel)
{
var proj = GetProject(pHierProj);
Console.WriteLine($"UpdateProjectCfg_Begin {proj.UniqueName}");
return 0;
}

public int UpdateProjectCfg_Done(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, int fSuccess, int fCancel)
{
var proj = GetProject(pHierProj);
Console.WriteLine($"UpdateProjectCfg_Done {proj.UniqueName}: dwAction {dwAction}, fSuccess {fSuccess}, fCancel {fCancel}");
return 0;
}
}
}
Loading

0 comments on commit 0b1f15d

Please sign in to comment.