Skip to content

Commit

Permalink
feat: use language server for HTML vulnerability counts
Browse files Browse the repository at this point in the history
Signed-off-by: Bastian Doetsch <[email protected]>
  • Loading branch information
bastiandoetsch committed Aug 23, 2023
1 parent b902bb4 commit 0ed89ef
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 221 deletions.
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"
}
}
2 changes: 1 addition & 1 deletion src/snyk/common/languageServer/languageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class LanguageServer implements ILanguageServer {

const serverOptions: ServerOptions = {
command: lsBinaryPath,
args: ['-l', 'info'],
args: ['-l', 'debug'],
options: {
env: processEnv,
},
Expand Down
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

0 comments on commit 0ed89ef

Please sign in to comment.