-
Notifications
You must be signed in to change notification settings - Fork 28
Implemented external API #149
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| /*************************************************************************************** | ||
| * Copyright (c) 2023 BlackBerry Limited and others. | ||
| * | ||
| * Licensed under the MIT license. See LICENSE file in the project root for details. | ||
| ***************************************************************************************/ | ||
| import { Experiment } from 'tsp-typescript-client/lib/models/experiment'; | ||
| import { TraceViewerPanel } from '../trace-viewer-panel/trace-viewer-webview-panel'; | ||
| import * as vscode from 'vscode'; | ||
| import { traceExtensionWebviewManager } from '../extension'; | ||
|
|
||
| export interface ExternalAPI { | ||
| getActiveExperiment(): Experiment | undefined, | ||
| getActiveWebviewPanels(): { [key: string]: TraceViewerPanel | undefined; }, | ||
| getActiveWebviews(): vscode.WebviewView[], | ||
| onWebviewCreated(listener: (data: vscode.WebviewView) => void): void, | ||
| onWebviewPanelCreated(listener: (data: vscode.WebviewPanel) => void): void, | ||
| } | ||
|
|
||
| export const traceExtensionAPI: ExternalAPI = { | ||
| /** | ||
| * Retrieves the currently active experiment | ||
| * | ||
| * @returns Experiment if one is currently active, otherwise undefined | ||
| */ | ||
| getActiveExperiment(): Experiment | undefined { | ||
| return TraceViewerPanel.getCurrentExperiment(); | ||
| }, | ||
|
|
||
| /** | ||
| * Retrieves active trace panels | ||
| * | ||
| * @returns Key value pairs where the value is of TraceViewerPanel type if panel with that key is active, otherwise undefined | ||
| */ | ||
| getActiveWebviewPanels(): { [key: string]: TraceViewerPanel | undefined; } { | ||
| return TraceViewerPanel.activePanels; | ||
| }, | ||
|
|
||
| /** | ||
| * Retrieves active webviews | ||
| * | ||
| * @returns List of active webviews | ||
| */ | ||
| getActiveWebviews(): vscode.WebviewView[] { | ||
| return traceExtensionWebviewManager.getAllActiveWebviews(); | ||
| }, | ||
|
|
||
| /** | ||
| * Registers an event listener for onWebviewCreated event | ||
| * | ||
| * @param listener event listener | ||
| */ | ||
| onWebviewCreated(listener: (data: vscode.WebviewView) => void): void { | ||
| traceExtensionWebviewManager.onWebviewCreated(listener); | ||
| }, | ||
|
|
||
| /** | ||
| * Registers an event listener for onWebviewPanelCreated event | ||
| * | ||
| * @param listener event listener | ||
| */ | ||
| onWebviewPanelCreated(listener: (data: vscode.WebviewPanel) => void): void { | ||
| traceExtensionWebviewManager.onWebviewPanelCreated(listener); | ||
| } | ||
marco-miller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
78 changes: 78 additions & 0 deletions
78
vscode-trace-extension/src/utils/trace-extension-webview-manager.ts
This file contains hidden or 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,78 @@ | ||
| /*************************************************************************************** | ||
| * Copyright (c) 2023 BlackBerry Limited and others. | ||
| * | ||
| * Licensed under the MIT license. See LICENSE file in the project root for details. | ||
| ***************************************************************************************/ | ||
| import * as vscode from 'vscode'; | ||
|
|
||
| /** | ||
| * Manages webview panels and webviews creation events | ||
| */ | ||
| export class TraceExtensionWebviewManager { | ||
| private webviews: vscode.WebviewView[] = []; | ||
| private webviewCreated: vscode.EventEmitter<vscode.WebviewView> = new vscode.EventEmitter(); | ||
| private webviewPanelCreated: vscode.EventEmitter<vscode.WebviewPanel> = new vscode.EventEmitter(); | ||
| private isManagerDisposed = false; | ||
|
|
||
| getAllActiveWebviews(): vscode.WebviewView[] { | ||
| if (!this.isDisposed()) { | ||
| return this.webviews; | ||
| } | ||
| return []; | ||
| } | ||
|
|
||
| fireWebviewCreated(_webview: vscode.WebviewView): void { | ||
| if (!this.isDisposed()) { | ||
| this.addWebview(_webview); | ||
| this.webviewCreated.fire(_webview); | ||
| } | ||
| } | ||
|
|
||
| fireWebviewPanelCreated(_webviewPanel: vscode.WebviewPanel): void { | ||
| if (!this.isDisposed()) { | ||
| this.webviewPanelCreated.fire(_webviewPanel); | ||
| } | ||
| } | ||
|
|
||
| onWebviewCreated(listener: (data: vscode.WebviewView) => unknown): void { | ||
| if (!this.isDisposed()) { | ||
| this.webviewCreated.event(listener); | ||
| } | ||
| } | ||
|
|
||
| onWebviewPanelCreated(listener: (data: vscode.WebviewPanel) => unknown): void { | ||
| if (!this.isDisposed()) { | ||
| this.webviewPanelCreated.event(listener); | ||
| } | ||
| } | ||
|
|
||
| dispose(): void { | ||
| if (!this.isDisposed()) { | ||
| this.webviews = []; | ||
| this.webviewCreated.dispose(); | ||
| this.webviewPanelCreated.dispose(); | ||
| this.isManagerDisposed = true; | ||
| } | ||
| } | ||
|
|
||
| isDisposed(): boolean { | ||
| return this.isManagerDisposed; | ||
| } | ||
|
|
||
| private addWebview(webview: vscode.WebviewView): void { | ||
| // Remove it from the array when the webview disposes | ||
| webview.onDidDispose(() => { | ||
| this.removeWebview(webview); | ||
| }); | ||
| this.webviews.push(webview); | ||
| } | ||
|
|
||
| private removeWebview(_webview: vscode.WebviewView): void { | ||
| this.webviews.filter(webview => webview === _webview).forEach(webview => { | ||
| const index = this.webviews.indexOf(webview); | ||
| if (index !== -1) { | ||
| this.webviews.splice(index, 1); | ||
| } | ||
| }); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.