Skip to content

Commit 28eade1

Browse files
authored
fix: high dpi svg scaling (#311)
* fix: high dpi svg scaling * chore: added comments * chore: set DPI aware on init * fix: folder trust on init * fix: send config to ls when folder trusted * refactor: move GetCliFilePath to SnykCli
1 parent a7a68dc commit 28eade1

14 files changed

+382
-58
lines changed

Snyk.Common/Settings/ISnykOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ public interface ISnykOptions
106106
SastSettings SastSettings { get; set; }
107107
Task OnAuthenticationSuccessfulAsync(string token);
108108
Task OnAuthenticationFailedAsync(string errorMessage);
109+
void FireSettingsChangedEvent();
109110
}
110111
}

Snyk.VisualStudio.Extension.2022/CLI/SnykCli.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,21 @@ public string GetCliPath()
5858
var cliPath = string.IsNullOrEmpty(snykCliCustomPath) ? GetSnykCliDefaultPath() : snykCliCustomPath;
5959
return cliPath;
6060
}
61+
62+
/// <summary>
63+
/// Gets the valid CLI path. When a custom CLI path is specified, it returns the custom path.
64+
/// When the Custom CLI path is null or empty, it returns the default CLI path.
65+
/// </summary>
66+
/// <param name="customCliPath">The custom CLI path from the settings.</param>
67+
/// <returns>If <paramref name="customCliPath"/> is null or empty, the default path would be returned.</returns>
68+
public static string GetCliFilePath(string customCliPath) => string.IsNullOrEmpty(customCliPath)
69+
? SnykCli.GetSnykCliDefaultPath()
70+
: customCliPath;
71+
72+
public static bool IsCliFileFound(string cliCustomPath)
73+
{
74+
var path = GetCliFilePath(cliCustomPath);
75+
return File.Exists(path);
76+
}
6177
}
6278
}

Snyk.VisualStudio.Extension.2022/Download/SnykCliDownloader.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,6 @@ public SnykCliDownloader(ISnykOptions snykOptions)
3939
/// </summary>
4040
public delegate void CliDownloadFinishedCallback();
4141

42-
/// <summary>
43-
/// Gets the valid CLI path. When a custom CLI path is specified, it returns the custom path.
44-
/// When the Custom CLI path is null or empty, it returns the default CLI path.
45-
/// </summary>
46-
/// <param name="customCliPath">The custom CLI path from the settings.</param>
47-
/// <returns>If <paramref name="customCliPath"/> is null or empty, the default path would be returned.</returns>
48-
public static string GetCliFilePath(string customCliPath) => string.IsNullOrEmpty(customCliPath)
49-
? SnykCli.GetSnykCliDefaultPath()
50-
: customCliPath;
51-
52-
53-
public static bool IsCliFileFound(string cliCustomPath)
54-
{
55-
var path = GetCliFilePath(cliCustomPath);
56-
return File.Exists(path);
57-
}
5842

5943
/// <summary>
6044
/// Request last cli information.
@@ -157,7 +141,7 @@ public async Task AutoUpdateCliAsync(ISnykProgressWorker progressWorker,
157141
string filePath = null,
158142
List<CliDownloadFinishedCallback> downloadFinishedCallbacks = null)
159143
{
160-
var fileDestinationPath = GetCliFilePath(filePath);
144+
var fileDestinationPath = SnykCli.GetCliFilePath(filePath);
161145

162146
var isCliDownloadNeeded = this.IsCliDownloadNeeded(fileDestinationPath);
163147

@@ -188,7 +172,7 @@ public async Task DownloadAsync(
188172
{
189173
Logger.Information("Enter Download method");
190174

191-
var cliFileDestinationPath = GetCliFilePath(fileDestinationPath);
175+
var cliFileDestinationPath = SnykCli.GetCliFilePath(fileDestinationPath);
192176

193177
Logger.Information("CLI File Destination Path: {Path}", cliFileDestinationPath);
194178

Snyk.VisualStudio.Extension.2022/Language/SnykLanguageClient.cs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Task = System.Threading.Tasks.Task;
1818
using LSP = Microsoft.VisualStudio.LanguageServer.Protocol;
1919
using Process = System.Diagnostics.Process;
20+
using Snyk.VisualStudio.Extension.Download;
2021

2122
namespace Snyk.VisualStudio.Extension.Language
2223
{
@@ -26,8 +27,7 @@ namespace Snyk.VisualStudio.Extension.Language
2627
public partial class SnykLanguageClient : ILanguageClient, ILanguageClientCustomMessage2, ILanguageClientManager
2728
{
2829
private static readonly ILogger Logger = LogManager.ForContext<SnykLanguageClient>();
29-
private object _lock = new object();
30-
30+
private SemaphoreSlim Semaphore = new SemaphoreSlim(1,1);
3131
private SnykLsInitializationOptions initializationOptions;
3232

3333
[ImportingConstructor]
@@ -65,7 +65,7 @@ public object GetInitializationOptions()
6565
ActivateSnykIac = options.IacEnabled.ToString(),
6666
SendErrorReports = "true",
6767
ManageBinariesAutomatically = options.BinariesAutoUpdate.ToString(),
68-
EnableTrustedFoldersFeature = "true",
68+
EnableTrustedFoldersFeature = "false",
6969
TrustedFolders = options.TrustedFolders.ToList(),
7070
IntegrationName = options.IntegrationName,
7171
FilterSeverity = new FilterSeverityOptions
@@ -80,7 +80,7 @@ public object GetInitializationOptions()
8080
AdditionalParams = ThreadHelper.JoinableTaskFactory.Run(() => options.GetAdditionalOptionsAsync()),
8181
#pragma warning restore VSTHRD104
8282
AuthenticationMethod = options.AuthenticationMethod == AuthenticationType.OAuth ? "oauth" : "token",
83-
CliPath = options.CliCustomPath,
83+
CliPath = SnykCli.GetCliFilePath(options.CliCustomPath),
8484
Organization = options.Organization,
8585
Token = options.ApiToken.ToString(),
8686
AutomaticAuthentication = "false",
@@ -125,7 +125,7 @@ public async Task<Connection> ActivateAsync(CancellationToken token)
125125
#endif
126126
var info = new ProcessStartInfo
127127
{
128-
FileName = string.IsNullOrEmpty(options.CliCustomPath) ? SnykCli.GetSnykCliDefaultPath() : options.CliCustomPath,
128+
FileName = SnykCli.GetCliFilePath(options.CliCustomPath),
129129
Arguments = "language-server -l "+ lsDebugLevel,
130130
RedirectStandardInput = true,
131131
RedirectStandardOutput = true,
@@ -164,25 +164,35 @@ public async Task OnLoadedAsync()
164164

165165
public async Task StartServerAsync(bool shouldStart = false)
166166
{
167-
if (StartAsync == null && shouldStart)
168-
{
169-
FireOnLanguageClientNotInitializedAsync();
170-
return;
171-
}
172-
if (StartAsync != null && SnykVSPackage.Instance?.Options != null && shouldStart)
167+
await Semaphore.WaitAsync();
168+
try
173169
{
174-
if (CustomMessageTarget == null)
170+
if (StartAsync == null && shouldStart)
175171
{
176-
CustomMessageTarget = new SnykLanguageClientCustomTarget(SnykVSPackage.ServiceProvider);
172+
FireOnLanguageClientNotInitializedAsync();
173+
return;
174+
}
175+
176+
if (StartAsync != null && SnykVSPackage.Instance?.Options != null && shouldStart)
177+
{
178+
if (CustomMessageTarget == null)
179+
{
180+
CustomMessageTarget = new SnykLanguageClientCustomTarget(SnykVSPackage.ServiceProvider);
181+
}
182+
183+
Logger.Information("Starting Language Server");
184+
await StartAsync.InvokeAsync(this, EventArgs.Empty);
185+
IsReady = true;
186+
FireOnLanguageServerReadyAsyncEvent();
187+
}
188+
else
189+
{
190+
Logger.Debug("Couldn't Start Language Server");
177191
}
178-
Logger.Information("Starting Language Server");
179-
await StartAsync.InvokeAsync(this, EventArgs.Empty);
180-
IsReady = true;
181-
FireOnLanguageServerReadyAsyncEvent();
182192
}
183-
else
193+
finally
184194
{
185-
Logger.Debug("Couldn't Start Language Server");
195+
Semaphore.Release();
186196
}
187197
}
188198

Snyk.VisualStudio.Extension.2022/Service/SnykTasksService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ public async Task<bool> IsFolderTrustedAsync()
307307
try
308308
{
309309
this.serviceProvider.WorkspaceTrustService.AddFolderToTrusted(solutionFolderPath);
310+
this.serviceProvider.Options.FireSettingsChangedEvent();
310311
Logger.Information("Workspace folder was trusted: {SolutionFolderPath}", solutionFolderPath);
311312
return true;
312313
}
@@ -736,7 +737,7 @@ public bool ShouldDownloadCli()
736737
{
737738
var options = this.serviceProvider.Options;
738739
var cliDownloader = new SnykCliDownloader(options);
739-
var fileDestinationPath = GetCliFilePath(options.CliCustomPath);
740+
var fileDestinationPath = SnykCli.GetCliFilePath(options.CliCustomPath);
740741

741742
return cliDownloader.IsCliDownloadNeeded(fileDestinationPath);
742743

Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralOptionsDialogPage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using Snyk.Common.Authentication;
1111
using Snyk.Common.Service;
1212
using Snyk.Common.Settings;
13-
using Snyk.VisualStudio.Extension.Download;
13+
using Snyk.VisualStudio.Extension.CLI;
1414
using Snyk.VisualStudio.Extension.Language;
1515
using Snyk.VisualStudio.Extension.Service;
1616

@@ -417,7 +417,7 @@ public void Initialize(ISnykServiceProvider provider)
417417
public void Authenticate()
418418
{
419419
Logger.Information("Enter Authenticate method");
420-
if (!SnykCliDownloader.IsCliFileFound(this.CliCustomPath))
420+
if (!SnykCli.IsCliFileFound(this.CliCustomPath))
421421
{
422422
ThrowFileNotFoundException();
423423
}
@@ -453,7 +453,7 @@ await ServiceProvider.Package.LanguageClientManager.InvokeLogin(SnykVSPackage.In
453453
}
454454
}
455455

456-
private void FireSettingsChangedEvent() => this.SettingsChanged?.Invoke(this, new SnykSettingsChangedEventArgs());
456+
public void FireSettingsChangedEvent() => this.SettingsChanged?.Invoke(this, new SnykSettingsChangedEventArgs());
457457

458458
public string GetCustomApiEndpoint()
459459
{

Snyk.VisualStudio.Extension.2022/Settings/SnykGeneralSettingsUserControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private async Task AuthenticateButtonClickAsync()
216216

217217
var serviceProvider = this.ServiceProvider;
218218

219-
if (SnykCliDownloader.IsCliFileFound(serviceProvider.Options.CliCustomPath))
219+
if (SnykCli.IsCliFileFound(serviceProvider.Options.CliCustomPath))
220220
{
221221
serviceProvider.Options.Authenticate();
222222
}

Snyk.VisualStudio.Extension.2022/Snyk.VisualStudio.Extension.2022.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
<Compile Include="UI\Toolwindow\ToolWindowContext.cs" />
197197
<Compile Include="UI\Toolwindow\ToolWindowState.cs" />
198198
<Compile Include="UI\Toolwindow\UpdateDownloadState.cs" />
199+
<Compile Include="UI\Toolwindow\WebBrowserHostUIHandler.cs" />
199200
<Compile Include="UI\Tree\OssRootTreeNode.cs" />
200201
<Compile Include="UI\Tree\OssVulnerabilityTreeNode.cs" />
201202
<Compile Include="UI\Tree\RootTreeNode.cs" />

Snyk.VisualStudio.Extension.2022/UI/Html/CodeHtmlProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ .summary .label {
8989
background-color: var(--line-removed);
9090
color: #fff;
9191
}
92-
92+
.lesson-link {
93+
margin-left: 3px;
94+
}
9395
.added {
9496
background-color: var(--line-added);
9597
color: #fff;

Snyk.VisualStudio.Extension.2022/UI/Toolwindow/HtmlDescriptionPanel.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
mc:Ignorable="d"
1010
d:DesignHeight="450" d:DesignWidth="800">
1111
<Grid>
12-
<WindowsFormsHost Name="windowsFormsHost" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
12+
<WebBrowser Name="HtmlViewer" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
1313
</Grid>
1414
</UserControl>

0 commit comments

Comments
 (0)