Skip to content

Commit

Permalink
feat: LSP integration in VS2022 (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawkyZ authored Sep 3, 2024
1 parent e4b3568 commit 385f104
Show file tree
Hide file tree
Showing 60 changed files with 1,871 additions and 976 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set VSIX version for 2022
uses: cezarypiatek/VsixVersionAction@1.0
with:
version: ${{ steps.vsix_version.outputs.next-tag }}
version: ${{ steps.vsix_version.outputs.next-tag }}-preview
vsix-manifest-file: .\Snyk.VisualStudio.Extension.2022\source.extension.vsixmanifest
- name: Check if secrets exist
env:
Expand Down
48 changes: 20 additions & 28 deletions Snyk.Code.Library/Domain/Analysis/Suggestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,96 +38,88 @@ public Suggestion(string fileName, SuggestionDto suggestionDto, FileDto fileDto)
}).ToList();
}

public Suggestion()
{

}
/// <summary>
/// Gets a value indicating analysis suggestion id. Id for this (local) result.
/// </summary>
public string Id { get; }
public string Id { get; set; }

/// <summary>
/// Gets tuple of rows.
/// </summary>
public Tuple<int, int> Rows { get; }
public Tuple<int, int> Rows { get; set; }

/// <summary>
/// Gets tuple of columns.
/// </summary>
public Tuple<int, int> Columns { get; }
public Tuple<int, int> Columns { get; set; }

/// <summary>
/// Gets a value indicating analysis rule.
/// </summary>
public string Rule { get; }
public string Rule { get; set; }

/// <summary>
/// Gets a value indicating suggestion message.
/// </summary>
public string Message { get; }
public string Message { get; set; }

/// <summary>
/// Gets file name (relative path).
/// </summary>
public string FileName { get; }
public string FileName { get; set; }

/// <summary>
/// Gets a value indicating analysis severity value (from 1 to 4).
/// </summary>
public int Severity { get; }
public int Severity { get; set; }

/// <summary>
/// Gets position markers.
/// </summary>
public IList<Marker> Markers { get; }
public IList<Marker> Markers { get; set; }

/// <summary>
/// Gets a value indicating analysis categories.
/// </summary>
public IList<string> Categories { get; }
public IList<string> Categories { get; set; }

/// <summary>
/// Gets a value indicating analysis tags.
/// </summary>
public IList<string> Tags { get; }
public IList<string> Tags { get; set; }

/// <summary>
/// Gets a value indicating suggestion title.
/// </summary>
public string Title { get; }
public string Title { get; set; }

/// <summary>
/// Gets repo dataset size.
/// </summary>
public int RepoDatasetSize { get; }
public int RepoDatasetSize { get; set; }

/// <summary>
/// Gets a value indicating analysis CWE list.
/// </summary>
public IList<string> Cwe { get; }
public IList<string> Cwe { get; set; }

/// <summary>
/// Gets a value indicating suggestion description.
/// </summary>
public string Text { get; }
public string Text { get; set; }

/// <summary>
/// Gets a value indicating suggestion examples.
/// </summary>
public IList<string> ExampleCommitDescriptions { get; }
public IList<string> ExampleCommitDescriptions { get; set; }

/// <summary>
/// Gets a value indicating suggestion list of proposed fixes and examples.
/// </summary>
public IList<SuggestionFix> Fixes { get; } = new List<SuggestionFix>();

/// <summary>
/// Get row line and title (if title is null it use message).
/// </summary>
/// <returns>Title for display.</returns>
public string GetDisplayTitleWithLineNumber() => "line " + this.Rows.Item1 + ": " + this.GetDisplayTitle();

/// <summary>
/// Get title. If title is null or empty it will return message as title.
/// </summary>
/// <returns>Title for display.</returns>
public string GetDisplayTitle() => string.IsNullOrEmpty(this.Title) ? this.Message : this.Title;
public IList<SuggestionFix> Fixes { get; set; } = new List<SuggestionFix>();
}
}
12 changes: 11 additions & 1 deletion Snyk.Common/Service/SastSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
namespace Snyk.Common.Service
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Snyk.Common.Service
{
/// <summary>
/// Sast settings.
/// </summary>
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class SastSettings
{
/// <summary>
Expand All @@ -20,6 +25,11 @@ public class SastSettings
/// Snyk Code enabled if SastEnabled = true and LocalCodeEngine.Enabled = false.
/// </summary>
public bool SnykCodeEnabled => this.SastEnabled;

public string Org { get; set; }
public IList<string> SupportedLanguages { get; set; }
public bool ReportFalsePositivesEnabled { get; set; }
public bool AutofixEnabled { get; set; }
/// <summary>
/// Gets a value indicating whether local code engine enabled/disabled.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Snyk.VisualStudio.Extension.2022/CLI/CLIResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public List<CliGroupedVulnerabilities> GroupVulnerabilities
}

/// <summary>
/// Gets or sets a value indicating whether instance of <see cref="CliError"/>.
/// Gets or sets a value indicating whether instance of <see cref="OssError"/>.
/// </summary>
public CliError Error { get; set; }
public OssError Error { get; set; }

/// <summary>
/// Check is response successfull or there is an error.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Snyk.VisualStudio.Extension.CLI
using Snyk.VisualStudio.Extension.Language;
using System.Collections.Generic;

namespace Snyk.VisualStudio.Extension.CLI
{
using System.Collections.Generic;

/// <summary>
/// Grouped CLI vulnerabilities.
Expand All @@ -10,7 +12,7 @@ public class CliGroupedVulnerabilities
/// <summary>
/// Gets or sets a value indicating whether vulnerabilities dictionary.
/// </summary>
public Dictionary<string, List<Vulnerability>> VulnerabilitiesMap { get; set; }
public Dictionary<string, List<Issue>> VulnerabilitiesMap { get; set; }

/// <summary>
/// Gets or sets a value indicating whether unique vulnerabilities count.
Expand Down
2 changes: 1 addition & 1 deletion Snyk.VisualStudio.Extension.2022/CLI/CliVulnerabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public CliGroupedVulnerabilities ToGroupedVulnerabilities()

return new CliGroupedVulnerabilities
{
VulnerabilitiesMap = vulnerabilitiesDictionary,
//VulnerabilitiesMap = vulnerabilitiesDictionary,
UniqueCount = uniqueCount,
PathsCount = pathsCount,
ProjectName = this.ProjectName,
Expand Down
60 changes: 18 additions & 42 deletions Snyk.VisualStudio.Extension.2022/CLI/Download/SnykCliDownloader.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
namespace Snyk.VisualStudio.Extension.CLI.Download
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Serilog;
using Snyk.Common;
using Snyk.VisualStudio.Extension.Service;

namespace Snyk.VisualStudio.Extension.CLI.Download
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Serilog;
using Snyk.Common;
using Snyk.VisualStudio.Extension.Service;

/// <summary>
/// Donwnload last Snyk CLI version.
/// </summary>
public class SnykCliDownloader
{
private const string BaseUrl = "https://static.snyk.io";
private const string LatestReleaseVersionUrl = BaseUrl + "/cli/latest/version";
private const string LatestReleaseDownloadUrl = BaseUrl + "/cli/latest/{0}";
private const string Sha256DownloadUrl = BaseUrl + "/cli/latest/snyk-win.exe.sha256";
private const string BaseUrl = "https://downloads.snyk.io";

private const string ReleaseChannel = "preview";
private const string LatestReleaseVersionUrl = BaseUrl + "/cli/"+ReleaseChannel+"/version";
private const string LatestReleaseDownloadUrl = BaseUrl + "/cli/"+ReleaseChannel+"/{0}";
private const string Sha256DownloadUrl = BaseUrl + "/cli/"+ReleaseChannel+"/snyk-win.exe.sha256";

private const int FourDays = 4;

Expand All @@ -44,7 +46,7 @@ public class SnykCliDownloader
/// </summary>
/// <param name="customCliPath">The custom CLI path from the settings.</param>
/// <returns>If <paramref name="customCliPath"/> is null or empty, the default path would be returned.</returns>
private static string GetCliFilePath(string customCliPath) => string.IsNullOrEmpty(customCliPath)
public static string GetCliFilePath(string customCliPath) => string.IsNullOrEmpty(customCliPath)
? SnykCli.GetSnykCliDefaultPath()
: customCliPath;

Expand Down Expand Up @@ -92,31 +94,6 @@ public string GetLatestCliSha()
}
}

/// <summary>
/// Compare CLI versions and if new version string is more new to current version method will return true.
/// </summary>
/// <param name="currentVersionStr">Current CLI version.</param>
/// <param name="newVersionStr">New CLI version.</param>
/// <returns>True if there is more new version.</returns>
public bool IsNewVersionAvailable(string currentVersionStr, string newVersionStr)
{
int newVersion = this.CliVersionAsInt(newVersionStr);

if (newVersion == -1)
{
return false;
}

int currentVersion = this.CliVersionAsInt(currentVersionStr);

if (currentVersion == -1)
{
return true;
}

return newVersion > currentVersion;
}

/// <summary>
/// Check is four days passed after lact check.
/// </summary>
Expand Down Expand Up @@ -155,8 +132,7 @@ public bool IsCliDownloadNeeded(DateTime lastCheckDate, string cliFileDestinatio
/// </summary>
/// <param name="lastCheckDate">Last check date.</param>
/// <returns>True if new version CLI exists</returns>
public bool IsCliUpdateExists(DateTime lastCheckDate) => this.IsFourDaysPassedAfterLastCheck(lastCheckDate)
&& this.IsNewVersionAvailable(this.currentCliVersion, this.GetLatestReleaseInfo().Version);
public bool IsCliUpdateExists(DateTime lastCheckDate) => this.IsFourDaysPassedAfterLastCheck(lastCheckDate);

/// <summary>
/// Check is there a new version on the server and if there is, download it.
Expand Down
21 changes: 0 additions & 21 deletions Snyk.VisualStudio.Extension.2022/CLI/Dto/Identifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,5 @@
/// <summary>
/// Vulnerability identifiers.
/// </summary>
public class Identifiers
{
/// <summary>
/// Gets or sets Cve identifiers.
/// </summary>
public string[] CVE { get; set; }

/// <summary>
/// Gets or sets Cwe identifiers.
/// </summary>
public string[] CWE { get; set; }

/// <summary>
/// Gets or sets Ghsa identifiers.
/// </summary>
public string[] GHSA { get; set; }

/// <summary>
/// Gets or sets Rhsa identifiers.
/// </summary>
public string[] RHSA { get; set; }
}
}
1 change: 1 addition & 0 deletions Snyk.VisualStudio.Extension.2022/CLI/ICli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ public interface ICli

string RunCommand(string basePath);
Task ReportAnalyticsAsync(string data);
string GetCliPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
/// <summary>
/// Snyk Open source error object.
/// </summary>
public class CliError
public class OssError
{
/// <summary>
/// Initializes a new instance of the <see cref="CliError"/> class.
/// Initializes a new instance of the <see cref="OssError"/> class.
/// </summary>
public CliError() { }
public OssError() { }

/// <summary>
/// Initializes a new instance of the <see cref="CliError"/> class.
/// Initializes a new instance of the <see cref="OssError"/> class.
/// </summary>
/// <param name="message">Error message string.</param>
public CliError(string message) => this.Message = message;
public OssError(string message) => this.Message = message;

/// <summary>
/// Gets or sets a value indicating whether is success. In Json it's "ok" property.
Expand Down
8 changes: 4 additions & 4 deletions Snyk.VisualStudio.Extension.2022/CLI/SnykCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public async Task ReportAnalyticsAsync(string data)
if (result.Length > 0) Logger.Warning("ReportAnalyticsAsync: Unexpected output: {Result}", result);
}

private string GetCliPath()
public string GetCliPath()
{
var snykCliCustomPath = this.options?.CliCustomPath;
var cliPath = string.IsNullOrEmpty(snykCliCustomPath) ? GetSnykCliDefaultPath() : snykCliCustomPath;
Expand Down Expand Up @@ -305,7 +305,7 @@ private async Task AddGeneralArgsFromConfigAsync(ICollection<string> arguments)
/// Convert raw json string to <see cref="CliResult"/> object.
/// Check is json object is array. If it's array of cli vulnerability objects it will create <see cref="CliVulnerabilities"/> list.
/// If json string is single object it will create <see cref="CliVulnerabilities"/> object.
/// If json string is error it will create <see cref="CliError"/> object.
/// If json string is error it will create <see cref="OssError"/> object.
/// </summary>
/// <param name="rawResult">Json string.</param>
/// <returns>Result <see cref="CliResult"/> object.</returns>
Expand Down Expand Up @@ -335,15 +335,15 @@ public static CliResult ConvertRawCliStringToCliResult(string rawResult)
{
return new CliResult
{
Error = Json.Deserialize<CliError>(rawResult),
Error = Json.Deserialize<OssError>(rawResult),
};
}
}
else
{
return new CliResult
{
Error = new CliError
Error = new OssError
{
IsSuccess = false,
Message = rawResult,
Expand Down
4 changes: 3 additions & 1 deletion Snyk.VisualStudio.Extension.2022/CLI/Vulnerability.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Snyk.VisualStudio.Extension.CLI
using Snyk.VisualStudio.Extension.Language;

namespace Snyk.VisualStudio.Extension.CLI
{
using System;

Expand Down
Loading

0 comments on commit 385f104

Please sign in to comment.