Conversation
- Extracted `WebviewCollection` class to `src/webview-collection.ts` to isolate it from `vscode` module dependency. - Updated `src/helpers.ts` to re-export `WebviewCollection`. - Added comprehensive unit tests in `tests/unit/webview_collection.test.ts`. Co-authored-by: zknpr <96851588+zknpr@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello @zknpr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the robustness and maintainability of the webview management system by extracting the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a solid improvement. It refactors the WebviewCollection class into its own dedicated file, which enhances modularity and makes the code easier to maintain. The addition of a comprehensive unit test suite for this class is excellent, as it significantly boosts confidence in its functionality and future changes. I have one suggestion to improve the performance of the WebviewCollection by optimizing its internal data structures for faster lookups.
| export class WebviewCollection { | ||
| /** Internal storage for URI to panel mappings */ | ||
| private readonly entries = new Set<{ | ||
| readonly uriString: string; | ||
| readonly panel: WebviewPanel; | ||
| }>(); | ||
|
|
||
| /** Map from webview ID to panel for direct lookup */ | ||
| private readonly idLookup = new Map<string, WebviewPanel>(); | ||
|
|
||
| /** | ||
| * Iterate all panels associated with a document URI. | ||
| * | ||
| * @param uri - Document URI to look up | ||
| * @yields WebviewPanel instances for this URI | ||
| */ | ||
| public *get(uri: Uri): IterableIterator<WebviewPanel> { | ||
| const targetKey = uri.toString(); | ||
| for (const entry of this.entries) { | ||
| if (entry.uriString === targetKey) { | ||
| yield entry.panel; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Find a panel by its unique webview ID. | ||
| * | ||
| * @param webviewId - Unique identifier for the webview | ||
| * @returns Panel if found, undefined otherwise | ||
| */ | ||
| public getByWebviewId(webviewId: string): WebviewPanel | undefined { | ||
| return this.idLookup.get(webviewId); | ||
| } | ||
|
|
||
| /** | ||
| * Check if any panels exist for a document URI. | ||
| * | ||
| * @param uri - Document URI to check | ||
| * @returns True if at least one panel exists | ||
| */ | ||
| public has(uri: Uri): boolean { | ||
| return !this.get(uri).next().done; | ||
| } | ||
|
|
||
| /** | ||
| * Register a new webview panel. | ||
| * | ||
| * @param uri - Associated document URI | ||
| * @param panel - Webview panel instance | ||
| * @param webviewId - Unique identifier for this webview | ||
| */ | ||
| public add(uri: Uri, panel: WebviewPanel, webviewId: string): void { | ||
| const entry = { uriString: uri.toString(), panel }; | ||
| this.entries.add(entry); | ||
| this.idLookup.set(webviewId, panel); | ||
|
|
||
| // Auto-cleanup on panel disposal | ||
| panel.onDidDispose(() => { | ||
| this.entries.delete(entry); | ||
| this.idLookup.delete(webviewId); | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
The current implementation of WebviewCollection uses a Set to store all panel entries. This leads to O(N) complexity for get(uri) and has(uri) operations, where N is the total number of webview panels. This could become a performance bottleneck if a large number of panels are open.
To improve performance, I recommend using a Map to group panels by their URI string. This would change the lookup complexity to O(1), making it much more efficient.
Below is a suggested refactoring of the class that implements this change.
export class WebviewCollection {
/** Map from URI string to a set of panels */
private readonly uriLookup = new Map<string, Set<WebviewPanel>>();
/** Map from webview ID to panel for direct lookup */
private readonly idLookup = new Map<string, WebviewPanel>();
/**
* Iterate all panels associated with a document URI.
*
* @param uri - Document URI to look up
* @yields WebviewPanel instances for this URI
*/
public *get(uri: Uri): IterableIterator<WebviewPanel> {
const panels = this.uriLookup.get(uri.toString());
if (panels) {
yield* panels;
}
}
/**
* Find a panel by its unique webview ID.
*
* @param webviewId - Unique identifier for the webview
* @returns Panel if found, undefined otherwise
*/
public getByWebviewId(webviewId: string): WebviewPanel | undefined {
return this.idLookup.get(webviewId);
}
/**
* Check if any panels exist for a document URI.
*
* @param uri - Document URI to check
* @returns True if at least one panel exists
*/
public has(uri: Uri): boolean {
const panels = this.uriLookup.get(uri.toString());
return !!panels && panels.size > 0;
}
/**
* Register a new webview panel.
*
* @param uri - Associated document URI
* @param panel - Webview panel instance
* @param webviewId - Unique identifier for this webview
*/
public add(uri: Uri, panel: WebviewPanel, webviewId: string): void {
const uriString = uri.toString();
let panels = this.uriLookup.get(uriString);
if (!panels) {
panels = new Set();
this.uriLookup.set(uriString, panels);
}
panels.add(panel);
this.idLookup.set(webviewId, panel);
// Auto-cleanup on panel disposal
panel.onDidDispose(() => {
const panelsForUri = this.uriLookup.get(uriString);
if (panelsForUri) {
panelsForUri.delete(panel);
if (panelsForUri.size === 0) {
this.uriLookup.delete(uriString);
}
}
this.idLookup.delete(webviewId);
});
}
}|
Merged as part of v1.3.0 release in PR #65 |
Acknowledged. Thank you for the update. |
🎯 What: add tests for
WebviewCollection📊 Coverage:
add,get,getByWebviewId,hasand panel disposal logic✨ Result: The
WebviewCollectionclass is now unit-testable and fully covered.PR created automatically by Jules for task 6092940338158183239 started by @zknpr