Skip to content

integrated webview manager to work with webviewview alongside panel. #41

Merged
jan3tlim merged 6 commits intomainfrom
fileWatcherFixes
Mar 25, 2026
Merged

integrated webview manager to work with webviewview alongside panel. #41
jan3tlim merged 6 commits intomainfrom
fileWatcherFixes

Conversation

@logann-tom
Copy link
Copy Markdown
Collaborator

Added functionality to add webview containers (webviewview/webviewpanel) to the manager so it could work with webviewview provider. Fixed syntax errors in rendering html.

PS: pls try and run extension to ensure pushed code doesnt break anything in future

…Added functionality to add webview containers (webviewview/webviewpanel) to the manager so it could work with webviewview provider. Fixed syntax errors in rendering html
@logann-tom logann-tom requested a review from pdsl2005 March 25, 2026 19:15
Comment thread src/extension.ts Outdated
context.subscriptions.push(
vscode.window.registerWebviewViewProvider("codescape.Cityview", provider),
);
// const create = vscode.commands.registerCommand("codescape.createPanel", () =>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why comment this

Comment thread src/extension.ts Outdated
}

function createPanel(context : vscode.ExtensionContext, store: FileParseStore){
// function createPanel(context : vscode.ExtensionContext, javaWatcher : JavaFileWatcher, store: FileParseStore){
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why comment all this

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the extension’s webview orchestration so a single manager can track and broadcast state to both WebviewPanel instances (commands) and a WebviewView (sidebar provider), aiming to unify multi-view rendering and state sync.

Changes:

  • Refactors WebviewManager to manage a generic “webview container” (WebviewView or WebviewPanel) and adds an addWebview(...) entry point.
  • Updates extension activation commands to create panels via createPanel(...) and registers the sidebar view with the manager.
  • Tweaks file watcher internals (rename java watcher field, guard a Python delete path).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
src/extension.ts Switches commands to createPanel, registers sidebar WebviewView with manager, and adjusts/extends webview script logging and rendering code.
src/WebviewManager.ts Adds support for managing both WebviewPanel and WebviewView, and uses shared getWebviewContent(...) to set HTML.
src/JavaFileWatcher.ts Renames the Java watcher field and adds a “no webviews yet” guard in the Python delete handler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/extension.ts
Comment thread src/extension.ts
Comment on lines 758 to 763
fileData = msg.payload.files;
render();
} else if (msg.type === 'PARTIAL_STATE' && msg.payload) {
console.log("PARTIAL STATE CHANGE RECIEVE")
//create default values because may not exist in payload
const { changed = [], related = [], removed = [] } = msg.payload;
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message handler assigns to and later exports fileData, but fileData is not declared anywhere in this script (earlier comment says state replaces it). This will throw at runtime on the first FULL_STATE/AST_DATA message or export click. Either declare let fileData = [] (and keep it in sync), or migrate these code paths to use state.classes instead of fileData.

Copilot uses AI. Check for mistakes.
Comment thread src/extension.ts Outdated
Comment thread src/WebviewManager.ts
Comment on lines +57 to +67
// WebviewView is already ready when provider gives it to us
if ('onDidChangeVisibility' in container) {
managedWebview.isReady = true;
if (this.lastFullState) {
container.webview.postMessage({
type: 'FULL_STATE',
payload: this.lastFullState,
});
}
}
container.webview.onDidReceiveMessage((message) => {
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addWebview() marks a WebviewView as ready based on 'onDidChangeVisibility' in container and immediately posts FULL_STATE. Messages posted before the webview script runs / registers its window.addEventListener('message', ...) handler can be dropped, which is why the READY handshake exists. Consider treating WebviewView the same as panels: wait for the webview to send { type: 'READY' } before setting isReady and sending FULL_STATE (or buffer via messageQueue and flush on READY).

Suggested change
// WebviewView is already ready when provider gives it to us
if ('onDidChangeVisibility' in container) {
managedWebview.isReady = true;
if (this.lastFullState) {
container.webview.postMessage({
type: 'FULL_STATE',
payload: this.lastFullState,
});
}
}
container.webview.onDidReceiveMessage((message) => {
container.webview.onDidReceiveMessage((message) => {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webviewview handshake already completed when provider returns it. Therefore needed way to add a webviewview without needing necessarily requiring handshake.

Comment thread src/extension.ts Outdated
Comment thread src/WebviewManager.ts
Comment on lines 1 to +3
import * as vscode from 'vscode';
import { ClassInfo } from './parser/javaExtractor';
import {getWebviewContent} from './extension'
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebviewManager now imports getWebviewContent from ./extension, while extension.ts imports WebviewManager, creating a circular dependency that can make getWebviewContent undefined at runtime (depending on module initialization order). Move getWebviewContent into a separate module (e.g., src/webview/getWebviewContent.ts) that both files import, or keep the HTML builder inside WebviewManager to avoid the cycle.

Copilot uses AI. Check for mistakes.
Comment thread src/WebviewManager.ts
Comment on lines 145 to +152
disposeAll(): void {
for (const managed of this.webviews.values()) {
managed.panel.dispose();
for (const id of this.webviews.keys()) {
let managed = this.webviews.get(id);
if(managed != null && 'dispose' in managed.container){
managed.container.dispose();
this.webviews.delete(id);
}
this.webviews.clear();
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disposeAll() only disposes/deletes entries when the container has a dispose() method; WebviewView instances won't be removed from this.webviews, so getActiveViewCount() will remain non-zero and broadcasts may target disposed views. Consider always deleting map entries, and only calling dispose() when available (also avoid mutating the map while iterating its keys).

Copilot uses AI. Check for mistakes.
Comment thread src/extension.ts
Comment on lines 574 to +577
// Registry of rendered buildings for hit detection (hover/click).
// Each entry is tracked in canvas/world coordinates before zoom.
const buildingRegistry = [];
//NOTE: THIS STOPS RENDER FROM RUNNING
//const buildingRegistry = [];
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment and commented-out buildingRegistry redeclaration should be removed rather than left in-place. The actual issue is that buildingRegistry is already declared earlier (let buildingRegistry = []), so redeclaring it here would cause a runtime/parse error; keeping this commented code and note is misleading and increases maintenance burden.

Copilot uses AI. Check for mistakes.
logann-tom and others added 3 commits March 25, 2026 18:11
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jan3tlim jan3tlim merged commit 0d287a1 into main Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants