-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added summary panel --------- Co-authored-by: DariusZdroba <[email protected]> Co-authored-by: Abdelrahman Shawki Hassan <[email protected]>
- Loading branch information
1 parent
8bed8bf
commit 53e51f1
Showing
16 changed files
with
202 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ILog } from '../../common/logger/interfaces'; | ||
import { SummaryWebviewViewProvider } from '../../common/views/summaryWebviewProvider'; | ||
|
||
export interface ISummaryProviderService { | ||
updateSummaryPanel(scanSummary: string): void; | ||
} | ||
|
||
export class SummaryProviderService implements ISummaryProviderService { | ||
constructor( | ||
private readonly logger: ILog, | ||
private readonly summaryWebviewViewProvider: SummaryWebviewViewProvider | undefined, | ||
) {} | ||
public updateSummaryPanel(scanSummary: string) { | ||
if (!this.summaryWebviewViewProvider) { | ||
this.logger.error('Summary Webview Provider was not initialized.'); | ||
return; | ||
} | ||
try { | ||
this.summaryWebviewViewProvider.updateWebviewContent(scanSummary); | ||
} catch (error) { | ||
this.logger.error('Failed to update Summary panel'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as vscode from 'vscode'; | ||
import { readFileSync } from 'fs'; | ||
import { getNonce } from './nonce'; | ||
import { SummaryMessage } from '../languageServer/types'; | ||
import { SNYK_TOGGLE_DELTA } from '../constants/commands'; | ||
import { Logger } from '../logger/logger'; | ||
export class SummaryWebviewViewProvider implements vscode.WebviewViewProvider { | ||
private static instance: SummaryWebviewViewProvider; | ||
private webviewView: vscode.WebviewView | undefined; | ||
private context: vscode.ExtensionContext; | ||
|
||
private constructor(context: vscode.ExtensionContext) { | ||
this.context = context; | ||
} | ||
|
||
public static getInstance(extensionContext?: vscode.ExtensionContext): SummaryWebviewViewProvider | undefined { | ||
if (!SummaryWebviewViewProvider.instance) { | ||
if (!extensionContext) { | ||
console.log('ExtensionContext is required for the first initialization of SnykDiagnosticsWebviewViewProvider'); | ||
return undefined; | ||
} else { | ||
SummaryWebviewViewProvider.instance = new SummaryWebviewViewProvider(extensionContext); | ||
} | ||
} | ||
return SummaryWebviewViewProvider.instance; | ||
} | ||
|
||
resolveWebviewView(webviewView: vscode.WebviewView) { | ||
this.webviewView = webviewView; | ||
webviewView.webview.options = { | ||
enableScripts: true, | ||
}; | ||
this.webviewView.webview.onDidReceiveMessage((msg: SummaryMessage) => this.handleMessage(msg)); | ||
} | ||
|
||
private async handleMessage(message: SummaryMessage) { | ||
try { | ||
switch (message.type) { | ||
case 'sendSummaryParams': { | ||
const { summary } = message.args; | ||
await vscode.commands.executeCommand(SNYK_TOGGLE_DELTA, summary.toggleDelta); | ||
break; | ||
} | ||
} | ||
} catch (error) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
Logger.error(error); | ||
} | ||
} | ||
|
||
public updateWebviewContent(html: string) { | ||
if (this.webviewView) { | ||
const nonce = getNonce(); | ||
const ideScriptPath = vscode.Uri.joinPath( | ||
vscode.Uri.file(this.context.extensionPath), | ||
'out', | ||
'snyk', | ||
'common', | ||
'views', | ||
'summaryWebviewScript.js', | ||
); | ||
const ideScript = readFileSync(ideScriptPath.fsPath, 'utf8'); | ||
|
||
html = html.replace('${ideStyle}', `<style nonce=${nonce}>` + '' + '</style>'); | ||
html = html.replace('${ideFunc}', ideScript); | ||
html = html.replace(/\${nonce}/g, nonce); | ||
|
||
this.webviewView.webview.html = html; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
|
||
type SummaryMessage = { | ||
type: 'sendSummaryParams'; | ||
args: { | ||
summary: Summary; | ||
}; | ||
}; | ||
|
||
type Summary = { | ||
toggleDelta: boolean; | ||
}; | ||
const vscode = acquireVsCodeApi(); | ||
Check warning on line 17 in src/snyk/common/views/summaryWebviewScript.ts GitHub Actions / build / Build and Test (ubuntu-latest)
Check warning on line 17 in src/snyk/common/views/summaryWebviewScript.ts GitHub Actions / build / Build and Test (macos-latest)
|
||
|
||
const summary: Summary = { | ||
// @ts-expect-error this will be injected in a func coming from LS that has isEnabled as arg. | ||
toggleDelta: isEnabled, | ||
Check warning on line 21 in src/snyk/common/views/summaryWebviewScript.ts GitHub Actions / build / Build and Test (ubuntu-latest)
Check warning on line 21 in src/snyk/common/views/summaryWebviewScript.ts GitHub Actions / build / Build and Test (macos-latest)
|
||
}; | ||
|
||
const message: SummaryMessage = { | ||
type: 'sendSummaryParams', | ||
args: { summary }, | ||
}; | ||
vscode.postMessage(message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.