Skip to content

Commit

Permalink
fix: initialize ToolWindow when command is triggered (#324)
Browse files Browse the repository at this point in the history
* fix: initialize ToolWindow when command is triggered
* chore: update changelog

Co-authored-by: Darius-Beniamin Zdroba <[email protected]>
  • Loading branch information
ShawkyZ and DariusZdroba authored Nov 18, 2024
1 parent cacf74c commit 093a722
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 249 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
args:
--severity-threshold=high
build-project:
uses: snyk/snyk-visual-studio-plugin/.github/workflows/build-project.yml@main
uses: snyk/snyk-visual-studio-plugin/.github/workflows/build-project.yml@release/1
with:
solution-file-path: .
secrets: inherit
Expand Down Expand Up @@ -74,5 +74,5 @@ jobs:
run: vstest.console.exe **\*.Tests.dll /TestCaseFilter:"FullyQualifiedName!=Xunit.Instances.VisualStudio&integration!=true" #exclude integration tests and the psuedo-tests that launch a VS instance
run-integration-tests:
needs: build-project
uses: snyk/snyk-visual-studio-plugin/.github/workflows/integration-tests.yml@main
uses: snyk/snyk-visual-studio-plugin/.github/workflows/integration-tests.yml@release/1
secrets: inherit
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Snyk Security Changelog

## [1.1.66]

### Fixed
- Support VS > 17.10.

## [1.1.63]

### Fixed
Expand Down
194 changes: 0 additions & 194 deletions Snyk.Code.Library.Tests/SnykCode/DcIgnoreServiceTest.cs

This file was deleted.

10 changes: 5 additions & 5 deletions Snyk.Common.Tests/Service/SnykApiServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task SnykApiService_GetUserAsync_ReturnsUserAsync()

optionsMock
.Setup(options => options.CustomEndpoint)
.Returns("https://snyk.io/api");
.Returns("https://api.snyk.io");
optionsMock
.Setup(options => options.ApiToken)
.Returns(TestToken);
Expand All @@ -44,7 +44,7 @@ public async Task SnykApiService_CallSastEnabled_TrueAsync()

optionsMock
.Setup(options => options.CustomEndpoint)
.Returns("https://snyk.io/api");
.Returns("https://api.snyk.io");

optionsMock
.Setup(options => options.ApiToken)
Expand All @@ -67,7 +67,7 @@ public async Task SnykApiService_SendSastSettingsRequestAsync_OrgIsInQueryParamA

optionsMock
.Setup(options => options.CustomEndpoint)
.Returns("https://dev.snyk.io/api");
.Returns("https://api.dev.snyk.io");
optionsMock
.Setup(options => options.ApiToken)
.Returns(TestToken);
Expand All @@ -89,7 +89,7 @@ public async Task SnykApiService_InvalidAuthTokenProvided_ReturnNullAsync()

optionsMock
.Setup(options => options.CustomEndpoint)
.Returns("https://snyk.io/api");
.Returns("https://api.snyk.io");

optionsMock
.Setup(options => options.ApiToken)
Expand All @@ -109,7 +109,7 @@ public async Task SnykApiService_InvalidUrlProvided_ReturnNullAsync()

optionsMock
.Setup(options => options.CustomEndpoint)
.Returns("https://snyk.io/");
.Returns("https://invalidurl.local");

optionsMock
.Setup(options => options.ApiToken)
Expand Down
8 changes: 3 additions & 5 deletions Snyk.Common/Service/SnykApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ public async Task<SastSettings> GetSastSettingsAsync()
{
return null;
}

var response = await SendSastSettingsRequestAsync();
var responseContent = await response.Content.ReadAsStringAsync();

try
{
SastSettings sastSettings = Json.Deserialize<SastSettings>(responseContent);
var response = await SendSastSettingsRequestAsync();
var responseContent = await response.Content.ReadAsStringAsync();
var sastSettings = Json.Deserialize<SastSettings>(responseContent);
this.options.SastSettings = sastSettings;
return sastSettings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ protected AbstractSnykCommand(AsyncPackage package, OleMenuCommandService comman
/// </summary>
/// <param name="sender">Source object.</param>
/// <param name="eventArgs">Event args.</param>
protected abstract void Execute(object sender, EventArgs eventArgs);
protected virtual void Execute(object sender, EventArgs eventArgs)
{
ThreadHelper.JoinableTaskFactory.Run(async () =>
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
await VsPackage.EnsureInitializeToolWindowAsync();
});
}

/// <summary>
/// Get command Id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public static async Task InitializeAsync(AsyncPackage package)
public override async Task UpdateStateAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (this.VsPackage.ToolWindow == null)
{
this.MenuCommand.Enabled = false;
return;
}
this.MenuCommand.Enabled = SnykVSPackage.ServiceProvider.Options.ApiToken.IsValidAfterRefresh()
&& this.VsPackage.ToolWindowControl.IsTreeContentNotEmpty();
}
Expand All @@ -55,6 +60,7 @@ public override async Task UpdateStateAsync()
/// <param name="eventArgs">Event args.</param>
protected override void Execute(object sender, EventArgs eventArgs)
{
base.Execute(sender, eventArgs);
this.VsPackage.ToolWindowControl.Clean();

SnykVSPackage.ServiceProvider.SolutionService.Clean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public static async Task InitializeAsync(AsyncPackage package)
/// </summary>
/// <param name="sender">Source object.</param>
/// <param name="eventArgs">Event args.</param>
protected override void Execute(object sender, EventArgs eventArgs) => this.VsPackage.ShowOptionPage();
protected override void Execute(object sender, EventArgs eventArgs)
{
base.Execute(sender, eventArgs);
this.VsPackage.ShowOptionPage();
}

/// <summary>
/// Get command Id.
Expand Down
6 changes: 5 additions & 1 deletion Snyk.VisualStudio.Extension.2022/Commands/SnykScanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public override async Task UpdateStateAsync()
/// </summary>
/// <param name="sender">Source object.</param>
/// <param name="eventArgs">Event args.</param>
protected override void Execute(object sender, EventArgs eventArgs) => ThreadHelper.JoinableTaskFactory.RunAsync(SnykTasksService.Instance.ScanAsync);
protected override void Execute(object sender, EventArgs eventArgs)
{
base.Execute(sender, eventArgs);
ThreadHelper.JoinableTaskFactory.RunAsync(SnykTasksService.Instance.ScanAsync);
}

/// <summary>
/// Get command Id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public override async Task UpdateStateAsync()
/// </summary>
/// <param name="sender">Source object.</param>
/// <param name="eventArgs">Event args.</param>
protected override void Execute(object sender, EventArgs eventArgs) => SnykTasksService.Instance.CancelTasks();
protected override void Execute(object sender, EventArgs eventArgs)
{
base.Execute(sender, eventArgs);
SnykTasksService.Instance.CancelTasks();
}

/// <summary>
/// Get command Id.
Expand Down
Loading

0 comments on commit 093a722

Please sign in to comment.