Browse Source

Fix VSIX analyzer warnings and disabled the analyzer

pull/1728/head
Andreas Weizel 6 years ago
parent
commit
39e879377e
  1. 5
      ILSpy.AddIn/Commands/NuGetReferenceForILSpy.cs
  2. 9
      ILSpy.AddIn/Commands/OpenCodeItemCommand.cs
  3. 6
      ILSpy.AddIn/Commands/OpenILSpyCommand.cs
  4. 4
      ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs
  5. 4
      ILSpy.AddIn/Commands/OpenReferenceCommand.cs
  6. 5
      ILSpy.AddIn/Commands/ProjectItemForILSpy.cs
  7. 5
      ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs
  8. 1
      ILSpy.AddIn/ILSpy.AddIn.csproj
  9. 6
      ILSpy.AddIn/ILSpyAddInPackage.cs
  10. 1
      ILSpy.AddIn/ILSpyInstance.cs
  11. 11
      ILSpy.AddIn/Utils.cs

5
ILSpy.AddIn/Commands/NuGetReferenceForILSpy.cs

@ -4,6 +4,7 @@ using System.Linq; @@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
namespace ICSharpCode.ILSpy.AddIn.Commands
{
@ -26,6 +27,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -26,6 +27,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns><see cref="NuGetReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
public static NuGetReferenceForILSpy Detect(object itemData)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (itemData is ProjectItem projectItem) {
var properties = Utils.GetProperties(projectItem.Properties, "Type");
if ((properties[0] as string) == "Package") {
@ -42,6 +45,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -42,6 +45,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
public ILSpyParameters GetILSpyParameters()
{
ThreadHelper.ThrowIfNotOnUIThread();
var properties = Utils.GetProperties(projectItem.Properties, "Name", "Version", "Path");
if (properties[0] != null && properties[1] != null && properties[2] != null) {
return new ILSpyParameters(new[] { $"{properties[2]}\\{properties[0]}.{properties[1]}.nupkg" });

9
ILSpy.AddIn/Commands/OpenCodeItemCommand.cs

@ -23,6 +23,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -23,6 +23,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnBeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (sender is OleMenuCommand menuItem) {
menuItem.Visible = false;
@ -46,6 +48,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -46,6 +48,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
Document GetRoslynDocument()
{
ThreadHelper.ThrowIfNotOnUIThread();
var document = owner.DTE.ActiveDocument;
var selection = (EnvDTE.TextPoint)((EnvDTE.TextSelection)document.Selection).ActivePoint;
var id = owner.Workspace.CurrentSolution.GetDocumentIdsWithFilePath(document.FullName).FirstOrDefault();
@ -57,12 +61,16 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -57,12 +61,16 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
EnvDTE.TextPoint GetEditorSelection()
{
ThreadHelper.ThrowIfNotOnUIThread();
var document = owner.DTE.ActiveDocument;
return ((EnvDTE.TextSelection)document.Selection).ActivePoint;
}
protected override async void OnExecute(object sender, EventArgs e)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var textView = Utils.GetCurrentViewHost(owner)?.TextView;
if (textView == null)
return;
@ -89,6 +97,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -89,6 +97,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
// Add our own project as well (not among references)
var project = FindProject(owner.DTE.Solution.Projects.OfType<EnvDTE.Project>(), roslynProject.FilePath);
if (project == null) {
owner.ShowMessage(OLEMSGICON.OLEMSGICON_WARNING, "Can't show ILSpy for this code element!");
return;

6
ILSpy.AddIn/Commands/OpenILSpyCommand.cs

@ -55,6 +55,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -55,6 +55,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected void OpenAssembliesInILSpy(ILSpyParameters parameters)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (parameters == null)
return;
@ -71,6 +73,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -71,6 +73,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected Dictionary<string, DetectedReference> GetReferences(Microsoft.CodeAnalysis.Project parentProject)
{
ThreadHelper.ThrowIfNotOnUIThread();
var dict = new Dictionary<string, DetectedReference>();
foreach (var reference in parentProject.MetadataReferences) {
using (var assemblyDef = AssemblyDefinition.ReadAssembly(reference.Display)) {
@ -97,6 +101,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -97,6 +101,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected EnvDTE.Project FindProject(IEnumerable<EnvDTE.Project> projects, string projectFile)
{
ThreadHelper.ThrowIfNotOnUIThread();
foreach (var project in projects) {
switch (project.Kind) {
case DTEConstants.vsProjectKindSolutionItems:

4
ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs

@ -17,6 +17,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -17,6 +17,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnBeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (sender is OleMenuCommand menuItem) {
menuItem.Visible = false;
@ -27,6 +29,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -27,6 +29,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnExecute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (owner.DTE.SelectedItems.Count != 1)
return;
var projectItemWrapper = ProjectItemForILSpy.Detect(owner, owner.DTE.SelectedItems.Item(1));

4
ILSpy.AddIn/Commands/OpenReferenceCommand.cs

@ -22,6 +22,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -22,6 +22,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnBeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (sender is OleMenuCommand menuItem) {
menuItem.Visible = false;
@ -44,6 +46,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -44,6 +46,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnExecute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
var itemObject = owner.GetSelectedItemsData<object>().FirstOrDefault();
if (itemObject == null)
return;

5
ILSpy.AddIn/Commands/ProjectItemForILSpy.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System.IO;
using System.Linq;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
namespace ICSharpCode.ILSpy.AddIn.Commands
{
@ -27,6 +28,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -27,6 +28,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns><see cref="ProjectItemForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
public static ProjectItemForILSpy Detect(ILSpyAddInPackage package, SelectedItem item)
{
ThreadHelper.ThrowIfNotOnUIThread();
var project = item.Project;
var roslynProject = package.Workspace.CurrentSolution.Projects.FirstOrDefault(p => p.FilePath == project.FileName);
if (roslynProject == null)
@ -42,6 +45,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -42,6 +45,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
public ILSpyParameters GetILSpyParameters(ILSpyAddInPackage package)
{
ThreadHelper.ThrowIfNotOnUIThread();
return new ILSpyParameters(new[] { Utils.GetProjectOutputAssembly(project, roslynProject) });
}
}

5
ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs

@ -4,6 +4,7 @@ using System.Linq; @@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.AddIn.Commands
@ -31,6 +32,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -31,6 +32,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns><see cref="ProjectReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
public static ProjectReferenceForILSpy Detect(object itemData)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (itemData is ProjectItem projectItem) {
var properties = Utils.GetProperties(projectItem.Properties, "FusionName", "ResolvedPath");
string fusionName = properties[0] as string;
@ -50,6 +53,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -50,6 +53,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
public ILSpyParameters GetILSpyParameters(Dictionary<string, DetectedReference> projectReferences)
{
ThreadHelper.ThrowIfNotOnUIThread();
string fileName = projectItem.ContainingProject?.FileName;
if (!string.IsNullOrEmpty(fileName)) {
if (projectReferences.TryGetValue(projectItem.Name, out DetectedReference path)) {

1
ILSpy.AddIn/ILSpy.AddIn.csproj

@ -51,7 +51,6 @@ @@ -51,7 +51,6 @@
<PackageReference Include="Microsoft.VisualStudio.ComponentModelHost" Version="15.6.27413" />
<PackageReference Include="Microsoft.VisualStudio.Editor" Version="15.6.27740" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServices" Version="2.4.0" />
<PackageReference Include="Microsoft.VisualStudio.SDK.Analyzers" Version="16.0.29" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="15.6.27413" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime" Version="14.3.26929" />
<PackageReference Include="Microsoft.VisualStudio.Text.UI" Version="15.6.27740" />

6
ILSpy.AddIn/ILSpyAddInPackage.cs

@ -113,6 +113,10 @@ namespace ICSharpCode.ILSpy.AddIn @@ -113,6 +113,10 @@ namespace ICSharpCode.ILSpy.AddIn
ThreadHelper.ThrowIfNotOnUIThread();
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
if (uiShell == null) {
return 0;
}
Guid clsid = Guid.Empty;
int result;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
@ -136,6 +140,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -136,6 +140,8 @@ namespace ICSharpCode.ILSpy.AddIn
public IEnumerable<T> GetSelectedItemsData<T>()
{
ThreadHelper.ThrowIfNotOnUIThread();
if (DTE.ToolWindows.SolutionExplorer.SelectedItems is IEnumerable<UIHierarchyItem> hierarchyItems) {
foreach (var item in hierarchyItems) {
if (item.Object is T typedItem) {

1
ILSpy.AddIn/ILSpyInstance.cs

@ -54,6 +54,7 @@ namespace ICSharpCode.ILSpy.AddIn @@ -54,6 +54,7 @@ namespace ICSharpCode.ILSpy.AddIn
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD110:Observe result of async calls", Justification = "<Pending>")]
void SendMessage(Process ilspyProcess, string message, bool activate)
{
// We wait asynchronously until target window can be found and try to find it multiple times

11
ILSpy.AddIn/Utils.cs

@ -8,6 +8,7 @@ using System.Text; @@ -8,6 +8,7 @@ using System.Text;
using EnvDTE;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.LanguageServices;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
@ -148,6 +149,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -148,6 +149,8 @@ namespace ICSharpCode.ILSpy.AddIn
public static object[] GetProperties(EnvDTE.Properties properties, params string[] names)
{
ThreadHelper.ThrowIfNotOnUIThread();
var values = new object[names.Length];
foreach (object p in properties) {
try {
@ -168,6 +171,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -168,6 +171,8 @@ namespace ICSharpCode.ILSpy.AddIn
public static List<(string, object)> GetAllProperties(EnvDTE.Properties properties)
{
ThreadHelper.ThrowIfNotOnUIThread();
var result = new List<(string, object)>();
for (int i = 0; i < properties.Count; i++) {
try {
@ -207,6 +212,10 @@ namespace ICSharpCode.ILSpy.AddIn @@ -207,6 +212,10 @@ namespace ICSharpCode.ILSpy.AddIn
public static IWpfTextViewHost GetCurrentViewHost(IServiceProvider serviceProvider)
{
IVsTextManager txtMgr = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));
if (txtMgr == null) {
return null;
}
IVsTextView vTextView = null;
int mustHaveFocus = 1;
txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);
@ -235,6 +244,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -235,6 +244,8 @@ namespace ICSharpCode.ILSpy.AddIn
public static string GetProjectOutputAssembly(Project project, Microsoft.CodeAnalysis.Project roslynProject)
{
ThreadHelper.ThrowIfNotOnUIThread();
string outputFileName = Path.GetFileName(roslynProject.OutputFilePath);
// Get the directory path based on the project file.

Loading…
Cancel
Save