Skip to content
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

CM-42969 - Improve rendering of suggested AI fixes; fix extension state; fix code actions #121

Merged
merged 1 commit into from
Dec 17, 2024
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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [v1.13.1]

- Improve suggested AI fix rendering in violation cards
- Fix extension state on startup
- Fix Code Actions creation

## [v1.13.0]

- Add AI remediations for IaC and SAST
Expand Down Expand Up @@ -124,6 +130,8 @@

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

[v1.13.1]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.13.1

[v1.13.0]: https://github.com/cycodehq/vscode-extension/releases/tag/v1.13.0

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

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

[Unreleased]: https://github.com/cycodehq/vscode-extension/compare/v1.13.0...HEAD
[Unreleased]: https://github.com/cycodehq/vscode-extension/compare/v1.13.1...HEAD
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cycode",
"displayName": "Cycode",
"version": "1.13.0",
"version": "1.13.1",
"publisher": "cycode",
"description": "Boost security in your dev lifecycle via SAST, SCA, Secrets & IaC scanning.",
"repository": {
Expand Down
12 changes: 8 additions & 4 deletions src/providers/code-action/unique-diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import * as vscode from 'vscode';
import { extensionId } from '../../utils/texts';

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

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

if (!aggregatedDiagnostics.has(diagnosticCode)) {
aggregatedDiagnostics.set(diagnosticCode, []);
if (!aggregatedDiagnostics.has(diagnostic.code)) {
aggregatedDiagnostics.set(diagnostic.code, []);
}

aggregatedDiagnostics.get(diagnosticCode)?.push(diagnostic);
aggregatedDiagnostics.get(diagnostic.code)?.push(diagnostic);
});

return aggregatedDiagnostics;
Expand Down
9 changes: 9 additions & 0 deletions src/services/state-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ export class StateService implements IStateService {
load(): void {
this.loadGlobalState();
this.loadLocalState();

/*
* TODO(MarshalX): should not be persistent state
* reset the state to the default values on every extension initialization
*/
this.globalState.CliInstalled = false;
this.globalState.CliAuthed = false;
this.globalState.IsAiLargeLanguageModelEnabled = false;
this.saveGlobalState();
}

private saveGlobalState(): void {
Expand Down
1 change: 1 addition & 0 deletions src/ui/panels/violation/card/iac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default `
<section class="ai-remediation compact">
<div class="section-header">AI Remediation</div>
<div class="ai-remediation-text">None</div>
<div class="ai-remediation-diff">None</div>
</section>

<section class="hr section-footer">
Expand Down
1 change: 1 addition & 0 deletions src/ui/panels/violation/card/sast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default `
<section class="ai-remediation compact">
<div class="section-header">AI Remediation</div>
<div class="ai-remediation-text">None</div>
<div class="ai-remediation-diff">None</div>
</section>

<section class="hr section-footer">
Expand Down
9 changes: 9 additions & 0 deletions src/ui/panels/violation/content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import mainStyles from './styles/main';
import diff2htmlStyles from './styles/diff2html/diff2html';
import hljsGithubLightThemeStyles from './styles/hljs/github-light-default';
import hljsGithubDarkThemeStyles from './styles/hljs/github-dark-dimmed';
import scaCard from './card/sca';
Expand All @@ -23,10 +24,18 @@ export default (scanType: CliScanType) => `
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cycode: Detection Details</title>

<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"
></script>
</head>
<body>
<script>const isDarkTheme = ${isDarkTheme};</script>

${mainStyles}
${isDarkTheme ? hljsGithubDarkThemeStyles : hljsGithubLightThemeStyles}
${diff2htmlStyles}

${scanType == CliScanType.Sca ? scaCard : ''}
${scanType == CliScanType.Secret ? secretCard : ''}
Expand Down
29 changes: 26 additions & 3 deletions src/ui/panels/violation/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,41 @@ export default (detectionType: CliScanType) => `
hideElement('ai-apply-fix-btn');
hideElement('ai-remediation');
ge('ai-remediation-text').innerText = 'None';
ge('ai-remediation-diff').innerText = '';
}

const renderAiRemediation = (remediation, isFixAvailable) => {
const renderAiRemediation = (remediation, unifyDiff, isFixAvailable) => {
isFixAvailable = false; // disable fix for now; not ready for production

hideElement('ai-remediation-btn');
showElement('ai-remediation');
ge('ai-remediation-text').innerHTML = remediation;
showElement('ai-remediation');

if (isFixAvailable) {
showElement('ai-apply-fix-btn');
}

if (!unifyDiff) {
return;
}

const configuration = {
drawFileList: false,
fileListToggle: false,
fileListStartVisible: false,
fileContentToggle: false,
matching: 'words',
outputFormat: 'line-by-line',
synchronisedScroll: true,
highlight: true,
renderNothingWhenEmpty: false,
colorScheme: isDarkTheme ? 'dark' : 'light',
};
const diff2htmlUi = new Diff2HtmlUI(ge('ai-remediation-diff'), unifyDiff, configuration);

diff2htmlUi.draw();
diff2htmlUi.highlightCode();
showElement('ai-remediation-diff');
};

const registerAiButtonCallbacks = () => {
Expand Down Expand Up @@ -133,7 +156,7 @@ export default (detectionType: CliScanType) => `
}

if (aiRemediation) {
renderAiRemediation(aiRemediation.remediation, aiRemediation.isFixAvailable);
renderAiRemediation(aiRemediation.remediation, aiRemediation.unifyDiff, aiRemediation.isFixAvailable);
}
};

Expand Down
Loading
Loading