Skip to content

Commit 77950fa

Browse files
authored
CM-42969 - Improve rendering of suggested AI fixes; fix extension state; fix code actions (#121)
1 parent 28787d7 commit 77950fa

File tree

10 files changed

+837
-10
lines changed

10 files changed

+837
-10
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
## [v1.13.1]
6+
7+
- Improve suggested AI fix rendering in violation cards
8+
- Fix extension state on startup
9+
- Fix Code Actions creation
10+
511
## [v1.13.0]
612

713
- Add AI remediations for IaC and SAST
@@ -124,6 +130,8 @@
124130

125131
The first stable release with the support of Secrets, SCA, TreeView, Violation Card, and more.
126132

133+
[v1.13.1]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.13.1
134+
127135
[v1.13.0]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.13.0
128136

129137
[v1.12.0]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.12.0
@@ -170,4 +178,4 @@ The first stable release with the support of Secrets, SCA, TreeView, Violation C
170178

171179
[v1.0.0]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.0.0
172180

173-
[Unreleased]: https://github.com/cycodehq/vscode-extension/compare/v1.13.0...HEAD
181+
[Unreleased]: https://github.com/cycodehq/vscode-extension/compare/v1.13.1...HEAD

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cycode",
33
"displayName": "Cycode",
4-
"version": "1.13.0",
4+
"version": "1.13.1",
55
"publisher": "cycode",
66
"description": "Boost security in your dev lifecycle via SAST, SCA, Secrets & IaC scanning.",
77
"repository": {

src/providers/code-action/unique-diagnostics.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import * as vscode from 'vscode';
2+
import { extensionId } from '../../utils/texts';
23

34
export const aggregateDiagnosticsByCode = (
45
diagnostics: readonly vscode.Diagnostic[],
56
): Map<string, vscode.Diagnostic[]> => {
67
const aggregatedDiagnostics = new Map<string, vscode.Diagnostic[]>();
78

89
diagnostics.forEach((diagnostic) => {
9-
const diagnosticCode = diagnostic.code as string;
10+
if (diagnostic.source !== extensionId || !diagnostic.code || typeof diagnostic.code !== 'string') {
11+
// if diagnostics came from an external source or something wrong with code, we don't want to aggregate them
12+
return;
13+
}
1014

11-
if (!aggregatedDiagnostics.has(diagnosticCode)) {
12-
aggregatedDiagnostics.set(diagnosticCode, []);
15+
if (!aggregatedDiagnostics.has(diagnostic.code)) {
16+
aggregatedDiagnostics.set(diagnostic.code, []);
1317
}
1418

15-
aggregatedDiagnostics.get(diagnosticCode)?.push(diagnostic);
19+
aggregatedDiagnostics.get(diagnostic.code)?.push(diagnostic);
1620
});
1721

1822
return aggregatedDiagnostics;

src/services/state-service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ export class StateService implements IStateService {
118118
load(): void {
119119
this.loadGlobalState();
120120
this.loadLocalState();
121+
122+
/*
123+
* TODO(MarshalX): should not be persistent state
124+
* reset the state to the default values on every extension initialization
125+
*/
126+
this.globalState.CliInstalled = false;
127+
this.globalState.CliAuthed = false;
128+
this.globalState.IsAiLargeLanguageModelEnabled = false;
129+
this.saveGlobalState();
121130
}
122131

123132
private saveGlobalState(): void {

src/ui/panels/violation/card/iac.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default `
4141
<section class="ai-remediation compact">
4242
<div class="section-header">AI Remediation</div>
4343
<div class="ai-remediation-text">None</div>
44+
<div class="ai-remediation-diff">None</div>
4445
</section>
4546
4647
<section class="hr section-footer">

src/ui/panels/violation/card/sast.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default `
4949
<section class="ai-remediation compact">
5050
<div class="section-header">AI Remediation</div>
5151
<div class="ai-remediation-text">None</div>
52+
<div class="ai-remediation-diff">None</div>
5253
</section>
5354
5455
<section class="hr section-footer">

src/ui/panels/violation/content.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import mainStyles from './styles/main';
3+
import diff2htmlStyles from './styles/diff2html/diff2html';
34
import hljsGithubLightThemeStyles from './styles/hljs/github-light-default';
45
import hljsGithubDarkThemeStyles from './styles/hljs/github-dark-dimmed';
56
import scaCard from './card/sca';
@@ -23,10 +24,18 @@ export default (scanType: CliScanType) => `
2324
<meta charset="UTF-8">
2425
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2526
<title>Cycode: Detection Details</title>
27+
28+
<script
29+
type="text/javascript"
30+
src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"
31+
></script>
2632
</head>
2733
<body>
34+
<script>const isDarkTheme = ${isDarkTheme};</script>
35+
2836
${mainStyles}
2937
${isDarkTheme ? hljsGithubDarkThemeStyles : hljsGithubLightThemeStyles}
38+
${diff2htmlStyles}
3039
3140
${scanType == CliScanType.Sca ? scaCard : ''}
3241
${scanType == CliScanType.Secret ? secretCard : ''}

src/ui/panels/violation/js.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,41 @@ export default (detectionType: CliScanType) => `
7676
hideElement('ai-apply-fix-btn');
7777
hideElement('ai-remediation');
7878
ge('ai-remediation-text').innerText = 'None';
79+
ge('ai-remediation-diff').innerText = '';
7980
}
8081
81-
const renderAiRemediation = (remediation, isFixAvailable) => {
82+
const renderAiRemediation = (remediation, unifyDiff, isFixAvailable) => {
8283
isFixAvailable = false; // disable fix for now; not ready for production
8384
8485
hideElement('ai-remediation-btn');
85-
showElement('ai-remediation');
8686
ge('ai-remediation-text').innerHTML = remediation;
87+
showElement('ai-remediation');
8788
8889
if (isFixAvailable) {
8990
showElement('ai-apply-fix-btn');
9091
}
92+
93+
if (!unifyDiff) {
94+
return;
95+
}
96+
97+
const configuration = {
98+
drawFileList: false,
99+
fileListToggle: false,
100+
fileListStartVisible: false,
101+
fileContentToggle: false,
102+
matching: 'words',
103+
outputFormat: 'line-by-line',
104+
synchronisedScroll: true,
105+
highlight: true,
106+
renderNothingWhenEmpty: false,
107+
colorScheme: isDarkTheme ? 'dark' : 'light',
108+
};
109+
const diff2htmlUi = new Diff2HtmlUI(ge('ai-remediation-diff'), unifyDiff, configuration);
110+
111+
diff2htmlUi.draw();
112+
diff2htmlUi.highlightCode();
113+
showElement('ai-remediation-diff');
91114
};
92115
93116
const registerAiButtonCallbacks = () => {
@@ -133,7 +156,7 @@ export default (detectionType: CliScanType) => `
133156
}
134157
135158
if (aiRemediation) {
136-
renderAiRemediation(aiRemediation.remediation, aiRemediation.isFixAvailable);
159+
renderAiRemediation(aiRemediation.remediation, aiRemediation.unifyDiff, aiRemediation.isFixAvailable);
137160
}
138161
};
139162

0 commit comments

Comments
 (0)