Skip to content

Commit

Permalink
feat: Use Detail Panel from Language Server (#389)
Browse files Browse the repository at this point in the history
* docs: update instructions for contribution to include `npm run build`

Signed-off-by: Bastian Doetsch <[email protected]>

* chore: use ls based oss service in cmdcontroller

* chore: move convertion of Issue to OssVulnerability

* chore: adapt test

* chore: delete vulnerabilityCountCodeActionProviderLS class as LS handles CodeActions now

* chore: delete vulnerabilityCountHoverProvider class as LS handles hovers now

* chore: clean up codeaction/hovers where they are not needed anymore

* fix: linting

* check license data if undefined

* chore: display received details html

* chore: initial version taking html from ls

* chore: inject learn icon

* chore: inject nonce and cspsource

* fix: linter

---------

Signed-off-by: Bastian Doetsch <[email protected]>
Co-authored-by: Bastian Doetsch <[email protected]>
Co-authored-by: Jason Luong <[email protected]>
  • Loading branch information
3 people committed Nov 23, 2023
1 parent ce00993 commit 85ca7e4
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 340 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Run extension and debug

Clone the repository, then run `npm install` in the directory.
Clone the repository, then run `npm install && npm run build` in the directory.

- Open repository directory in VS Code and press `F5` to run extension in a new VS Code window.
- This allows extension debugging within VS Code.
Expand Down
27 changes: 20 additions & 7 deletions src/snyk/common/commands/commandController.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import _ from 'lodash';
import path from 'path';
import { IAuthenticationService } from '../../base/services/authenticationService';
import { ScanModeService } from '../../base/services/scanModeService';
import { createDCIgnore } from '../../snykCode/utils/ignoreFileUtils';
import { IssueUtils } from '../../snykCode/utils/issueUtils';
import { CodeIssueCommandArg } from '../../snykCode/views/interfaces';
import { IacIssueCommandArg } from '../../snykIac/views/interfaces';
import { capitalizeOssSeverity } from '../../snykOss/ossResult';
import { OssService } from '../../snykOss/services/ossService';
import { OssIssueCommandArg } from '../../snykOss/views/ossVulnerabilityTreeProvider';
import { OssServiceLanguageServer } from '../../snykOss/ossServiceLanguageServer';
import { IAnalytics } from '../analytics/itly';
import {
SNYK_INITIATE_LOGIN_COMMAND,
Expand Down Expand Up @@ -40,7 +39,7 @@ export class CommandController {
private authService: IAuthenticationService,
private snykCode: IProductService<CodeIssueData>,
private iacService: IProductService<IacIssueData>,
private ossService: OssService,
private ossService: OssServiceLanguageServer,
private scanModeService: ScanModeService,
private workspace: IVSCodeWorkspace,
private commands: IVSCodeCommands,
Expand Down Expand Up @@ -122,14 +121,28 @@ export class CommandController {
severity: IssueUtils.issueSeverityAsText(issue.severity),
});
} else if (arg.issueType == OpenCommandIssueType.OssVulnerability) {
const issue = arg.issue as OssIssueCommandArg;
void this.ossService.showSuggestionProvider(issue);
const issueArgs = arg.issue as CodeIssueCommandArg;
const folderPath = path.dirname(issueArgs.filePath);
const issue = this.ossService.getIssue(folderPath, issueArgs.id);

if (!issue) {
this.logger.warn(`Failed to find the issue ${issueArgs.id}.`);
return;
}

await this.openLocalFile(issue.filePath, issueArgs.range);

try {
await this.ossService.showSuggestionProvider(folderPath, issueArgs.id);
} catch (e) {
ErrorHandler.handle(e, this.logger);
}

this.analytics.logIssueInTreeIsClicked({
ide: IDE_NAME,
issueId: issue.id,
issueType: 'Open Source Vulnerability',
severity: capitalizeOssSeverity(issue.severity),
severity: IssueUtils.issueSeverityAsText(issue.severity),
});
} else if (arg.issueType == OpenCommandIssueType.IacIssue) {
const issueArgs = arg.issue as IacIssueCommandArg;
Expand Down
2 changes: 2 additions & 0 deletions src/snyk/common/languageServer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export type OssIssueData = {

projectName: string;
displayTargetFile: string;

details: string;
};
export type Identifiers = {
CWE: string[];
Expand Down
7 changes: 2 additions & 5 deletions src/snyk/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { DownloadService } from './common/services/downloadService';
import { LearnService } from './common/services/learnService';
import { NotificationService } from './common/services/notificationService';
import { User } from './common/user';
import { CodeActionAdapter, CodeActionKindAdapter } from './common/vscode/codeAction';
import { CodeActionAdapter } from './common/vscode/codeAction';
import { vsCodeCommands } from './common/vscode/commands';
import { vsCodeEnv } from './common/vscode/env';
import { extensionContext } from './common/vscode/extensionContext';
Expand Down Expand Up @@ -239,8 +239,6 @@ class SnykExtension extends SnykLib implements IExtension {
extensionContext,
configuration,
ossSuggestionProvider,
new CodeActionAdapter(),
this.codeActionKindAdapter,
this.viewManagerService,
vsCodeWorkspace,
this.workspaceTrust,
Expand Down Expand Up @@ -278,7 +276,7 @@ class SnykExtension extends SnykLib implements IExtension {
this.authService,
this.snykCode,
this.iacService,
this.ossService,
this.ossServiceLanguageServer,
this.scanModeService,
vsCodeWorkspace,
vsCodeCommands,
Expand Down Expand Up @@ -427,7 +425,6 @@ class SnykExtension extends SnykLib implements IExtension {
this.ossServiceLanguageServer,
Logger,
new EditorDecorator(vsCodeWindow, vsCodeLanguages, new ThemeColorAdapter()),
new CodeActionKindAdapter(),
this.analytics,
configuration,
);
Expand Down
101 changes: 0 additions & 101 deletions src/snyk/snykOss/codeActions/vulnerabilityCodeActionProviderLS.ts

This file was deleted.

49 changes: 0 additions & 49 deletions src/snyk/snykOss/hoverProvider/vulnerabilityCountHoverProvider.ts

This file was deleted.

33 changes: 32 additions & 1 deletion src/snyk/snykOss/ossResult.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';
import { CliError } from '../cli/services/cliService';
import { IssueSeverity } from '../common/languageServer/types';
import { Issue, IssueSeverity, OssIssueData } from '../common/languageServer/types';

export type OssResult = OssFileResult[] | OssFileResult;

Expand Down Expand Up @@ -70,3 +70,34 @@ export function convertSeverity(severity: IssueSeverity): OssSeverity {
return OssSeverity.Critical;
}
}

export function convertIssue(issue: Issue<OssIssueData>): OssVulnerability {
const tempVuln: OssVulnerability = {
id: issue.id,
identifiers: issue.additionalData.identifiers,
title: issue.title,
description: issue.additionalData.description,
language: issue.additionalData.language,
packageManager: issue.additionalData.packageManager,
packageName: issue.additionalData.packageName,
severity: convertSeverity(issue.severity),
name: issue.additionalData.name,
version: issue.additionalData.version,
exploit: issue.additionalData.exploit,

CVSSv3: issue.additionalData.CVSSv3,
cvssScore: issue.additionalData.cvssScore,

fixedIn: issue.additionalData.fixedIn === undefined ? [] : issue.additionalData.fixedIn,
from: issue.additionalData.from,
upgradePath: issue.additionalData.upgradePath,
isPatchable: issue.additionalData.isPatchable,
isUpgradable: issue.additionalData.isUpgradable,
};

if (issue.additionalData.license !== undefined) {
tempVuln.license = issue.additionalData.license;
}

return tempVuln;
}
7 changes: 0 additions & 7 deletions src/snyk/snykOss/ossServiceLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { OssIssueData, Scan, ScanProduct } from '../common/languageServer/types'
import { ILog } from '../common/logger/interfaces';
import { ProductService } from '../common/services/productService';
import { IViewManagerService } from '../common/services/viewManagerService';
import { ICodeActionAdapter, ICodeActionKindAdapter } from '../common/vscode/codeAction';
import { ExtensionContext } from '../common/vscode/extensionContext';
import { IVSCodeLanguages } from '../common/vscode/languages';
import { IVSCodeWorkspace } from '../common/vscode/workspace';
Expand All @@ -18,8 +17,6 @@ export class OssServiceLanguageServer extends ProductService<OssIssueData> {
extensionContext: ExtensionContext,
config: IConfiguration,
suggestionProvider: IOssSuggestionWebviewProvider,
readonly codeActionAdapter: ICodeActionAdapter,
readonly codeActionKindAdapter: ICodeActionKindAdapter,
viewManagerService: IViewManagerService,
workspace: IVSCodeWorkspace,
workspaceTrust: IWorkspaceTrust,
Expand All @@ -39,10 +36,6 @@ export class OssServiceLanguageServer extends ProductService<OssIssueData> {
languages,
logger,
);

// this.registerCodeActionsProvider(
// new OssCodeActionsProvider(this.result, codeActionAdapter, codeActionKindAdapter, languages, analytics),
// );
}

subscribeToLsScanMessages(): Subscription {
Expand Down
Loading

0 comments on commit 85ca7e4

Please sign in to comment.