Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(webview-view): show webview views in every container under their when

rokartur8e58d657fa22
diff --git a/README.md b/README.md
index ca76f9f09d8..d62904827f1 100644
--- a/README.md
+++ b/README.md
@@ -11,8 +11,8 @@ Coverage of VS Code 1.147.0, from [port/ledger.md](port/ledger.md) (584 rows). V
```mermaid
pie showData
- "verified" : 412
- "ported" : 18
+ "verified" : 413
+ "ported" : 17
"removed" : 126
"n/a" : 28
```
@@ -20,7 +20,7 @@ pie showData
| area | verified | ported | removed | n/a | verified of in scope |
|---|---:|---:|---:|---:|---|
| src/vs/platform | 68 | 1 | 30 | 13 | `████████████████████ 99%` |
-| workbench contribution | 62 | 6 | 30 | 3 | `██████████████████░░ 91%` |
+| workbench contribution | 63 | 5 | 30 | 3 | `███████████████████░ 93%` |
| built-in extension | 88 | 1 | 6 | 0 | `████████████████████ 99%` |
| MainThread* shape (Rust side) | 59 | 0 | 30 | 0 | `████████████████████ 100%` |
| workbench service | 59 | 6 | 23 | 7 | `██████████████████░░ 91%` |
@@ -31,7 +31,7 @@ pie showData
| src/vs/editor | 0 | 2 | 1 | 1 | `░░░░░░░░░░░░░░░░░░░░ 0%` |
| src/vs/base | 0 | 0 | 2 | 3 | `████████████████████ 100%` |
| port feature | 1 | 0 | 0 | 0 | `████████████████████ 100%` |
-| **all** | **412** | **18** | **126** | **28** | `███████████████████░ 96%` |
+| **all** | **413** | **17** | **126** | **28** | `███████████████████░ 96%` |
<!-- coverage:end -->
`removed` are parts left out by decision: AI features, Microsoft services, telemetry, remote and tunnels ([port/notes.md](port/notes.md)). `n/a` are upstream test infrastructure and the Electron process, IPC and DOM layers the native architecture replaces.
diff --git a/native/crates/app/src/main.rs b/native/crates/app/src/main.rs
index 45a477f8c72..6ddde4d0ae0 100644
--- a/native/crates/app/src/main.rs
+++ b/native/crates/app/src/main.rs
@@ -562,7 +562,6 @@ pub(crate) fn open_window(request: WindowRequest, cx: &mut App) -> anyhow::Resul
extension_point_messages::report(&extensions);
workbench.host.set_running_extensions(&extensions);
workbench.extensions = extensions.clone();
- workbench.register_webview_view_commands();
workbench.start_tasks();
if let Some(folder) = &export_default_keybindings {
match workbench.export_default_keybindings(folder) {
diff --git a/native/crates/app/src/workbench.rs b/native/crates/app/src/workbench.rs
index ed4d07cbd27..12ebe56ea31 100644
--- a/native/crates/app/src/workbench.rs
+++ b/native/crates/app/src/workbench.rs
@@ -1666,10 +1666,7 @@ impl Workbench {
if self.side_bar_view == SideBarView::Testing {
return self.testing_side_bar(window, cx).children(self.testing_contributed_sections(window, cx));
}
- let has_folder = self.folder.as_ref().is_some_and(|tree| !tree.workspace.folders.is_empty());
self.explorer_view_container(window, cx)
- // shortcut: extension webview views sit below the Explorer's panes, not in view_panes.rs; milestone 11 moves them in.
- .when(has_folder, |container| container.children(self.webview_view_panes(cx)))
// The pane view is laid out 5px shorter than the side bar content.
.child(div().h(px(5.)).flex_none())
}
diff --git a/native/crates/app/src/workbench/accessible_view.rs b/native/crates/app/src/workbench/accessible_view.rs
index fe94db6e2f1..292e852520f 100644
--- a/native/crates/app/src/workbench/accessible_view.rs
+++ b/native/crates/app/src/workbench/accessible_view.rs
@@ -255,10 +255,7 @@ impl Workbench {
}
fn view_accessibility_help_content(&self, view: &str) -> Option<String> {
- match self.tree_views.views.iter().find(|contributed| contributed.id == view) {
- Some(contributed) => contributed.accessibility_help_content.clone(),
- None => self.webview_view_accessibility_help_content(view),
- }
+ self.tree_views.views.iter().find(|contributed| contributed.id == view)?.accessibility_help_content.clone()
}
fn notification_focused(&self, window: &Window) -> Option<u64> {
@@ -1220,7 +1217,7 @@ mod tests {
let (workbench, cx) = cx.add_window_view(|_, cx| {
let mut workbench = Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx);
workbench.extensions = vec![exthost::scan::ScannedExtension { id: "test.views".into(), location: "/x".into(), description }];
- workbench.register_webview_view_commands();
+ workbench.set_tree_views(&workbench.extensions.clone());
workbench
});
cx.update(|window, _| window.activate_window());
diff --git a/native/crates/app/src/workbench/activity.rs b/native/crates/app/src/workbench/activity.rs
index deb709eb049..96bf8526a65 100644
--- a/native/crates/app/src/workbench/activity.rs
+++ b/native/crates/app/src/workbench/activity.rs
@@ -128,7 +128,6 @@ impl Workbench {
}
match container {
"workbench.view.explorer" => {
- badges.extend(self.webview_view_badges().map(Badge::Number));
badges.push(Badge::Number(self.dirty_working_copy_count()));
}
"workbench.view.scm" => badges.push(Badge::Number(self.scm_badge())),
diff --git a/native/crates/app/src/workbench/extension_management.rs b/native/crates/app/src/workbench/extension_management.rs
index 8c454c99af1..c5271c9f3f0 100644
--- a/native/crates/app/src/workbench/extension_management.rs
+++ b/native/crates/app/src/workbench/extension_management.rs
@@ -296,7 +296,6 @@ impl Workbench {
crate::extension_point_messages::report(&running);
self.host.set_running_extensions(&running);
self.extensions = running;
- self.register_webview_view_commands();
self.refresh_extensions_views(cx);
cx.notify();
}
diff --git a/native/crates/app/src/workbench/part_grid/tests.rs b/native/crates/app/src/workbench/part_grid/tests.rs
index 17531bc6f2a..69ef1b4e3a7 100644
--- a/native/crates/app/src/workbench/part_grid/tests.rs
+++ b/native/crates/app/src/workbench/part_grid/tests.rs
@@ -357,30 +357,6 @@ fn progress_at_a_view_container_badges_its_activity_bar_item(cx: &mut TestAppCon
assert!(!badges(window_cx).contains(&Badge::Progress));
}
-/// webviewViewPane.ts `updateBadge`: a webview view's `$setWebviewViewBadge` badges the Explorer's item until cleared.
-#[gpui::test]
-fn a_webview_view_badge_shows_on_the_explorer_item(cx: &mut TestAppContext) {
- use super::super::activity::Badge;
- use serde_json::json;
- let dir = std::env::temp_dir().join(format!("code-gpui-webview-view-badge-{}", std::process::id()));
- std::fs::create_dir_all(&dir).unwrap();
- let (workbench, window_cx) = open(Some(dir.clone()), &stores(), cx);
- let views = json!({ "contributes": { "views": { "explorer": [{ "type": "webview", "id": "port.view", "name": "Port View" }] } } });
- workbench.update_in(window_cx, |workbench, window, cx| {
- workbench.extensions.push(exthost::scan::ScannedExtension { id: "port.test".into(), location: PathBuf::new(), description: views });
- drop(workbench.handle_webview_views_request("$registerWebviewViewProvider", &[json!({ "id": "port.test" }), json!("port.view"), json!({})], window, cx));
- workbench.open_webview_view("port.view", true, window, cx);
- workbench.update_webview_views();
- });
- let badge = |value: serde_json::Value, cx: &mut VisualTestContext| {
- workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_webview_views_request("$setWebviewViewBadge", &[json!("webview-view-1"), value], window, cx)));
- workbench.read_with(cx, |workbench, _| workbench.container_badges("workbench.view.explorer"))
- };
- assert!(badge(json!({ "value": 3, "tooltip": "3 items" }), window_cx).contains(&Badge::Number(3)));
- assert!(!badge(serde_json::Value::Null, window_cx).contains(&Badge::Number(3)));
- std::fs::remove_dir_all(&dir).unwrap();
-}
-
/// compositeBarActions.ts `CompositeBarActionViewItem` click: Source Control, Run and Debug and Extensions open their views.
#[gpui::test]
fn the_source_control_run_and_debug_and_extensions_items_open_their_views(cx: &mut TestAppContext) {
diff --git a/native/crates/app/src/workbench/tree_view.rs b/native/crates/app/src/workbench/tree_view.rs
index 1f38be2e06d..53216552ccf 100644
--- a/native/crates/app/src/workbench/tree_view.rs
+++ b/native/crates/app/src/workbench/tree_view.rs
@@ -24,7 +24,7 @@ use crate::notifications::{Node, Severity, parse_linked_text};
#[cfg(test)]
mod tests;
-/// A tree view of `contributes.views`.
+/// A tree or webview view of `contributes.views`.
pub(super) struct ContributedView {
pub id: &'static str,
pub name: String,
@@ -37,6 +37,8 @@ pub(super) struct ContributedView {
pub collapsed: bool,
/// `accessibilityHelpContent`, read only with the `contribAccessibilityHelpContent` proposal enabled.
pub accessibility_help_content: Option<String>,
+ /// `type: webview`: a webview view (webview_views.rs), whose pane holds a webview, not a tree.
+ pub webview: bool,
}
#[derive(Default)]
@@ -92,8 +94,7 @@ pub(super) fn static_id(id: &str) -> &'static str {
interned
}
-/// viewsExtensionPoint.ts: the tree views of every container, in extension order. Webview views (`type: webview`)
-/// are webview_views.rs's.
+/// viewsExtensionPoint.ts: the tree and webview views of every container, in extension order.
pub(super) fn contributed_views(extensions: &[exthost::scan::ScannedExtension]) -> Vec<ContributedView> {
let mut known_containers: HashSet<String> = ["explorer", "debug", "scm", "remote"].map(String::from).into();
known_containers.extend(super::view_containers::valid_view_containers(extensions).into_iter().filter(|(_, location, _)| ["activitybar", "panel", "secondarySidebar"].contains(location)).filter_map(|(_, _, descriptor)| descriptor["id"].as_str().map(String::from)));
@@ -146,11 +147,8 @@ pub(super) fn contributed_views(extensions: &[exthost::scan::ScannedExtension])
}
};
ids.insert(id);
- if webview {
- continue;
- }
let (hide_by_default, collapsed) = super::view_visibility::initial_visibility(view);
- views.push(ContributedView { id: static_id(id), name: view["name"].as_str().expect("validated").to_owned(), container: container.clone(), when: view["when"].as_str().and_then(Expr::deserialize), hide_by_default, collapsed, accessibility_help_content: accessibility_help_content(extension, view) });
+ views.push(ContributedView { id: static_id(id), name: view["name"].as_str().expect("validated").to_owned(), container: container.clone(), when: view["when"].as_str().and_then(Expr::deserialize), hide_by_default, collapsed, accessibility_help_content: accessibility_help_content(extension, view), webview });
}
}
}
@@ -270,7 +268,7 @@ impl Workbench {
/// The `$setBadge` value of a contributed view (`{ value, tooltip }`).
pub(super) fn tree_view_badge(&self, id: &str) -> Option<&Value> {
- self.tree_views.trees.get(id).and_then(|tree| tree.badge.as_ref())
+ self.tree_views.trees.get(id).and_then(|tree| tree.badge.as_ref()).or_else(|| self.webview_view_badge(id))
}
fn update_tree(&mut self, id: &str, update: impl FnOnce(&mut CustomTree), cx: &mut Context<Self>) {
@@ -462,8 +460,12 @@ impl Workbench {
/// The pane of a contributed view: its title (the view's `name`, or `TreeView.title`), title actions, message
/// and rows.
pub(super) fn tree_view_pane(&self, id: &'static str, window: &Window, cx: &mut Context<Self>) -> super::view_panes::ViewPane {
+ let view = self.tree_views.views.iter().find(|view| view.id == id);
+ let name = view.map(|view| view.name.clone()).unwrap_or_default();
+ if view.is_some_and(|view| view.webview) {
+ return self.webview_view_pane(id, name, window, cx);
+ }
let focus = self.tree_views.focus[id].clone();
- let name = self.tree_views.views.iter().find(|view| view.id == id).map(|view| view.name.clone()).unwrap_or_default();
let empty = CustomTree::default();
let tree = self.tree_views.trees.get(id).unwrap_or(&empty);
let title = tree.title.clone().unwrap_or(name);
diff --git a/native/crates/app/src/workbench/tree_view/tests.rs b/native/crates/app/src/workbench/tree_view/tests.rs
index b6c52c7f95b..f2d7df13163 100644
--- a/native/crates/app/src/workbench/tree_view/tests.rs
+++ b/native/crates/app/src/workbench/tree_view/tests.rs
@@ -174,7 +174,7 @@ fn invalid_views_and_view_containers_are_extension_messages() {
let second = extension("test.view-messages-2", json!({ "views": { "explorer": [{ "id": "test.one", "name": "Elsewhere" }, { "id": "test.seven", "name": "Seven" }], "scm": [{ "id": "test.six", "name": "Six", "when": true }] } }));
let views = super::contributed_views(&[first, second]);
let shown: Vec<(&str, &str)> = views.iter().map(|view| (view.id, view.container.as_str())).collect();
- assert_eq!(shown, [("test.one", "good"), ("test.two", "untitled"), ("test.moved", "explorer"), ("test.seven", "explorer")]);
+ assert_eq!(shown, [("test.one", "good"), ("test.web", "good"), ("test.two", "untitled"), ("test.moved", "explorer"), ("test.seven", "explorer")]);
let messages = crate::perf::messages;
let expected = |messages: &[(crate::notifications::Severity, &str)]| messages.iter().map(|(severity, message)| (*severity, message.to_string())).collect::<Vec<_>>();
assert_eq!(messages("test.view-messages"), expected(&[
diff --git a/native/crates/app/src/workbench/view_containers.rs b/native/crates/app/src/workbench/view_containers.rs
index 05e240d2bd2..63966fc8f18 100644
--- a/native/crates/app/src/workbench/view_containers.rs
+++ b/native/crates/app/src/workbench/view_containers.rs
@@ -223,6 +223,9 @@ impl Workbench {
}
fn focus_tree_view(&mut self, id: &'static str, window: &mut Window, cx: &mut Context<Self>) {
+ if self.tree_views.views.iter().any(|view| view.id == id && view.webview) {
+ return self.focus_webview_view(id, window, cx);
+ }
let focus = self.tree_views.focus.entry(id.to_owned()).or_insert_with(|| cx.focus_handle()).clone();
window.focus(&focus, cx);
}
diff --git a/native/crates/app/src/workbench/webview_views.rs b/native/crates/app/src/workbench/webview_views.rs
index 839a67411e3..022d1dc4baa 100644
--- a/native/crates/app/src/workbench/webview_views.rs
+++ b/native/crates/app/src/workbench/webview_views.rs
@@ -1,18 +1,18 @@
-//! mainThreadWebviewViews.ts with contrib/webviewView: the webview views extensions contribute to the Explorer, each a
-//! pane under the folder's tree whose webview lives in the webview panels' list (handled by the same
-//! MainThreadWebviews calls), resolved once the pane first shows and its provider is registered.
+//! mainThreadWebviewViews.ts with contrib/webviewView: the webview views extensions contribute (`type: webview`), panes of
+//! their containers like the tree views (tree_view.rs), whose webview lives in the webview panels' list (handled by the
+//! same MainThreadWebviews calls), resolved once the pane first shows and its provider is registered.
use std::collections::HashMap;
use std::path::PathBuf;
-use exthost::scan::ScannedExtension;
-use gpui::{ClickEvent, Context, Div, Window, div, prelude::*, px};
+use gpui::{Context, Window, prelude::*};
use serde_json::{Value, json};
use super::Workbench;
-use super::search_view::SideBarView;
+use super::view_panes::ViewPane;
use super::webview_panels::WebviewPanel;
use crate::commands::Outcome;
+use crate::menus::MenuId;
/// The scheme of a webview view's entry in the webview panels' list; its path is the view id.
pub const WEBVIEW_VIEW_SCHEME: &str = "webview-view";
@@ -30,12 +30,10 @@ pub struct WebviewViews {
#[derive(Default)]
struct Pane {
- /// The header's toggle; until clicked, the contribution's `visibility`.
- collapsed: Option<bool>,
/// `$setWebviewViewTitle`, shown in place of the contributed name.
title: Option<String>,
description: Option<String>,
- /// `$setWebviewViewBadge` (`{ value, tooltip }`), shown on the Explorer's activity bar item.
+ /// `$setWebviewViewBadge` (`{ value, tooltip }`), shown on its container's activity bar item.
badge: Option<Value>,
/// Set once `$resolveWebviewView` is sent; the webview is the panel entry with this handle.
handle: Option<String>,
@@ -43,14 +41,6 @@ struct Pane {
visible: bool,
}
-/// A `contributes.views.explorer` entry of `type: webview`.
-struct ViewContribution {
- id: String,
- name: String,
- collapsed: bool,
- accessibility_help_content: Option<String>,
-}
-
impl Workbench {
pub(crate) fn handle_webview_views_request(&mut self, method: &str, args: &[Value], window: &mut Window, cx: &mut Context<Self>) -> Outcome {
let arg = |index: usize| args.get(index).cloned().unwrap_or(Value::Null);
@@ -93,37 +83,25 @@ impl Workbench {
self.open_webview_view(&view_id, preserve_focus, window, cx);
}
- /// `viewsService.openView`: a pane not resolved yet takes the focus once its webview exists.
+ /// `viewsService.openView`: shows the view's container and expands its pane.
pub(super) fn open_webview_view(&mut self, view_id: &str, preserve_focus: bool, window: &mut Window, cx: &mut Context<Self>) {
- let pane = self.webview_views.panes.entry(view_id.to_owned()).or_default();
- pane.collapsed = Some(false);
- let handle = pane.handle.clone();
- self.side_bar_view = SideBarView::Explorer;
- cx.notify();
- match handle.filter(|_| !preserve_focus) {
- Some(handle) => self.focus_webview_panel(&handle, window, cx),
- None => self.update_webview_panels(window, cx),
- }
+ self.open_tree_view(view_id, !preserve_focus, window, cx);
}
- /// views.ts registers `<view id>.focus` for every contributed view (`viewsService.openView(id, true)`).
- pub(crate) fn register_webview_view_commands(&mut self) {
- for contribution in webview_view_contributions(&self.extensions) {
- let id = contribution.id;
- self.commands.register(format!("{id}.focus"), move |workbench, _, window, cx| {
- workbench.open_webview_view(&id, false, window, cx);
- Outcome::done()
- });
+ /// The focus of `openView(id, true)`: the resolved webview; a pane not resolved yet takes the focus once its webview exists.
+ pub(super) fn focus_webview_view(&mut self, view_id: &str, window: &mut Window, cx: &mut Context<Self>) {
+ match self.webview_views.panes.get(view_id).and_then(|pane| pane.handle.clone()) {
+ Some(handle) => self.focus_webview_panel(&handle, window, cx),
+ None => self.update_webview_panels(window, cx),
}
}
/// Runs before the webview panels update each render (webviewViewPane.ts `updateTreeVisibility`): a pane whose body
/// shows activates `onView:<id>` and is resolved once its provider is there; the host hears visibility changes.
pub(super) fn update_webview_views(&mut self) {
- let container_visible = self.side_bar_view == SideBarView::Explorer && self.side_bar_visible();
- for contribution in webview_view_contributions(&self.extensions) {
- let pane = self.webview_views.panes.entry(contribution.id.clone()).or_default();
- let visible = container_visible && !pane.collapsed.unwrap_or(contribution.collapsed);
+ let views: Vec<_> = self.tree_views.views.iter().filter(|view| view.webview).map(|view| (view.id, view.name.clone(), self.tree_view_body_visible(view.id))).collect();
+ for (id, name, visible) in views {
+ let pane = self.webview_views.panes.entry(id.to_owned()).or_default();
if let Some(handle) = &pane.handle
&& pane.visible != visible
{
@@ -131,28 +109,28 @@ impl Workbench {
}
pane.visible = visible;
if visible && pane.handle.is_none() {
- self.resolve_webview_view(&contribution);
+ self.resolve_webview_view(id, name);
}
}
}
/// webviewViewPane.ts `activate`, then mainThreadWebviewViews.ts `resolve`.
- fn resolve_webview_view(&mut self, contribution: &ViewContribution) {
- drop(self.host.activate_by_event(&format!("onView:{}", contribution.id)));
- let Some((extension, retain)) = self.webview_views.providers.get(&contribution.id).cloned() else { return };
+ fn resolve_webview_view(&mut self, id: &str, name: String) {
+ drop(self.host.activate_by_event(&format!("onView:{id}")));
+ let Some((extension, retain)) = self.webview_views.providers.get(id).cloned() else { return };
self.webview_views.next_handle += 1;
let handle = format!("webview-view-{}", self.webview_views.next_handle);
- let state_key = view_state_key(&contribution.id);
+ let state_key = view_state_key(id);
let memento = self.workspace_storage.lock().unwrap().get(&state_key).and_then(|text| serde_json::from_str::<Value>(text).ok());
let state = memento.map_or(Value::Null, |memento| memento[WEBVIEW_STATE_KEY].clone());
- let pane = self.webview_views.panes.get_mut(&contribution.id).expect("the pane of a contributed view");
+ let pane = self.webview_views.panes.get_mut(id).expect("the pane of a contributed view");
pane.handle = Some(handle.clone());
- let mut panel = WebviewPanel::new(handle.clone(), WEBVIEW_VIEW_SCHEME.into(), PathBuf::from(&contribution.id), &contribution.id, contribution.name.clone(), &extension, json!({}), retain, None);
+ let mut panel = WebviewPanel::new(handle.clone(), WEBVIEW_VIEW_SCHEME.into(), PathBuf::from(id), id, name, &extension, json!({}), retain, None);
panel.state = state.clone();
self.webview_panels.panels.push(panel);
let parsed = state.as_str().and_then(|text| serde_json::from_str(text).ok()).unwrap_or(Value::Null);
let title = pane.title.clone().map_or(Value::Null, Value::String);
- self.host.send("ExtHostWebviewViews", "$resolveWebviewView", vec![json!(handle), json!(contribution.id), title, parsed]);
+ self.host.send("ExtHostWebviewViews", "$resolveWebviewView", vec![json!(handle), json!(id), title, parsed]);
}
/// The webview view whose webview has the keyboard: its pane is the focused view.
@@ -161,13 +139,9 @@ impl Workbench {
Some(super::tree_view::static_id(&panel.view_type))
}
- pub(super) fn webview_view_accessibility_help_content(&self, view: &str) -> Option<String> {
- webview_view_contributions(&self.extensions).into_iter().find(|contribution| contribution.id == view)?.accessibility_help_content
- }
-
- /// The `$setWebviewViewBadge` values of the webview views, all in the Explorer.
- pub(super) fn webview_view_badges(&self) -> impl Iterator<Item = u64> + '_ {
- self.webview_views.panes.values().filter_map(|pane| pane.badge.as_ref()?["value"].as_u64())
+ /// The `$setWebviewViewBadge` value of a webview view.
+ pub(super) fn webview_view_badge(&self, view_id: &str) -> Option<&Value> {
+ self.webview_views.panes.get(view_id)?.badge.as_ref()
}
/// The view ids whose pane body shows, as the paths of their webview panel entries.
@@ -181,31 +155,24 @@ impl Workbench {
self.workspace_storage.lock().unwrap().set(&view_state_key(view_id), memento.to_string());
}
- /// The Explorer's contributed webview view panes, after its own sections.
- pub(super) fn webview_view_panes(&self, cx: &mut Context<Self>) -> Vec<Div> {
- let mut panes = Vec::new();
- for contribution in webview_view_contributions(&self.extensions) {
- let pane = self.webview_views.panes.get(&contribution.id);
- let expanded = !pane.and_then(|pane| pane.collapsed).unwrap_or(contribution.collapsed);
- let title = pane.and_then(|pane| pane.title.clone()).unwrap_or(contribution.name.clone());
- let description = pane.and_then(|pane| pane.description.clone());
- let id = contribution.id.clone();
- let header = self
- .section_header(&title, expanded, true)
- .when_some(description, |header, description| {
- header.child(div().ml(px(4.)).text_size(px(11.)).text_color(self.color("descriptionForeground")).child(description))
- })
- .id(format!("webview-view-header-{id}"))
- .on_click(cx.listener(move |workbench, _: &ClickEvent, _, cx| {
- let pane = workbench.webview_views.panes.entry(id.clone()).or_default();
- pane.collapsed = Some(expanded);
- cx.notify();
- }));
- let handle = pane.and_then(|pane| pane.handle.as_deref());
- let body = expanded.then(|| self.webview_body(|panel| Some(panel.handle.as_str()) == handle));
- panes.push(div().flex().flex_col().when(expanded, |pane| pane.flex_1().min_h_0()).child(header).children(body));
+ /// webviewViewPane.ts: the view's title (`$setWebviewViewTitle`, else its `name`), description, title actions
+ /// and the box its webview is placed over.
+ pub(super) fn webview_view_pane(&self, id: &'static str, name: String, window: &Window, cx: &mut Context<Self>) -> ViewPane {
+ let pane = self.webview_views.panes.get(id);
+ let mut context = self.key_context(window);
+ context.insert("view".into(), json!(id));
+ // paneCompositePart.css: 4px after each title action.
+ let actions = self.inline_actions(MenuId::ViewTitle, Some(id), &context, Vec::new(), self.foreground_or("sideBar.foreground"), cx).gap(gpui::px(4.)).into_any_element();
+ let handle = pane.and_then(|pane| pane.handle.as_deref());
+ ViewPane {
+ id,
+ title: pane.and_then(|pane| pane.title.clone()).unwrap_or(name),
+ description: pane.and_then(|pane| pane.description.clone()),
+ actions: Some(actions),
+ draws_more: false,
+ show_actions: self.focused_webview_view() == Some(id),
+ body: self.webview_body(|panel| Some(panel.handle.as_str()) == handle).into_any_element(),
}
- panes
}
}
@@ -213,19 +180,5 @@ fn view_state_key(view_id: &str) -> String {
format!("memento/webviewView.{view_id}")
}
-/// viewsExtensionPoint.ts: the `views.explorer` entries of `type: webview`.
-// shortcut: views in other containers wait for contributed view containers (milestone 11); `when` is not evaluated.
-// Every Explorer view starts collapsed, whatever its `visibility` (viewsExtensionPoint.ts `showCollapsed`).
-fn webview_view_contributions(extensions: &[ScannedExtension]) -> Vec<ViewContribution> {
- let mut contributions = Vec::new();
- for extension in extensions {
- for view in extension.description["contributes"]["views"]["explorer"].as_array().into_iter().flatten() {
- let (Some(id), Some(name)) = (view["id"].as_str(), view["name"].as_str()) else { continue };
- if view["type"] != "webview" {
- continue;
- }
- contributions.push(ViewContribution { id: id.to_owned(), name: name.to_owned(), collapsed: true, accessibility_help_content: super::tree_view::accessibility_help_content(extension, view) });
- }
- }
- contributions
-}
+#[cfg(test)]
+mod tests;
diff --git a/native/crates/app/src/workbench/webview_views/tests.rs b/native/crates/app/src/workbench/webview_views/tests.rs
new file mode 100644
index 00000000000..39728012dd6
--- /dev/null
+++ b/native/crates/app/src/workbench/webview_views/tests.rs
@@ -0,0 +1,64 @@
+use std::path::Path;
+use std::sync::{Arc, Mutex};
+
+use config::registry::Registry;
+use config::service::Settings;
+use gpui::{TestAppContext, VisualTestContext};
+use serde_json::{Value, json};
+
+use crate::host_sync::HostSync;
+use crate::languages::Languages;
+use crate::theme::load_theme;
+use crate::workbench::Workbench;
+use crate::workbench::activity::Badge;
+use crate::workbench::view_panes::PaneContainer;
+
+/// viewsExtensionPoint.ts registers a `type: webview` view in its own container under its `when`, like a tree view:
+/// a Source Control webview view resolves only while its `when` holds and its pane shows, and badges Source Control.
+#[gpui::test]
+fn a_webview_view_shows_in_its_own_container_while_its_when_holds(cx: &mut TestAppContext) {
+ let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
+ let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
+ let theme = load_theme(&[themes], "Dark Modern").unwrap();
+ let dir = std::env::temp_dir().join(format!("vsrustium-webview-view-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(&dir).unwrap();
+ let workspace = config::workspace::Workspace::folder(dir.clone());
+ let settings = Arc::new(Mutex::new(Settings::load(Registry::with_extensions(&[]), dir.join("User"), Some(workspace.clone()))));
+ let view = json!({ "type": "webview", "id": "test.web", "name": "Web", "when": "test.show" });
+ let extension = exthost::scan::ScannedExtension { id: "test.views".into(), location: "/x".into(), description: json!({ "contributes": { "views": { "scm": [view] } } }) };
+ let (sender, receiver) = std::sync::mpsc::channel();
+ let (workbench, cx) = cx.add_window_view(|_, cx| {
+ let mut workbench = Workbench::new(theme, app_root.clone(), Some(workspace), Languages::new(&[]), settings, HostSync::new(sender), cx);
+ workbench.set_tree_views(std::slice::from_ref(&extension));
+ workbench.extensions = vec![extension];
+ workbench
+ });
+ let draw = |cx: &mut VisualTestContext| {
+ cx.update(|window, cx| drop(window.draw(cx)));
+ cx.run_until_parked();
+ };
+ cx.update(|window, _| window.activate_window());
+ draw(cx);
+ let focus_view = |cx: &mut VisualTestContext| {
+ drop(workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("test.web.focus", Vec::new(), window, cx)));
+ draw(cx);
+ receiver.try_iter().filter(|message| message.method == "$resolveWebviewView").map(|message| message.args[1].clone()).collect::<Vec<Value>>()
+ };
+ workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_webview_views_request("$registerWebviewViewProvider", &[json!({ "id": "test.views" }), json!("test.web"), json!({})], window, cx)));
+
+ assert_eq!(focus_view(cx), Vec::<Value>::new(), "a webview view whose when is false is not shown");
+ workbench.update(cx, |workbench, _| drop(workbench.context_keys.insert("test.show".into(), json!(true))));
+ draw(cx);
+ assert_eq!(focus_view(cx), vec![json!("test.web")]);
+ assert!(workbench.read_with(cx, |workbench, _| workbench.view_pane_expanded(PaneContainer::Scm, "test.web")));
+
+ let badges = |badge: Value, container: &str, cx: &mut VisualTestContext| {
+ workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_webview_views_request("$setWebviewViewBadge", &[json!("webview-view-1"), badge], window, cx)));
+ workbench.read_with(cx, |workbench, _| workbench.container_badges(container))
+ };
+ assert!(badges(json!({ "value": 3, "tooltip": "3 items" }), "workbench.view.scm", cx).contains(&Badge::Number(3)));
+ assert!(!badges(json!({ "value": 3 }), "workbench.view.explorer", cx).contains(&Badge::Number(3)));
+ assert!(!badges(Value::Null, "workbench.view.scm", cx).contains(&Badge::Number(3)));
+ std::fs::remove_dir_all(&dir).unwrap();
+}
diff --git a/port/ledger.md b/port/ledger.md
index fc0ef6d1558..3a2050f6c29 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -556,7 +556,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/contrib/userDataSync | workbench contribution | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
| workbench/contrib/webview | workbench contribution | M17 | verified | | webviewElement.ts host protocol, theme variables, focus handoff, local resource loading, http frames (webview.rs); resources of extension file system providers through the file service: `cargo test -p app maps_resource_urls_to_resources_inside_the_roots webview_resource_reads_answer_with_the_file_service_bytes reads_resource_roots_and_stable_origins`; find widget (Cmd+F, Enter, Escape) in the host page; Open Webview Developer Tools (Web Inspector), Reload Webviews; `FIXTURE=webview-tests port/tools/webview-check` 8/8 (provider resources inside and outside the roots); api-tests `MOCHA_GREP="vscode API - webview"` 1 passing; ui-pair markdown-preview.json find shots (port/results/webviews.md); Open Webview Developer Tools opens a Web Inspector window per webview: ui-pair `webview-devtools.json` `windows` step lists "Web Inspector — …index.html" (upstream docks the workbench's Chromium devtools) |
| workbench/contrib/webviewPanel | workbench contribution | M17 | verified | | webview panels as editors in groups (workbench/webview_panels.rs), reveal moves to the target group, `activeWebviewPanelId`/`activeCustomEditorId` per group, a focused group focuses its webview; `FIXTURE=webview-tests` and `FIXTURE=markdown-tests port/tools/webview-check`; cargo test -p app webview_panels; panel restore on restart and reload: ui-pair webview-panel-restore.json, cargo test -p app panels_with_a_serializer |
-| workbench/contrib/webviewView | workbench contribution | M17 | ported | [3 L] webview_views.rs:217, workbench.rs:1619: other view containers and `when`; webview views in view_panes | `contributes.views.explorer` of type webview, collapsed at first (viewsExtensionPoint.ts `showCollapsed`), resolved on first show with `onView:` activation (workbench/webview_views.rs); `$setWebviewViewBadge` on the Explorer's activity bar item (webviewViewPane.ts `updateBadge`: cargo test -p app a_webview_view_badge_shows_on_the_explorer_item); `FIXTURE=webview-view-tests port/tools/webview-check` 5/5 on both apps. Other view containers wait for milestone 11; `when` not evaluated |
+| workbench/contrib/webviewView | workbench contribution | M17 | verified | | `contributes.views` of type webview as contributed views beside the tree views: their container, `when`, pane layout and `<id>.focus`, collapsed at first (viewsExtensionPoint.ts `showCollapsed`), resolved on first show with `onView:` activation (workbench/webview_views.rs); `$setWebviewViewBadge` on the view's container (webviewViewPane.ts `updateBadge`: cargo test -p app a_webview_view_shows_in_its_own_container_while_its_when_holds); `FIXTURE=webview-view-tests port/tools/webview-check` 5/5 on both apps |
| workbench/contrib/welcomeBanner | workbench contribution | M19 | n/a | | shows the web embedder's `welcomeBanner` option; a desktop window has none |
| workbench/contrib/welcomeGettingStarted | workbench contribution | M19 | verified | | walkthroughs.rs (`featuredFor`: welcome_page::tests::a_walkthrough_is_featured_when_the_workspace_has_a_featured_for_file), `onView:` for the side bar, panel and auxiliary bar containers (a_panel_view_showing_completes_its_on_view_step), `onContext:` over the workbench's context keys (a_workbench_context_key_completes_its_on_context_step), bold, italic and code runs in step descriptions (a_step_description_keeps_its_bold_italic_and_code_runs, drawn: a_step_description_draws_its_bold_run), workbench/welcome_page.rs: categories and details slides, built-in and extension walkthroughs without the Copilot, sync, web and remote items, step progress and completion events, media in webviews, startup page; port/tools/ui-pair with port/fixtures/ui-steps/welcome.json (port/results/welcome.md); cargo test -p app walkthroughs welcome_page (the_terminal_startup_editor_opens_a_terminal_editor); step buttons draw their `$(icon)`s (cargo test -p app a_step_button_draws_its_label_icons); `command:toSide:` runs in a group beside the page (cargo test -p app a_to_side_step_command_runs_in_a_group_beside_the_page) |
| workbench/contrib/welcomeOnboarding | workbench contribution | M19 | removed | | Developer: Welcome Onboarding 2026 (onboardingVariationA.ts) is sign-in and Copilot setup: no sign-in or AI by decision (port/notes.md) |
diff --git a/port/notes.md b/port/notes.md
index ca73f193e2d..156b7215c13 100644
--- a/port/notes.md
+++ b/port/notes.md
@@ -594,7 +594,7 @@ Scope (roadmap section 13): diagnostics, hover, completion, go to definition and
- History (`navigation.rs`, `workbench/history_actions.rs`; historyService.ts): the three navigation stacks per `workbench.editor.navigationScope` key, fed by editor changes (`editors_changed`), cursor moves (`cursors_changed`, source to reason as textEditor.ts) and edits. Reopen Closed Editor keeps file editors only (a diff or untitled editor has no reopenable input in the port). shortcut: mouse buttons 4 and 5 (`workbench.editor.mouseBackForwardToNavigate`) are not read.
- Sash settings (contrib/sash): `sash_size`, `sash_hover_size`, `sash_hover_delay` in part_grid.rs; the grippers recede after `autoHideGrippersDelay` without a mouse move. shortcut: no opacity transition (no motion support in GPUI elements here).
- Panel views (`PanelView` in panel.rs: id, title, body and title actions). The Output view's code editor lives in the hidden group `PANEL_GROUP` (`u32::MAX`), outside the grid, the MRU order and `$acceptEditorTabModel`; focusing it swaps that group in as split groups do, so `editorPosition` stays the grid's. Terminal is a panel view with its own body. Its title actions (channel dropdown, filter, Clear, gear) are in the panel's title bar as upstream.
-- Tree views (`custom_tree.rs` model, `workbench/tree_view.rs`; mainThreadTreeViews.ts, treeView.ts): the views of `contributes.views.explorer` whose `when` holds are Explorer panes, collapsed at first (`showCollapsed`). A view's tree exists only while its pane is expanded and the Explorer shows (`$setVisible`, `onView:<id>` on the first show), as upstream creates the tree on render: a `$refresh` or `$reveal` of a hidden view fetches nothing. The root fetch is shared (AsyncDataTree), so a reveal during it does not fetch twice. Pane ids are `&'static str`; a contributed id is interned once (`static_id`). Not ported yet: views in other containers (scm, debug, test, remote, `viewsContainers`), webview views, checkboxes, drag and drop and `$resolve`; there is no view container registry beyond the Explorer.
+- Tree views (`custom_tree.rs` model, `workbench/tree_view.rs`; mainThreadTreeViews.ts, treeView.ts): the views of `contributes.views.explorer` whose `when` holds are Explorer panes, collapsed at first (`showCollapsed`). A view's tree exists only while its pane is expanded and the Explorer shows (`$setVisible`, `onView:<id>` on the first show), as upstream creates the tree on render: a `$refresh` or `$reveal` of a hidden view fetches nothing. The root fetch is shared (AsyncDataTree), so a reveal during it does not fetch twice. Pane ids are `&'static str`; a contributed id is interned once (`static_id`). Not ported yet: views in other containers (scm, debug, test, remote, `viewsContainers`), checkboxes, drag and drop and `$resolve`; there is no view container registry beyond the Explorer.
- View columns (`activate_column`, editorGroupColumn.ts `columnToEditorGroup`): `$tryShowTextDocument` and `_workbench.open` pick the nth group in grid order, adding groups in the side-by-side direction below 9, else the group beside; `MainThreadTextEditors` requests address the active editor of any group.
- Panel views since the port-integrate merge (624b11540c5): Problems (`workbench/problems_view.rs`, order 0), Output, Debug Console (`workbench.panel.repl`), Test Results (`workbench.panel.testResults`, a tab only while results exist: `PanelView.visible`), Terminal. `PanelView.badge` draws the tab's count (`activityBarBadge.*`). Ports is n/a: forwarded ports belong to remote and tunnels, removed by decision.
- Handoff (milestone 11, branch `port-m11b-layout`), in order: (1) the panel's composite bar overflow "…" (tabs that do not fit, as the reference hides Terminal at 1024px with the Problems filter shown) and the Problems filter box with its filter menu and View as Table (port/results/problems.md lists the differences); (2) a view container registry (services/views, panecomposite) so contributed views of scm, debug, test and `viewsContainers` draw, with `${viewId}.active` keys from it (today each view sets its own in `key_context`); (3) the SCM Changes header onto `view_panes.rs`: waits for the Graph view (milestone 14 handoff), since with Changes alone the container merges its single view and draws no header (`mergeViewWithContainerWhenSingleView`); (4) Refactor Preview (bulkEdit) in the panel; (5) rows to verified: pixel-check `git` window (decorations) against the reference. api-tests `MOCHA_GREP="vscode API - window"` are 39/0/1 (the 1 is notebooks, milestone 17). Hot exit and windows belong to session 4f0d8561 (m11c-windows).
@@ -813,7 +813,7 @@ Handoff (branch `port-m18b-gallery`, after `docs(port): record milestone 18 exte
- Quick diff peek body (quickDiffWidget.ts `_fillBody`): a code editor of the file's own model (`EditorGroup.peek_editors`, `PeekOwner::QuickDiff`) with the inline diff's deleted lines as its view zones and the original's line numbers beside it, `lineDecorationsWidth` 10, no indicators and no sticky scroll; typing in it edits the file, `toggleQuickDiffWidgetFocus` (Cmd+K F2) moves the focus in and out. ui-pair m14/quick-diff-peek.json on a git folder whose `a.txt` (30 lines) has line 10 changed and line 12 deleted matches, the outer cursor's `LINE` word highlight and its scrollbar mark in the embedded editor included: wordHighlighter.ts `renderDecorations` decorates every code editor of the model (document_highlights.rs `share_highlights_with_model_editors`).
- Custom editors (`workbench/custom_editors.rs`, mainThreadCustomEditors.ts, contrib/customEditor, editorResolverService.ts): providers by view type, `onCustomEditor:` activation with the open waiting for the provider, the default editor from `workbench.editorAssociations` (longest glob) then contributed priorities ranked against the text editor (`priorityToRank`, `builtin` only for built-in extensions), `vscode.open`/`vscode.openWith`, files opened from the Explorer and quick open. A custom text editor keeps the text model as its tab (CustomEditorInput, tab kind 6): saving, dirty state, moves (`$onMoveCustomEditor`) and undo/redo (customEditors.ts implementation, priority 105) are the model's. A custom document's tab is a `webview-panel` editor; `$disposeCustomDocument` when its last editor closes. `workbench.action.reopenWithEditor` and `reopenActiveEditorWith` (openWithEditorPicker.ts: Active/Default descriptions, "Configure default editor for '*.ext'..." writing the association). Shortcuts: custom document edits, `$undo`/`$redo`, save-as, revert and backups are not ported; a reopened custom document opens where the group opens editors.
-- Webview views (`workbench/webview_views.rs`, mainThreadWebviewViews.ts, webviewViewPane.ts): `contributes.views.explorer` entries of `type: webview` draw as Explorer panes, collapsed at first (viewsExtensionPoint.ts `showCollapsed` for Explorer, SCM and Debug); a pane whose body shows activates `onView:<id>` and sends `$resolveWebviewView` once the provider registered; `<id>.focus` and `$show` open the Explorer and expand it; the webview state is the `webviewView.<id>` memento. Shortcuts: other view containers wait for milestone 11; `when` is not evaluated; badges are not drawn.
+- Webview views (`workbench/webview_views.rs`, mainThreadWebviewViews.ts, webviewViewPane.ts): `contributes.views` entries of `type: webview` are contributed views like the tree views (`tree_view.rs` `ContributedView.webview`), so they take the same containers, `when`, visibility, pane layout, Views submenu and `<id>.focus` command; their pane draws the webview where a tree view draws its tree. Collapsed at first in the Explorer, SCM and Debug (viewsExtensionPoint.ts `showCollapsed`); a pane whose body shows activates `onView:<id>` and sends `$resolveWebviewView` once the provider registered; `<id>.focus` and `$show` open the view's container and expand it; `$setWebviewViewBadge` badges the view's container; the webview state is the `webviewView.<id>` memento.
- Media preview (`workbench/media_preview.rs`, contrib/mediaPreview): image, video and audio files open in built-in editors (view types `imagePreview.previewEditor`, `vscode.videoPreview`, `vscode.audioPreview`, priority builtin), each a webview panel without an extension loading `media_preview/image.html` (a port of imageViewer.ts: scale to fit, zoom levels, pixelation past 3x, pinch, alt-click zoom out) or `player.html` (mediaPlayerEditorInput.ts markup). Status bar: zoom (Select Zoom Level picker), dimensions, file size. Shortcuts: upstream draws these in the workbench DOM, the port in a webview; codec probing (mediaCodecs.ts), Copy image, Save As and the legacy `media-preview` editor migration are not ported; only `file` resources preview. A custom editor or media preview tab draws its file's icon and the Explorer reveals that file (`EditorResourceAccessor.getOriginalUri`). ui-pair (`port/fixtures/ui-steps/media-preview.json`, FILE=image.png, video.mp4 and audio.mp3): WebKit's video and audio controls where Chromium draws its own. Breadcrumbs: a custom editor or media preview shows its file's breadcrumbs without outline symbols, and every editor whose file another editor can open draws the editor type control at the right (breadcrumbsControl.ts `_updateEditorTypeControl`, editorTypePicker.ts: `getEditorMatches` order, priority then glob length, the unconfigured `*` option editors left out; the menu reopens with an editor, Alt opens it to the side, the Set Default submenu writes the association; workbench/editor_type_picker.rs, menu commands `editorType.<action>.<id>`). Focus: imagePreviewEditor.ts `focus` moves DOM focus to the viewer; in the port the editor's focus reaches the page as its window's `focus` event (the host page focuses the frame on its first load and on the `focus` message), and image.html moves it to the viewer, which draws the workbench's `[tabindex="0"]:focus` ring for keyboard and programmatic focus. A media preview opened from the command line on a first start opens in its preview: unlike extension editors, it is registered before `resolveEditor` runs.
- Markdown: `FIXTURE=markdown-tests port/tools/webview-check` (5 checks, incl. `showPreviewToSide` in column Two); the extension's own tests run with `port/tools/extension-tests markdown-language-features test-workspace` (`APP=reference` for the baseline: 215 passing, 2 pending). `vscode.open` of a URI with a `#L<line>` fragment and no column goes through the opener's `extractSelection` (editorCommands.ts `_workbench.open`), which documentLink.test.ts needs.
- Webview panels in editor groups (session m17c): `$createWebviewPanel` and `$reveal` resolve `viewColumn` as `getTargetGroupFromShowOptions` (ACTIVE, SIDE, a column, one past the last adds one group); a reveal into another group moves the panel (webviewPanel.contribution.ts `onEditorOpening`, Singleton); `preserveFocus` leaves the active group (`EditorActivation.RESTORE`); `$onDidChangeWebviewPanelViewStates` carries visible per group, active, and the column; every group's active webview shows. `cargo test -p app panels_open_in_their_view_column`.