Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(extensions): report the configuration points' collector messages

rokartur9ea5b3ded856
diff --git a/native/crates/app/src/workbench/extension_editor.rs b/native/crates/app/src/workbench/extension_editor.rs
index b1f5470ec81..2fdaf05f468 100644
--- a/native/crates/app/src/workbench/extension_editor.rs
+++ b/native/crates/app/src/workbench/extension_editor.rs
@@ -540,7 +540,8 @@ impl Workbench {
let content = match id {
"runtimeStatus" => {
let id = &extension.identifier().id;
- let markdown = extension_features::runtime_status_markdown(crate::perf::activation(id), &crate::perf::runtime_errors(id), &crate::perf::messages(id));
+ let messages = extension_features::extension_messages(id, &self.settings.lock().unwrap().registry);
+ let markdown = extension_features::runtime_status_markdown(crate::perf::activation(id), &crate::perf::runtime_errors(id), &messages);
self.feature_markdown("runtime-status", &markdown, cx)
}
_ => match extension_features::feature_data(manifest, id) {
diff --git a/native/crates/app/src/workbench/extension_features.rs b/native/crates/app/src/workbench/extension_features.rs
index e5b58822cf1..22ae1fae3b3 100644
--- a/native/crates/app/src/workbench/extension_features.rs
+++ b/native/crates/app/src/workbench/extension_features.rs
@@ -473,6 +473,20 @@ fn colors_table(colors: &Value) -> FeatureData {
}
/// `RuntimeStatusMarkdownRenderer.createElement` without the feature access data, which only AI features record.
+/// The extension's collector messages: those of the points the workbench handles, then the configuration
+/// registry's.
+pub(super) fn extension_messages(id: &str, registry: &config::registry::Registry) -> Vec<(Severity, String)> {
+ let mut messages = crate::perf::messages(id);
+ for (extension, message) in &registry.messages {
+ match message {
+ _ if !extension.eq_ignore_ascii_case(id) => {}
+ config::registry::CollectorMessage::Warning(text) => messages.push((Severity::Warning, text.clone())),
+ config::registry::CollectorMessage::Error(text) => messages.push((Severity::Error, text.clone())),
+ }
+ }
+ messages
+}
+
pub(super) fn runtime_status_markdown(activation: Option<crate::perf::Activation>, runtime_errors: &[String], messages: &[(Severity, String)]) -> String {
let state = match activation {
Some(activation) if activation.startup => format!("Activated on Startup: `{}ms`", activation.activate_call),
diff --git a/native/crates/app/src/workbench/extension_features/tests.rs b/native/crates/app/src/workbench/extension_features/tests.rs
index 0b06b3a2820..c94b57598fd 100644
--- a/native/crates/app/src/workbench/extension_features/tests.rs
+++ b/native/crates/app/src/workbench/extension_features/tests.rs
@@ -39,6 +39,37 @@ fn the_runtime_status_lists_uncaught_errors_and_messages() {
assert_eq!(markdown, "### Activation\n\nNot yet activated\n ### Uncaught Errors (2)\n$(error)&nbsp;boom\n\n$(error)&nbsp;TypeError: bad\n\n\n ### Messages (1)\n$(warning)&nbsp;a warning\n\n");
}
+/// configurationExtensionPoint.ts collector messages of both points.
+#[test]
+fn invalid_configuration_is_an_extension_message() {
+ use crate::notifications::Severity::{Error, Warning};
+ let first = json!({ "contributes": {
+ "configuration": [
+ { "title": 5, "properties": { "test.ok": { "type": "string" }, " ": {}, "[json]": {}, "editor.fontSize": {}, "test.both": { "policy": { "name": "A" }, "policyReference": "B" }, "test.number": 3, "test.agents": { "agentsWindow": { "default": 1 }, "agentHost": { "key": "x" } } } },
+ { "properties": "none", "allOf": [{ "properties": { "test.ok": {}, "test.nested": { "type": "boolean" } } }] },
+ ],
+ "configurationDefaults": { "editor.fontSize": 20, "chat.useAgentsMdFile": false, "update.mode": "none" },
+ } });
+ let registry = config::registry::Registry::with_extensions(&[("Test.Configuration", &first)]);
+ assert!(registry.property("test.nested").is_some(), "an allOf node's properties register");
+ let expected = |messages: &[(crate::notifications::Severity, &str)]| messages.iter().map(|(severity, message)| (*severity, message.to_string())).collect::<Vec<_>>();
+ assert_eq!(super::extension_messages("test.configuration", &registry), expected(&[
+ (Error, "'configuration.title' must be a string"),
+ (Warning, "Cannot register an empty property"),
+ (Warning, "Cannot register '[json]'. This matches property pattern '\\[.*\\]$' for describing language specific editor settings. Use 'configurationDefaults' contribution."),
+ (Warning, "Cannot register 'editor.fontSize'. This property is already registered."),
+ (Warning, "Cannot register 'test.both'. A setting must not declare both 'policy' and 'policyReference'."),
+ (Error, "configuration.properties property 'test.number' must be an object"),
+ (Error, "Extension 'Test.Configuration' CANNOT use 'agentsWindow' property on configuration 'test.agents' without enabling the 'agentsWindowConfiguration' API proposal."),
+ (Error, "Extension 'Test.Configuration' CANNOT use the 'agentHost' property on configuration 'test.agents'."),
+ (Error, "'configuration.properties' must be an object"),
+ (Error, "'configuration.allOf' is deprecated and should no longer be used. Instead, pass multiple configuration sections as an array to the 'configuration' contribution point."),
+ (Warning, "Cannot register 'test.ok'. This property is already registered."),
+ (Warning, "Cannot register configuration defaults for 'chat.useAgentsMdFile'. This setting does not allow contributing configuration defaults."),
+ (Warning, "Cannot register configuration defaults for 'update.mode'. Only defaults for machine-overridable, window, resource and language overridable scoped settings are supported."),
+ ]));
+}
+
#[test]
fn commands_list_their_keybindings_and_menus_with_the_implicit_command_palette() {
let manifest = json!({ "contributes": {
diff --git a/native/crates/config/src/registry.rs b/native/crates/config/src/registry.rs
index 323fe25fb7e..0824253d4ca 100644
--- a/native/crates/config/src/registry.rs
+++ b/native/crates/config/src/registry.rs
@@ -54,6 +54,13 @@ pub const PROFILE_SCOPES: [Scope; 5] = [Scope::Machine, Scope::Window, Scope::Re
pub const WORKSPACE_SCOPES: [Scope; 4] = [Scope::Window, Scope::Resource, Scope::LanguageOverridable, Scope::MachineOverridable];
pub const FOLDER_SCOPES: [Scope; 3] = [Scope::Resource, Scope::LanguageOverridable, Scope::MachineOverridable];
+/// An extension point's `collector.warn` or `collector.error` message.
+#[derive(Clone, Debug, PartialEq)]
+pub enum CollectorMessage {
+ Warning(String),
+ Error(String),
+}
+
/// `IRegisteredConfigurationPropertySchema`: the schema as registered, plus what the registry derives from it.
#[derive(Clone, Debug)]
pub struct Property {
@@ -90,6 +97,8 @@ pub struct Registry {
pub semantic_token_types: Vec<Value>,
pub semantic_token_modifiers: Vec<Value>,
pub debuggers: Vec<crate::debuggers::Debugger>,
+ /// The `configuration` and `configurationDefaults` points' collector messages, by extension id.
+ pub messages: Vec<(String, CollectorMessage)>,
}
/// The core settings of VS Code 1.147.0 as its registry holds them, dumped with port/tools/dump-settings.
@@ -299,29 +308,77 @@ impl Registry {
_ => Vec::new(),
};
for node in nodes {
+ if js_truthy(&node["title"]) && !node["title"].is_string() {
+ self.messages.push((extension_id.to_owned(), CollectorMessage::Error("'configuration.title' must be a string".into())));
+ }
let section = json!({
"id": node["id"].as_str().unwrap_or(extension_id),
"title": node["title"].as_str().or(display_name).unwrap_or(extension_id),
"order": node["order"],
"extensionInfo": { "id": extension_id, "displayName": display_name },
});
- for (key, schema) in node["properties"].as_object().into_iter().flatten() {
- // validateProperty, and the extension point's object check.
- if key.trim().is_empty() || is_override_key(key) || self.properties.contains_key(key) || !schema.is_object() {
- continue;
- }
- // `included: false` goes to the excluded properties, which only policies and experiments read.
- if schema["included"] == false {
- self.excluded.insert(key.clone(), schema.clone());
- continue;
- }
- let mut schema = schema.clone();
- schema["section"] = section.clone();
- let scope = schema["scope"].as_str().map_or(Scope::Window, Scope::parse);
- let restricted = schema["restricted"].as_bool().unwrap_or_else(|| restricted.contains(&key.as_str()));
- let default = schema.get("default").cloned();
- self.insert(key.clone(), Property { scope, restricted, default: Value::Null, default_default: default, source: Some(extension_id.to_owned()), schema });
+ self.register_properties(extension_id, description, node, &section, &restricted);
+ }
+ }
+
+ /// configurationExtensionPoint.ts `validateProperties` of a node and its `allOf` nodes, then the registration of
+ /// the properties that pass.
+ fn register_properties(&mut self, extension_id: &str, description: &Value, node: &Value, section: &Value, restricted: &[&str]) {
+ let mut report = |message| self.messages.push((extension_id.to_owned(), message));
+ let properties = &node["properties"];
+ if js_truthy(properties) && !properties.is_object() && !properties.is_array() {
+ report(CollectorMessage::Error("'configuration.properties' must be an object".into()));
+ }
+ let proposed = description["enabledApiProposals"].as_array().is_some_and(|proposals| proposals.iter().any(|proposal| proposal == "agentsWindowConfiguration"));
+ let mut accepted = Vec::new();
+ for (key, schema) in properties.as_object().into_iter().flatten() {
+ // configurationRegistry.ts `validateProperty`; a key seen earlier in this delta is registered already.
+ let invalid = if key.trim().is_empty() {
+ Some("Cannot register an empty property".to_owned())
+ } else if is_override_key(key) {
+ Some(format!("Cannot register '{key}'. This matches property pattern '\\[.*\\]$' for describing language specific editor settings. Use 'configurationDefaults' contribution."))
+ } else if self.properties.contains_key(key) || accepted.iter().any(|(accepted, _)| accepted == key) {
+ Some(format!("Cannot register '{key}'. This property is already registered."))
+ } else if js_truthy(&schema["policy"]) && js_truthy(&schema["policyReference"]) {
+ Some(format!("Cannot register '{key}'. A setting must not declare both 'policy' and 'policyReference'."))
+ } else {
+ None
+ };
+ if let Some(message) = invalid {
+ report(CollectorMessage::Warning(message));
+ continue;
}
+ if !schema.is_object() {
+ report(CollectorMessage::Error(format!("configuration.properties property '{key}' must be an object")));
+ continue;
+ }
+ if js_truthy(&schema["agentsWindow"]) && !proposed {
+ report(CollectorMessage::Error(format!("Extension '{extension_id}' CANNOT use 'agentsWindow' property on configuration '{key}' without enabling the 'agentsWindowConfiguration' API proposal.")));
+ }
+ if js_truthy(&schema["agentHost"]) {
+ report(CollectorMessage::Error(format!("Extension '{extension_id}' CANNOT use the 'agentHost' property on configuration '{key}'.")));
+ }
+ accepted.push((key.clone(), schema));
+ }
+ let sub_nodes = &node["allOf"];
+ if js_truthy(sub_nodes) {
+ report(CollectorMessage::Error("'configuration.allOf' is deprecated and should no longer be used. Instead, pass multiple configuration sections as an array to the 'configuration' contribution point.".into()));
+ }
+ for (key, schema) in accepted {
+ // `included: false` goes to the excluded properties, which only policies and experiments read.
+ if schema["included"] == false {
+ self.excluded.insert(key, schema.clone());
+ continue;
+ }
+ let mut schema = schema.clone();
+ schema["section"] = section.clone();
+ let scope = schema["scope"].as_str().map_or(Scope::Window, Scope::parse);
+ let restricted = schema["restricted"].as_bool().unwrap_or_else(|| restricted.contains(&key.as_str()));
+ let default = schema.get("default").cloned();
+ self.insert(key, Property { scope, restricted, default: Value::Null, default_default: default, source: Some(extension_id.to_owned()), schema });
+ }
+ for sub_node in sub_nodes.as_array().into_iter().flatten() {
+ self.register_properties(extension_id, description, sub_node, section, restricted);
}
}
@@ -333,9 +390,11 @@ impl Registry {
for (key, value) in overrides {
let property = self.properties.get(key);
if property.is_some_and(|p| p.schema["disallowConfigurationDefault"] == true) {
+ self.messages.push((extension_id.to_owned(), CollectorMessage::Warning(format!("Cannot register configuration defaults for '{key}'. This setting does not allow contributing configuration defaults."))));
continue;
}
if !is_override_key(key) && property.is_some_and(|p| !ALLOWED.contains(&p.scope)) {
+ self.messages.push((extension_id.to_owned(), CollectorMessage::Warning(format!("Cannot register configuration defaults for '{key}'. Only defaults for machine-overridable, window, resource and language overridable scoped settings are supported."))));
continue;
}
allowed.insert(key.clone(), value.clone());
@@ -452,6 +511,15 @@ impl Registry {
}
/// `getDefaultValue(type)`.
+fn js_truthy(value: &Value) -> bool {
+ match value {
+ Value::Null | Value::Bool(false) => false,
+ Value::Number(number) => number.as_f64() != Some(0.),
+ Value::String(text) => !text.is_empty(),
+ _ => true,
+ }
+}
+
fn default_for_type(type_: &Value) -> Value {
let first = match type_ {
Value::Array(types) => types.first().and_then(Value::as_str),
diff --git a/port/ledger.md b/port/ledger.md
index 0d58755c8fa..85470cb6ab3 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -482,7 +482,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/contrib/emergencyAlert | workbench contribution | | removed | | no AI or Microsoft services by decision (port/notes.md); API stays inert |
| workbench/contrib/emmet | workbench contribution | M13 | verified | | workbench/emmet.rs: Emmet: Expand Abbreviation (`emmet.expandAbbreviation` with the language at the cursor and the emmet parent mode of its grammar's scope, emmetAction.test.ts cases), Tab with `emmet.triggerExpansionOnTab`, the Edit menu entry: cargo test -p app emmet menubar |
| workbench/contrib/encryption | workbench contribution | M10 | n/a | | encryption.contribution.ts only migrates Linux `password-store` argv values to gnome-libsecret; the port runs on macOS and keeps secrets in the Keychain |
-| workbench/contrib/extensions | workbench contribution | M18 | ported | [3 L] snippet_completions.rs:121: the Runtime Status Messages list the `collector` messages of the snippets, keybindings, languages, statusBarItems, viewsWelcome, debuggers, menus, submenus, commands, views and viewsContainers points only; those of configuration, jsonValidation, colors, icons, semanticToken*, problemMatchers, problemPatterns, grammars, notebooks and authentication are not ported | Extensions view, queries, details editor, enablement, updates, badge, Help: Start/Continue/Stop Extension Bisect (services/extensionManagement/browser/extensionBisect.ts: state in the application storage across reloads, bisect-disabled extensions as DisabledByEnvironment in the window and out of the host, the urgent sticky prompt, the default-checked Keep this extension disabled; Report Issue & Continue is out with the removed contrib/issue): cargo test -p app extension_bisect, bisect_finds_the_extension_and_keeps_it_disabled; cargo test -p app extension (extensionsViews.test.ts, extensionQuery.test.ts, extensionEnablementService.test.ts cases); Features tab tables and markdown of extensionFeaturesTab.ts and the registered renderers: cargo test -p app extension_features; Runtime Status Uncaught Errors from `$onExtensionRuntimeError` and Messages: cargo test -p app the_runtime_status_lists_uncaught_errors_and_messages, invalid_contributed, static_entries_need_the_proposal, group_needs_the_proposal, debuggers_merge_by_type_and_keep_the_built_in_values, skipped_menu_contributions_are_extension_messages, contributed_command_messages, invalid_views_and_view_containers_are_extension_messages; ui-pair port/fixtures/extensions/ui-view.json (view, search, details) against the reference |
+| workbench/contrib/extensions | workbench contribution | M18 | ported | [3 L] snippet_completions.rs:121: the Runtime Status Messages list the `collector` messages of the snippets, keybindings, languages, statusBarItems, viewsWelcome, debuggers, menus, submenus, commands, views, viewsContainers, configuration and configurationDefaults points only; those of jsonValidation, colors, icons, semanticToken*, problemMatchers, problemPatterns, grammars, notebooks and authentication are not ported | Extensions view, queries, details editor, enablement, updates, badge, Help: Start/Continue/Stop Extension Bisect (services/extensionManagement/browser/extensionBisect.ts: state in the application storage across reloads, bisect-disabled extensions as DisabledByEnvironment in the window and out of the host, the urgent sticky prompt, the default-checked Keep this extension disabled; Report Issue & Continue is out with the removed contrib/issue): cargo test -p app extension_bisect, bisect_finds_the_extension_and_keeps_it_disabled; cargo test -p app extension (extensionsViews.test.ts, extensionQuery.test.ts, extensionEnablementService.test.ts cases); Features tab tables and markdown of extensionFeaturesTab.ts and the registered renderers: cargo test -p app extension_features; Runtime Status Uncaught Errors from `$onExtensionRuntimeError` and Messages: cargo test -p app the_runtime_status_lists_uncaught_errors_and_messages, invalid_contributed, static_entries_need_the_proposal, group_needs_the_proposal, debuggers_merge_by_type_and_keep_the_built_in_values, skipped_menu_contributions_are_extension_messages, contributed_command_messages, invalid_views_and_view_containers_are_extension_messages, invalid_configuration_is_an_extension_message; ui-pair port/fixtures/extensions/ui-view.json (view, search, details) against the reference |
| workbench/contrib/externalTerminal | workbench contribution | M15 | verified | | workbench/external_terminal.rs: Open New External Terminal (`workbench.action.terminal.openNativeConsole`, cmd+shift+c), with several workspace folders after the Select workspace folder pick (cargo test -p app open_native_console_picks_a_folder_in_a_multi_root_workspace); cargo test -p app external_terminal; ui-pair (port/results/terminal.md) |
| workbench/contrib/externalUriOpener | workbench contribution | M12 | verified | | workbench/opener.rs: externalUriOpenerService.ts getRequestedOpener (workbench.externalUriOpeners globs), chooseOpener, "How would you like to open: {0}" picker; no Simple Browser (out of scope); verified at port-m12b-verify: cargo test -p app opener 4/4; Simple Browser is out of scope by decision |
| workbench/contrib/files | workbench contribution | M12 | ported | [3 M] Files m12: non-file workspace folders | Cmd+V pastes the files another app copied after explorer.confirmPasteNative (explorerView.ts paste listener, fileActions.ts `pasteFileHandler`: cargo test -p app cmd_v_pastes_the_files_finder_copied); Dragged workspace roots reorder before or after a root by the pointer's half, or to the end, with the list.dropBetweenBackground line (explorerViewer.ts `doHandleRootDrop`: cargo test -p app dragging_a_root_reorders_the_workspace_folders; ui-pair dragShot of a three-root workspace, line over a root and below the rows matches); Compact folders off while optimized for a screen reader (explorerView.ts `isCompressionEnabled`: cargo test -p app compacts_single_child_folders_into_one_row); A workspace root that fails to resolve: the single folder's file item of its own resource, the "!" decoration in `list.invalidItemForeground` with "Unable to resolve workspace folder (...)" (explorerViewer.ts `getChildren`, explorerDecorationsProvider.ts: cargo test -p app a_workspace_root_that_fails_to_resolve_is_decorated_with_its_error; ui-pair of a two-root workspace with a missing folder, row and hover match); a copy soft-reverts the target's dirty model, which shows the copied file (workingCopyFileService.ts `doMoveOrCopy`: cargo test -p app a_copy_onto_a_dirty_model_reverts_it_to_the_copied_file); An unreadable folder expands to no children without an error (fileService.ts `toFileStat`: cargo test -p app an_unreadable_folder_expands_to_no_children); Explorer tree read from disk (explorer.rs): folders first, default excludes, click to expand, click opens a file as preview, double click pins, selection follows the active editor; Seti file icons and compareFileNamesDefault sort; workspace folders as roots, first five expanded (cargo test -p app); new file and folder, rename, delete, copy, cut, paste, drag and drop and undo through the working copy file operations (cargo test -p app explorer_actions, file_actions); "Do not ask me again" as the NSAlert suppression checkbox (dialog.rs); the context menu with the items whose commands the port has (port/results/contextmenu.md); tree view state in workspace storage (cargo test -p app view_state); file nesting with the explorerFileNestingTrie.test.ts cases (cargo test -p app nest); copyFilePath, copyRelativeFilePath and revealFileInOS (cargo test -p app copy_path, copied_path_labels); compact folders (cargo test -p app compact, get_context, compressed_navigation); Explorer find (cargo test -p app explorer_find find_filters); Finder drops through ExternalFileImport (cargo test -p app files_dropped_from_finder); explorer.sortOrder and sortOrderLexicographicOptions; explorer.autoReveal; list keyboard commands; the view title actions on hover or focus, revealInExplorer, showActiveFileInExplorer and the other file actions (cargo test -p app view_title_and_file_actions); workbench.action.files.newFile and showOpenedFileInNewWindow (cargo test -p app new_file_creates); Add Folder to Workspace and removeRootFolder (workbench/workspace_editing.rs, ui-pair port/fixtures/ui-pair/m12/workspace-folders.json); the compare commands compareFiles, selectForCompare, compareSelected, compareFileWith, compareWithSaved, compareWithClipboard, compareNewUntitledTextFiles (workbench/file_compare.rs: cargo test -p app file_compare); compare with saved by its chord: ui-pair port/fixtures/ui-pair/m12/compare-saved.json (the modified side has its own editor and cursor, at the first change: cargo test -p app file_compare; left the breadcrumbs editor type picker); Find in Folder..., Open in Integrated/External Terminal (cargo test -p app explorer_actions; ui-pair m12/find-in-folder.json and m12/folder-terminal.json), high contrast list outline (icons.json hc matches); rename, delete, new file and drag and drop with its move confirmation: ui-pair m12/explorer-ops.json matches; `<view id>.focus` of the Explorer panes (cargo test -p app focus_view_commands); the editor placeholders: binary, too large, not found and read errors with their actions (cargo test -p app files_that_do_not_resolve; ui-pair m12/editor-placeholders.json matches); the Open Editors view: pane size limits, group rows, unsaved badge, title actions, row close and dirty actions, drag to groups (cargo test -p app open_editors body_limits_clamp; ui-pair m12/open-editors.json); pinned (sticky) editors and scrolling tab bars, sticky shrink tabs in place with the `m…` label (cargo test -p app sticky pinned_editors tab_scroll; ui-pair m12/tab-scroll.json); Explorer indent guides at the reference x, row hover background, decoration badges at 11px 8px from the end, the Unpin Editor hover again after the tab menu closes (cargo test -p app tree_guides hover unpin_hover; ui-pair m12/explorer-guides.json and m12/pinned-tabs.json match). Differences left (port/notes.md milestone 12, session m12-files-done): a long tooltip breaks one path segment earlier (GPUI's line wrapper), the pin action loses its hover style after Cmd+W until the pointer moves (gpui keyboard modality), a shrink sticky tab with a badge and no room for its name; Open With... (`explorer.openWith`, `explorerResourceAvailableEditorIds`: cargo test -p app open_with_opens_the_resource the_context_menu_selects_the_row); Compare Active File With... from a file it opens itself: ui-pair m12/compare.json, the picker, the diff and the README.md menu match (port/notes.md session compare-fix); `explorerResourceReadonly` and `explorerResourceParentReadOnly` from `isReadonly` (cargo test -p app readonly_keys_follow_the_focused_item_and_its_parent); a failed create as an error notification with Retry, a dropped folder added to the workspace (cargo test -p app a_failed_create_offers a_folder_dropped_on_the_root) |