Skip to content

Commit

Permalink
fix: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Nov 13, 2024
1 parent 154647c commit 0bc72d0
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Snyk.Common/Settings/ISnykOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface ISnykOptions

string DeviceId { get; set; }
bool AutoScan { get; set; }

bool ConsistentIgnoresEnabled { get; set; }

/// <summary>
/// Gets or sets a value indicating whether Snyk user API token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public interface ILanguageClientManager
event AsyncEventHandler<SnykLanguageServerEventArgs> OnLanguageClientNotInitializedAsync;
void FireOnLanguageClientNotInitializedAsync();
Task InvokeReportAnalyticsAsync(IAbstractAnalyticsEvent analyticsEvent, CancellationToken cancellationToken);
Task<string> InvokeGetFeatureFlagStatusAsync(string featureFlagName, CancellationToken cancellationToken);
}
}
5 changes: 4 additions & 1 deletion Snyk.VisualStudio.Extension.2022/Language/LsConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public static class LsConstants
{
public const string ProtocolVersion = "16";
public const string ProtocolVersion = "17";

// Notifications
public const string SnykHasAuthenticated = "$/snyk.hasAuthenticated";
Expand All @@ -28,5 +28,8 @@ public static class LsConstants
public const string SnykGetFeatureFlagStatus = "snyk.getFeatureFlagStatus";
public const string SnykGenerateIssueDescription = "snyk.generateIssueDescription";
public const string SnykReportAnalytics = "snyk.reportAnalytics";

// Feature flags
public const string SnykConsistentIgnoresEnabled = "snykCodeConsistentIgnores";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;
Expand Down Expand Up @@ -405,15 +406,14 @@ public async Task<string> InvokeGenerateIssueDescriptionAsync(string issueId, Ca
return result;
}

public async Task<object> InvokeGetFeatureFlagStatus(string featureFlag, CancellationToken cancellationToken)
public async Task<string> InvokeGetFeatureFlagStatusAsync(string featureFlag, CancellationToken cancellationToken)
{
var param = new LSP.ExecuteCommandParams
{
Command = LsConstants.SnykGetFeatureFlagStatus,
Arguments = new object[] { featureFlag }
};
var featureFlagStatus = await InvokeWithParametersAsync<object>(LsConstants.WorkspaceExecuteCommand, param, cancellationToken);
return featureFlagStatus;
return await InvokeWithParametersAsync<string>(LsConstants.WorkspaceExecuteCommand, param, cancellationToken);
}

public async Task InvokeReportAnalyticsAsync(IAbstractAnalyticsEvent analyticsEvent, CancellationToken cancellationToken)
Expand Down
29 changes: 29 additions & 0 deletions Snyk.VisualStudio.Extension.2022/Service/FeatureFlagService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Threading.Tasks;
using Serilog;
using Snyk.Common;
using Snyk.Common.Settings;
using Snyk.VisualStudio.Extension.Language;

namespace Snyk.VisualStudio.Extension.Service;

public class FeatureFlagService(ILanguageClientManager languageClient, ISnykOptions settings)
{
private readonly ILogger logger = LogManager.ForContext<FeatureFlagService>();

public async Task OnLanguageServerReadyAsync(object sender, SnykLanguageServerEventArgs args)
{
var result = await languageClient.InvokeGetFeatureFlagStatusAsync(LsConstants.SnykGetFeatureFlagStatus, SnykVSPackage.Instance.DisposalToken);
var response = Json.Deserialize<FeatureFlagResponse>(result);
settings.ConsistentIgnoresEnabled = response.Ok;
if (!response.Ok)
{
if (!response.UserMessage.IsNullOrEmpty()) this.logger.Error("feature flag not enabled: {UserMessage}", response.UserMessage);
}
}

private class FeatureFlagResponse
{
public bool Ok { get; set; }
public string UserMessage { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public ISet<string> TrustedFolders
/// </summary>
public ISnykServiceProvider ServiceProvider => this.serviceProvider;

public bool ConsistentIgnoresEnabled
{
get => this.userStorageSettingsService.ConsistentIgnoresEnabled;
set => this.userStorageSettingsService.ConsistentIgnoresEnabled = value;
}

/// <summary>
/// Gets or sets a value indicating whether API token.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Snyk.VisualStudio.Extension.2022/Settings/SnykSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ public SnykSettings()
public string Organization { get; set; }
public string CustomEndpoint { get; set; }
public string DeviceId { get; set; }
public bool ConsistentIgnoresEnabled { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public string DeviceId
public bool AnalyticsPluginInstalledSent
{ get; set; }

public bool ConsistentIgnoresEnabled { get => snykSettings.ConsistentIgnoresEnabled;
set => snykSettings.ConsistentIgnoresEnabled = value; }

/// <summary>
/// Get is all projects enabled.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Compile Include="Service\Domain\FeaturesSettings.cs" />
<Compile Include="Service\FeatureFlagService.cs" />
<Compile Include="Service\ISnykProgressWorker.cs" />
<Compile Include="Service\ISnykService.cs" />
<Compile Include="Service\ISnykServiceProvider.cs" />
Expand Down
2 changes: 2 additions & 0 deletions Snyk.VisualStudio.Extension.2022/SnykVSPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ private async Task InitializeLanguageClientAsync()
LanguageClientManager = languageServerClientManager;
LanguageClientManager.OnLanguageClientNotInitializedAsync += LanguageClientManagerOnOnLanguageClientNotInitializedAsync;
LanguageClientManager.OnLanguageServerReadyAsync += LanguageClientManagerOnOnLanguageServerReadyAsync;
FeatureFlagService featureFlagService = new FeatureFlagService(LanguageClientManager, Options);
LanguageClientManager.OnLanguageServerReadyAsync += featureFlagService.OnLanguageServerReadyAsync;
if (languageServerClientManager != null && !languageServerClientManager.IsReady)
{
// If CLI download is necessary, Skip initializing.
Expand Down

0 comments on commit 0bc72d0

Please sign in to comment.