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

feat: add detail section to code webview [HEAD-559] #405

Merged
merged 6 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 media/views/snykCode/suggestion/suggestion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
line-height: 1.6;
}

#suggestion-details {
display: none;
}

#suggestion-details.show {
display: block;
}

.cwe-list {
display: inline-block;
margin: 0;
Expand Down Expand Up @@ -231,4 +239,4 @@

.report-fp-actions {
margin-left: auto;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import he from 'he';
import _ from 'lodash';
import { marked } from 'marked';
import * as vscode from 'vscode';
import {
SNYK_IGNORE_ISSUE_COMMAND,
Expand Down Expand Up @@ -155,18 +156,20 @@
}

private mapToModel(issue: Issue<CodeIssueData>): Suggestion {
const parsedDetails = marked.parse(issue.additionalData.text) as string;
return {
id: issue.id,
title: issue.title,
uri: issue.filePath,
severity: _.capitalize(issue.severity),
...issue.additionalData,
text: parsedDetails,
};
}

private async handleMessage(message: any) {

Check warning on line 170 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewProvider.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 170 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewProvider.ts

View workflow job for this annotation

GitHub Actions / Build and Test (macos-latest)

Unexpected any. Specify a different type

Check warning on line 170 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewProvider.ts

View workflow job for this annotation

GitHub Actions / Build and Test (windows-latest)

Unexpected any. Specify a different type
try {
const { type, args } = message;

Check warning on line 172 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewProvider.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 172 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewProvider.ts

View workflow job for this annotation

GitHub Actions / Build and Test (macos-latest)

Unsafe assignment of an `any` value

Check warning on line 172 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewProvider.ts

View workflow job for this annotation

GitHub Actions / Build and Test (windows-latest)

Unsafe assignment of an `any` value
switch (type) {
case 'openLocal': {
const { uri, cols, rows, suggestionUri } = args as {
Expand Down Expand Up @@ -292,6 +295,8 @@
</div>
</div>
</section>
<section id="suggestion-details" class="delimiter-top">
</section>
<section class="delimiter-top">
<div id="info-top" class="font-light">
This <span class="issue-type">issue</span> was fixed by <span id="dataset-number"></span> projects. Here are <span id="example-number"></span> examples:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,14 @@ declare const acquireVsCodeApi: any;
}

exampleCount = 0;

const currentSeverity = getCurrentSeverity();
const severity = document.getElementById('severity')!;
const title = document.getElementById('title')!;
const description = document.getElementById('description')!;
const suggestionDetails = document.querySelector('#suggestion-details');
const meta = document.getElementById('meta')!;

let type = '';

// Set issue type: vulnerability or issue
Expand Down Expand Up @@ -245,6 +248,9 @@ declare const acquireVsCodeApi: any;

description.querySelectorAll('*').forEach(n => n.remove());
description.innerHTML = '';

showSuggestionDetails(suggestion);

if (suggestion.markers && suggestion.markers.length) {
let i = 0;
for (const m of suggestion.markers) {
Expand Down Expand Up @@ -314,6 +320,15 @@ declare const acquireVsCodeApi: any;
example.className = 'hidden';
noExamples.className = 'font-light';
}

function showSuggestionDetails(suggestion: Suggestion) {
if (!suggestion.text) {
return;
}

suggestionDetails!.className = 'show';
suggestionDetails!.innerHTML = suggestion.text;
}
}

function sendMessage(message: {
Expand Down
Loading