Skip to content

CM-48120 - Add detection sorting by line number in addition to severity #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [Unreleased]

## [1.10.0] - 2025-05-14

- Add detection sorting by line number in addition to severity

## [1.9.0] - 2025-02-24

- Add tree view filtering by severity
Expand Down Expand Up @@ -85,6 +89,8 @@

The first public release of the extension.

[1.10.0]: https://github.com/cycodehq/visual-studio-extension/releases/tag/v1.10.0

[1.9.0]: https://github.com/cycodehq/visual-studio-extension/releases/tag/v1.9.0

[1.8.0]: https://github.com/cycodehq/visual-studio-extension/releases/tag/v1.8.0
Expand Down Expand Up @@ -119,4 +125,4 @@ The first public release of the extension.

[1.0.0]: https://github.com/cycodehq/visual-studio-extension/releases/tag/v1.0.0

[Unreleased]: https://github.com/cycodehq/visual-studio-extension/compare/v1.9.0...HEAD
[Unreleased]: https://github.com/cycodehq/visual-studio-extension/compare/v1.10.0...HEAD
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.404",
"rollForward": "latestFeature"
"version": "8.0.408",
"rollForward": "disable"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Cycode.7e1a0714-9b3b-4e0e-9c0a-d23fb20ab86e" Version="1.9.0" Language="en-US" Publisher="cycodehq" />
<Identity Id="Cycode.7e1a0714-9b3b-4e0e-9c0a-d23fb20ab86e" Version="1.10.0" Language="en-US" Publisher="cycodehq" />
<DisplayName>Cycode</DisplayName>
<Description xml:space="preserve">Cycode for Visual Studio IDE</Description>
<MoreInfo>https://github.com/cycodehq/visual-studio-extension</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Cycode.f2c5020e-67a2-46f8-a888-609412fd59db" Version="1.9.0" Language="en-US" Publisher="cycodehq" />
<Identity Id="Cycode.f2c5020e-67a2-46f8-a888-609412fd59db" Version="1.10.0" Language="en-US" Publisher="cycodehq" />
<DisplayName>Cycode</DisplayName>
<Description xml:space="preserve">Cycode for Visual Studio IDE</Description>
<MoreInfo>https://github.com/cycodehq/visual-studio-extension</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public abstract class DetectionDetailsBase {
public abstract string GetFilePath();
// This method returns a 1-indexed line number
public abstract int GetLineNumber();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public override string GetFormattedTitle() {
}

public override string GetFormattedNodeTitle() {
return $"line {DetectionDetails.LineInFile + 1}: {GetFormattedMessage()}";
return $"line {DetectionDetails.GetLineNumber()}: {GetFormattedMessage()}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public class IacDetectionDetails : DetectionDetailsBase {
public override string GetFilePath() {
return FileName;
}

public override int GetLineNumber() {
return LineInFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public override string GetFormattedTitle() {
}

public override string GetFormattedNodeTitle() {
return $"line {DetectionDetails.LineInFile}: {GetFormattedMessage()}";
return $"line {DetectionDetails.GetLineNumber()}: {GetFormattedMessage()}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public class SastDetectionDetails : DetectionDetailsBase {
public override string GetFilePath() {
return FilePath;
}

public override int GetLineNumber() {
return LineInFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public override string GetFormattedTitle() {
}

public override string GetFormattedNodeTitle() {
return $"line {DetectionDetails.LineInFile}: {GetFormattedTitle()}";
return $"line {DetectionDetails.GetLineNumber()}: {GetFormattedTitle()}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public class ScaDetectionDetails : DetectionDetailsBase {
public override string GetFilePath() {
return FileName;
}

public override int GetLineNumber() {
return LineInFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public override string GetFormattedTitle() {
}

public override string GetFormattedNodeTitle() {
return $"line {DetectionDetails.Line + 1}: a hardcoded {Type} is used";
return $"line {DetectionDetails.GetLineNumber()}: a hardcoded {Type} is used";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public class SecretDetectionDetails : DetectionDetailsBase {
public override string GetFilePath() {
return $"{FilePath}{FileName}";
}

public override int GetLineNumber() {
return Line + 1; // 1-indexed
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
case SecretDetectionNode secretDetectionNode: {
SecretDetection detection = secretDetectionNode.Detection;
filePath = detection.DetectionDetails.GetFilePath();
line = detection.DetectionDetails.Line + 1;
line = detection.DetectionDetails.GetLineNumber();
_toolWindowMessengerService.Send(
new MessageEventArgs(MessengerCommand.LoadSecretViolationCardControl, detection)
);
Expand All @@ -53,7 +53,7 @@ private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
case ScaDetectionNode scaDetectionNode: {
ScaDetection detection = scaDetectionNode.Detection;
filePath = detection.DetectionDetails.GetFilePath();
line = detection.DetectionDetails.LineInFile;
line = detection.DetectionDetails.GetLineNumber();
_toolWindowMessengerService.Send(
new MessageEventArgs(MessengerCommand.LoadScaViolationCardControl, detection)
);
Expand All @@ -62,7 +62,7 @@ private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
case IacDetectionNode iacDetectionNode: {
IacDetection detection = iacDetectionNode.Detection;
filePath = detection.DetectionDetails.GetFilePath();
line = detection.DetectionDetails.LineInFile + 1;
line = detection.DetectionDetails.GetLineNumber();
_toolWindowMessengerService.Send(
new MessageEventArgs(MessengerCommand.LoadIacViolationCardControl, detection)
);
Expand All @@ -71,7 +71,7 @@ private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
case SastDetectionNode sastDetectionNode: {
SastDetection detection = sastDetectionNode.Detection;
filePath = detection.DetectionDetails.GetFilePath();
line = detection.DetectionDetails.LineInFile;
line = detection.DetectionDetails.GetLineNumber();
_toolWindowMessengerService.Send(
new MessageEventArgs(MessengerCommand.LoadSastViolationCardControl, detection)
);
Expand Down Expand Up @@ -144,14 +144,11 @@ Func<DetectionBase, BaseNode> createNodeCallback
List<DetectionBase> severityFilteredDetections = detections
.Where(detection => !enabledSeverityFilters.Contains(detection.Severity.ToLower()))
.ToList();
List<DetectionBase> sortedDetections = severityFilteredDetections
.OrderByDescending(detection => GetSeverityWeight(detection.Severity))
.ToList();
IEnumerable<IGrouping<string, DetectionBase>> detectionsByFile =
sortedDetections.GroupBy(detection => detection.GetDetectionDetails().GetFilePath());
severityFilteredDetections.GroupBy(detection => detection.GetDetectionDetails().GetFilePath());

ScanTypeNode scanTypeNode = RootNodesManager.GetScanTypeNode(scanType);
scanTypeNode.Summary = GetRootNodeSummary(sortedDetections);
scanTypeNode.Summary = GetRootNodeSummary(severityFilteredDetections);

foreach (IGrouping<string, DetectionBase> detectionsInFile in detectionsByFile) {
string filePath = detectionsInFile.Key;
Expand All @@ -162,7 +159,12 @@ Func<DetectionBase, BaseNode> createNodeCallback
Icon = ExtensionIcons.GetFileIconPath(filePath)
};

foreach (DetectionBase detection in detectionsInFile) fileNode.Items.Add(createNodeCallback(detection));
List<DetectionBase> sortedDetectionsInFile = detectionsInFile
.OrderByDescending(detection => GetSeverityWeight(detection.Severity))
.ThenBy(detection => detection.GetDetectionDetails().GetLineNumber())
.ToList();

foreach (DetectionBase detection in sortedDetectionsInFile) fileNode.Items.Add(createNodeCallback(detection));

scanTypeNode.Items.Add(fileNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static List<ErrorTask> CreateErrorTasks(List<IacDetection> detections) {

errorTasks.AddRange(detections.Select(detection => new ErrorTask {
Text = $"Cycode: {detection.GetFormattedTitle()}",
Line = detection.DetectionDetails.LineInFile,
Line = detection.DetectionDetails.GetLineNumber() - 1,
Document = detection.DetectionDetails.GetFilePath(),
Category = TaskCategory.User,
ErrorCategory = ErrorCategoryUtilities.GetTaskErrorCategory(detection.Severity),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static List<ErrorTask> CreateErrorTasks(List<SastDetection> detections) {

errorTasks.AddRange(detections.Select(detection => new ErrorTask {
Text = $"Cycode: {detection.GetFormattedTitle()}",
Line = detection.DetectionDetails.LineInFile - 1,
Line = detection.DetectionDetails.GetLineNumber() - 1,
Document = detection.DetectionDetails.GetFilePath(),
Category = TaskCategory.User,
ErrorCategory = ErrorCategoryUtilities.GetTaskErrorCategory(detection.Severity),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static List<ErrorTask> CreateErrorTasks(List<ScaDetection> detections) {

errorTasks.AddRange(detections.Select(detection => new ErrorTask {
Text = $"Cycode: {detection.GetFormattedTitle()}",
Line = detection.DetectionDetails.LineInFile - 1,
Line = detection.DetectionDetails.GetLineNumber() - 1,
Document = detection.DetectionDetails.GetFilePath(),
Category = TaskCategory.User,
ErrorCategory = ErrorCategoryUtilities.GetTaskErrorCategory(detection.Severity),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static List<ErrorTask> CreateErrorTasks(List<SecretDetection> detections)

errorTasks.AddRange(detections.Select(detection => new ErrorTask {
Text = $"Cycode: {detection.GetFormattedTitle()}",
Line = detection.DetectionDetails.Line,
Line = detection.DetectionDetails.GetLineNumber() - 1,
Document = detection.DetectionDetails.GetFilePath(),
Category = TaskCategory.User,
ErrorCategory = ErrorCategoryUtilities.GetTaskErrorCategory(detection.Severity),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static List<ITagSpan<DetectionTag>> CreateTagSpans(ITextSnapshot snapshot
.ToList();

tagSpans.AddRange(from detection in detections
let line = detection.DetectionDetails.LineInFile
let line = detection.DetectionDetails.GetLineNumber() - 1
let startSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start
let endSnapshotPoint = snapshot.GetLineFromLineNumber(line).End
let snapshotSpan = new SnapshotSpan(startSnapshotPoint, endSnapshotPoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static List<ITagSpan<DetectionTag>> CreateTagSpans(ITextSnapshot snapshot
.ToList();

tagSpans.AddRange(from detection in detections
let line = detection.DetectionDetails.LineInFile - 1
let line = detection.DetectionDetails.GetLineNumber() - 1
let startSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start
let endSnapshotPoint = snapshot.GetLineFromLineNumber(line).End
let snapshotSpan = new SnapshotSpan(startSnapshotPoint, endSnapshotPoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static List<ITagSpan<DetectionTag>> CreateTagSpans(ITextSnapshot snapshot
.ToList();

tagSpans.AddRange(from detection in detections
let line = detection.DetectionDetails.LineInFile - 1
let line = detection.DetectionDetails.GetLineNumber() - 1
let length = snapshot.GetLineFromLineNumber(line).Length
let startSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start.Add(0)
let endSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start.Add(length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static List<ITagSpan<DetectionTag>> CreateTagSpans(ITextSnapshot snapshot
.ToList();

tagSpans.AddRange(from detection in detections
let line = detection.DetectionDetails.Line
let line = detection.DetectionDetails.GetLineNumber() - 1
let column = ErrorTaggerUtilities.CalculateColumn(snapshot, detection.DetectionDetails.StartPosition)
let length = detection.DetectionDetails.Length
let startSnapshotPoint = snapshot.GetLineFromLineNumber(line).Start.Add(column)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace Cycode.VisualStudio.Extension.Shared;
internal sealed class Vsix {
public const string Name = "Cycode";
public const string Description = "Cycode for Visual Studio IDE";
public const string Version = "1.9.0";
public const string Version = "1.10.0";
}
Loading