@@ -6,7 +6,6 @@ import { ModuleParserProvider } from '../../../common/services/moduleParserProvi
66import { Language } from '../../../common/types' ;
77import { IVSCodeLanguages } from '../../../common/vscode/languages' ;
88import {
9- Diagnostic ,
109 DiagnosticCollection ,
1110 Disposable ,
1211 TextDocument ,
@@ -19,7 +18,7 @@ import { DIAGNOSTICS_OSS_COLLECTION_NAME } from '../../../snykCode/constants/ana
1918import { EditorDecorator } from '../../editor/editorDecorator' ;
2019import { OssService } from '../../ossService' ;
2120import { OssVulnerabilityCountProvider } from '../../providers/ossVulnerabilityCountProvider' ;
22- import { ImportedModule , ModuleVulnerabilityCount , ModuleVulnerabilityCountSeverity } from './importedModule' ;
21+ import { ImportedModule , ModuleVulnerabilityCount } from './importedModule' ;
2322import { VulnerabilityCountEmitter , VulnerabilityCountEvents } from './vulnerabilityCountEmitter' ;
2423
2524export class OssVulnerabilityCountService implements Disposable {
@@ -120,52 +119,13 @@ export class OssVulnerabilityCountService implements Disposable {
120119
121120 emitter . on ( VulnerabilityCountEvents . Done , ( modules : ModuleVulnerabilityCount [ ] ) => {
122121 this . editorDecorator . setScanDoneDecorations ( fileName , modules ) ;
123- // TODO: delete this and related code if we move HTML diagnostics to Language Server
124- // Update diagnostics only for HTML files; for other files, diagnostics are provided by Language Server
125- if ( getSupportedLanguage ( fileName , languageId ) === Language . HTML ) {
126- this . updateDiagnostics ( document , modules ) ;
127- }
128122 } ) ;
129123
130124 // Start
131125 void this . getImportedModules ( fileName , document . getText ( ) , supportedLanguage , emitter ) ;
132126 return true ;
133127 }
134128
135- private updateDiagnostics ( document : TextDocument , modules : ModuleVulnerabilityCount [ ] ) : void {
136- if ( ! this . diagnostics ) {
137- return ;
138- }
139-
140- const diagnostics : Diagnostic [ ] = [ ] ;
141- for ( const module of modules ) {
142- if ( ! module . hasCount || ! module . range ) {
143- continue ;
144- }
145-
146- const diagnosticMessage = this . getDiagnosticMessage ( module ) ;
147- if ( ! diagnosticMessage . length ) {
148- continue ;
149- }
150-
151- const range = this . languages . createRange (
152- module . range . start . line - 1 ,
153- module . range . start . column ,
154- module . range . end . line - 1 ,
155- module . range . end . column ,
156- ) ;
157-
158- const diagnostic = this . languages . createDiagnostic ( range , diagnosticMessage , 1 ) ; // Warning severity
159- diagnostics . push ( {
160- ...diagnostic ,
161- source : DIAGNOSTICS_OSS_COLLECTION_NAME ,
162- code : module . mostSevereVulnerabilityId ,
163- } ) ;
164- }
165-
166- this . diagnostics . set ( document . uri , diagnostics ) ;
167- }
168-
169129 private shouldProcessFile ( fileName : string , language : Language ) : boolean {
170130 if ( [ Language . TypeScript , Language . JavaScript , Language . PJSON ] . includes ( language ) ) {
171131 const ossResult = this . vulnerabilityCountProvider . getResultArray ( ) ;
@@ -215,41 +175,4 @@ export class OssVulnerabilityCountService implements Disposable {
215175
216176 return parser . getModules ( fileName , source , language ) ;
217177 }
218-
219- private getDiagnosticMessage ( module : ModuleVulnerabilityCount ) : string {
220- if ( ! module . count ) {
221- return '' ;
222- }
223-
224- let message = `Dependency ${ module . name } ${ module . version ? `@${ module . version } ` : '' } has ` ;
225- message += this . getSeverityCountMessage (
226- [
227- ModuleVulnerabilityCountSeverity . Critical ,
228- ModuleVulnerabilityCountSeverity . High ,
229- ModuleVulnerabilityCountSeverity . Medium ,
230- ModuleVulnerabilityCountSeverity . Low ,
231- ] ,
232- module ,
233- ) ;
234-
235- return message ;
236- }
237-
238- private getSeverityCountMessage (
239- severities : ModuleVulnerabilityCountSeverity [ ] ,
240- module : ModuleVulnerabilityCount ,
241- ) : string {
242- if ( ! module . severityCounts ) {
243- return module . count ? module . count : '' ;
244- }
245-
246- const content : string [ ] = [ ] ;
247- for ( const severity of severities ) {
248- if ( module . severityCounts [ severity ] > 0 ) {
249- content . push ( `${ module . severityCounts [ severity ] } ${ severity } ` ) ;
250- }
251- }
252-
253- return content . join ( ', ' ) ;
254- }
255178}
0 commit comments