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: use language server for html vulnerability counts [HEAD-282] #371

Merged
merged 9 commits into from
Aug 30, 2023
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Snyk Security - Code and Open Source Dependencies Changelog

## [1.21.4]

### Changed
- Use Language Server to retrieve vulnerability count for HTML files

## [1.21.1]
### Fixed
- Snyk Learn links

## [1.21.0]
### Fixed
- Plugin Initialization

## [1.20.3]

### Removed
Expand Down
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@
"string-argv": "^0.3.1",
"uuid": "^8.3.2",
"validate-npm-package-name": "^3.0.0",
"vscode-languageclient": "8.1.0"
"vscode-languageclient": "8.1.0",
"vscode-languageserver-textdocument":"^1.0.8"
}
}
12 changes: 12 additions & 0 deletions src/snyk/common/vscode/textdocument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as vlt from 'vscode-languageserver-textdocument';
import { LSPTextDocument } from './types';

export interface ITextDocumentAdapter {
create(uri: string, language: string, version: number, content: string): LSPTextDocument;
}

export class TextDocumentAdapter implements ITextDocumentAdapter {
create(uri: string, language: string, version: number, content: string): LSPTextDocument {
return vlt.TextDocument.create(uri, language, version, content);
}
}
4 changes: 4 additions & 0 deletions src/snyk/common/vscode/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import * as lsc from 'vscode-languageclient/node';
import * as lst from 'vscode-languageserver-textdocument';

// VS Code core type mappings
export type Disposable = vscode.Disposable;
Expand Down Expand Up @@ -57,3 +58,6 @@ export type ConfigurationParams = lsc.ConfigurationParams;
export type CancellationToken = lsc.CancellationToken;
export type ConfigurationRequestHandlerSignature = lsc.ConfigurationRequest.HandlerSignature;
export type ResponseError<D = void> = lsc.ResponseError<D>;
export type InlineValueContext = lsc.InlineValueContext;
export type InlineValueText = lsc.InlineValueText;
export type LSPTextDocument = lst.TextDocument;
15 changes: 7 additions & 8 deletions src/snyk/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { HoverAdapter } from './common/vscode/hover';
import { LanguageClientAdapter } from './common/vscode/languageClient';
import { vsCodeLanguages } from './common/vscode/languages';
import SecretStorageAdapter from './common/vscode/secretStorage';
import { TextDocumentAdapter } from './common/vscode/textdocument';
import { ThemeColorAdapter } from './common/vscode/theme';
import { Range, Uri } from './common/vscode/types';
import { UriAdapter } from './common/vscode/uri';
Expand All @@ -74,10 +75,8 @@ import { CodeSuggestionWebviewProvider } from './snykCode/views/suggestion/codeS
import { IacService } from './snykIac/iacService';
import IacIssueTreeProvider from './snykIac/views/iacIssueTreeProvider';
import { IacSuggestionWebviewProvider } from './snykIac/views/suggestion/iacSuggestionWebviewProvider';
import { NpmTestApi } from './snykOss/api/npmTestApi';
import { EditorDecorator } from './snykOss/editor/editorDecorator';
import { OssService } from './snykOss/services/ossService';
import { NpmModuleInfoFetchService } from './snykOss/services/vulnerabilityCount/npmModuleInfoFetchService';
import { OssVulnerabilityCountService } from './snykOss/services/vulnerabilityCount/ossVulnerabilityCountService';
import { ModuleVulnerabilityCountProvider } from './snykOss/services/vulnerabilityCount/vulnerabilityCountProvider';
import { OssVulnerabilityTreeProvider } from './snykOss/views/ossVulnerabilityTreeProvider';
Expand Down Expand Up @@ -361,16 +360,16 @@ class SnykExtension extends SnykLib implements IExtension {

this.initDependencyDownload();

const npmModuleInfoFetchService = new NpmModuleInfoFetchService(
configuration,
Logger,
new NpmTestApi(Logger, vsCodeWorkspace),
);
this.ossVulnerabilityCountService = new OssVulnerabilityCountService(
vsCodeWorkspace,
vsCodeWindow,
vsCodeLanguages,
new ModuleVulnerabilityCountProvider(this.ossService, npmModuleInfoFetchService),
new ModuleVulnerabilityCountProvider(
this.ossService,
languageClientAdapter,
new UriAdapter(),
new TextDocumentAdapter(),
),
this.ossService,
Logger,
new EditorDecorator(vsCodeWindow, vsCodeLanguages, new ThemeColorAdapter()),
Expand Down
40 changes: 0 additions & 40 deletions src/snyk/snykOss/api/npmTestApi.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class OssVulnerabilityCountService implements Disposable {
emitter.startScanning(modules);

const promises = modules
.map(module => this.vulnerabilityCountProvider.getVulnerabilityCount(module, language))
.map(module => this.vulnerabilityCountProvider.getVulnerabilityCount(fileName, module, language))
.map(promise =>
promise.then(module => {
emitter.scanned(module);
Expand Down
Loading
Loading