дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-29 13:52:36 +02:00
Порівняти коміти
3
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
25911a96fc | ||
|
|
dfea6d2c1e | ||
|
|
b9a25462ea |
No files matched your search
@@ -391,9 +391,10 @@ pub const DEBUGPY_MISSING: &str = "debugpy is not installed";
|
||||
/// `PYTHONPATH`. Neither: an `unavailable` error naming the interpreter.
|
||||
pub async fn prepare_debugpy(spec: &mut AdapterSpec) -> IdeResult<()> {
|
||||
let (command, cwd) = (spec.command.clone(), spec.cwd.clone());
|
||||
let Some(python) = tokio::task::spawn_blocking(move || resolve_binary(&command, &cwd)).await.ok().flatten() else {
|
||||
let Some(python) = tokio::task::spawn_blocking(move || debugpy_python(&command, &cwd)).await.ok().flatten() else {
|
||||
return Ok(()); // Reported as a missing adapter when it is started.
|
||||
};
|
||||
spec.command = python.to_string_lossy().into_owned();
|
||||
let mut probe = Command::new(&python);
|
||||
probe.current_dir(&spec.cwd);
|
||||
ide_core::process::prepare(probe.as_std_mut());
|
||||
@@ -426,6 +427,46 @@ pub async fn prepare_debugpy(spec: &mut AdapterSpec) -> IdeResult<()> {
|
||||
)))
|
||||
}
|
||||
|
||||
/// The interpreter `<python> -m debugpy.adapter` runs with. On Windows a bare `python3` (the
|
||||
/// built-in `python.toml`'s) or `python` may name an App Execution Alias in `WindowsApps`,
|
||||
/// which only opens the Store unless the Store's Python is installed: every match on `PATH`
|
||||
/// of the command, then `python`, then the `py` launcher, the first that is no alias or runs.
|
||||
fn debugpy_python(command: &str, cwd: &Path) -> Option<PathBuf> {
|
||||
let found = resolve_binary(command, cwd);
|
||||
if !cfg!(windows) || !matches!(command, "python3" | "python") {
|
||||
return found;
|
||||
}
|
||||
let pathext = std::env::var("PATHEXT").ok();
|
||||
let dirs = search_dirs(cwd);
|
||||
let mut candidates: Vec<PathBuf> = Vec::new();
|
||||
for name in [command, "python", "py"] {
|
||||
for dir in &dirs {
|
||||
if let Some(p) = find_binary_in(name, cwd, std::slice::from_ref(dir), true, pathext.as_deref())
|
||||
&& !candidates.contains(&p)
|
||||
{
|
||||
candidates.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
let runs = |p: &Path| {
|
||||
let mut c = std::process::Command::new(p);
|
||||
ide_core::process::prepare(&mut c);
|
||||
c.arg("--version").stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
|
||||
c.status().is_ok_and(|s| s.success())
|
||||
};
|
||||
pick_python(candidates, runs).or(found)
|
||||
}
|
||||
|
||||
/// The first candidate that is no App Execution Alias, or is one that `runs`.
|
||||
fn pick_python(candidates: Vec<PathBuf>, runs: impl Fn(&Path) -> bool) -> Option<PathBuf> {
|
||||
candidates.into_iter().find(|p| !is_app_execution_alias(p) || runs(p))
|
||||
}
|
||||
|
||||
/// A Windows App Execution Alias (`%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe`).
|
||||
fn is_app_execution_alias(path: &Path) -> bool {
|
||||
path.parent().and_then(Path::file_name).is_some_and(|d| d.eq_ignore_ascii_case("WindowsApps"))
|
||||
}
|
||||
|
||||
/// GDB's DAP interpreter (`-i dap`) shipped in GDB 14; older ones exit with
|
||||
/// "Interpreter `dap' unrecognized".
|
||||
const GDB_MIN_MAJOR: u32 = 14;
|
||||
@@ -859,6 +900,19 @@ async fn connect_with_retries(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Windows: a Store alias on `PATH` before the real interpreter is skipped unless it runs
|
||||
/// (the Store's Python is installed), so the Python Debug Server starts the real one.
|
||||
#[test]
|
||||
fn debugpy_skips_store_aliases_that_do_not_run() {
|
||||
let alias = PathBuf::from("C:/Users/me/AppData/Local/Microsoft/WindowsApps/python3.exe");
|
||||
let real = PathBuf::from("C:/Program Files/Python313/python.exe");
|
||||
assert!(is_app_execution_alias(&alias) && !is_app_execution_alias(&real));
|
||||
let both = vec![alias.clone(), real.clone()];
|
||||
assert_eq!(pick_python(both.clone(), |_| false), Some(real.clone()));
|
||||
assert_eq!(pick_python(both, |_| true), Some(alias.clone()));
|
||||
assert_eq!(pick_python(vec![alias], |_| false), None);
|
||||
}
|
||||
|
||||
/// A user's `languages/python.toml` `[debugger]` is the one debugpy runs with: no other
|
||||
/// language (a template one) declares debugpy before Python.
|
||||
#[test]
|
||||
|
||||
@@ -423,11 +423,25 @@ pub struct CapabilityInfo {
|
||||
pub optional: bool,
|
||||
/// Currently granted.
|
||||
pub granted: bool,
|
||||
/// The plugin's own explanation (`[capabilities.reasons]`), shown below `description`.
|
||||
#[serde(default)]
|
||||
pub reason: Option<String>,
|
||||
/// `reason` translated by the plugin's `locales/<tag>.json`, by language tag.
|
||||
#[serde(default)]
|
||||
pub reason_locales: std::collections::BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl CapabilityInfo {
|
||||
pub fn new(cap: &Capability, optional: bool, granted: bool) -> Self {
|
||||
Self { id: cap.to_string(), risk: cap.risk(), description: cap.describe(), optional, granted }
|
||||
Self {
|
||||
id: cap.to_string(),
|
||||
risk: cap.risk(),
|
||||
description: cap.describe(),
|
||||
optional,
|
||||
granted,
|
||||
reason: None,
|
||||
reason_locales: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,14 @@ use crate::capability::Capability;
|
||||
use crate::plugin_point::PointDecl;
|
||||
use crate::resolve::Dependency;
|
||||
use serde::Deserialize;
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
pub const MANIFEST_FILE: &str = "plugin.toml";
|
||||
/// The plugin API (engine) version this host implements.
|
||||
pub const ENGINE_VERSION: &str = "1.18.0";
|
||||
pub const ENGINE_VERSION: &str = "1.19.0";
|
||||
/// The longest `[capabilities.reasons]` entry, in characters: a sentence or two.
|
||||
pub const MAX_CAPABILITY_REASON: usize = 500;
|
||||
/// The 0.1 API, still accepted for contribution-only packages and 0.1 components.
|
||||
pub const LEGACY_API: &str = "0.1";
|
||||
/// Marketplace categories, in the order they are shown.
|
||||
@@ -84,6 +86,10 @@ pub struct Manifest {
|
||||
pub struct Capabilities {
|
||||
pub required: Vec<Capability>,
|
||||
pub optional: Vec<Capability>,
|
||||
/// `[capabilities.reasons]` (API 1.19): the plugin's own words on why it asks for a
|
||||
/// declared capability, keyed by the capability as printed (`net:127.0.0.1`). Shown
|
||||
/// below the host's description, never instead of it.
|
||||
pub reasons: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl Capabilities {
|
||||
@@ -94,6 +100,11 @@ impl Capabilities {
|
||||
pub fn is_optional(&self, cap: &Capability) -> bool {
|
||||
self.optional.contains(cap) && !self.required.contains(cap)
|
||||
}
|
||||
|
||||
/// The plugin's explanation of `cap`, if it gave one.
|
||||
pub fn reason(&self, cap: &Capability) -> Option<&str> {
|
||||
self.reasons.get(&cap.to_string()).map(String::as_str)
|
||||
}
|
||||
}
|
||||
|
||||
/// When a plugin's code is instantiated (plan 4.4). Contributions are live
|
||||
@@ -251,6 +262,8 @@ struct RawCapabilities {
|
||||
required: Vec<String>,
|
||||
#[serde(default)]
|
||||
optional: Vec<String>,
|
||||
#[serde(default)]
|
||||
reasons: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl Manifest {
|
||||
@@ -279,8 +292,18 @@ impl Manifest {
|
||||
Ok(out)
|
||||
};
|
||||
let capabilities = match (raw.capabilities, raw.permissions) {
|
||||
(Some(c), _) => Capabilities { required: parse_caps(c.required)?, optional: parse_caps(c.optional)? },
|
||||
(None, Some(p)) => Capabilities { required: parse_caps(p)?, optional: Vec::new() },
|
||||
(Some(c), _) => {
|
||||
let mut reasons = BTreeMap::new();
|
||||
for (key, text) in c.reasons {
|
||||
// Keyed as the capability prints, so `net:Example.com` finds `net:example.com`.
|
||||
let cap: Capability = key.parse().map_err(|e| format!("capabilities.reasons: {e}"))?;
|
||||
reasons.insert(cap.to_string(), text);
|
||||
}
|
||||
Capabilities { required: parse_caps(c.required)?, optional: parse_caps(c.optional)?, reasons }
|
||||
}
|
||||
(None, Some(p)) => {
|
||||
Capabilities { required: parse_caps(p)?, optional: Vec::new(), reasons: BTreeMap::new() }
|
||||
}
|
||||
(None, None) => Capabilities::default(),
|
||||
};
|
||||
let activation = match raw.activation {
|
||||
@@ -365,6 +388,19 @@ impl Manifest {
|
||||
self.needs_api("`change-notes-file`", 18)?;
|
||||
check_relative(path, "change-notes-file")?;
|
||||
}
|
||||
if !self.capabilities.reasons.is_empty() {
|
||||
self.needs_api("`capabilities.reasons`", 19)?;
|
||||
}
|
||||
for (key, text) in &self.capabilities.reasons {
|
||||
if !self.capabilities.all().any(|c| c.to_string() == *key) {
|
||||
return Err(format!("capabilities.reasons: {key:?} is not under `required` or `optional`"));
|
||||
}
|
||||
if text.trim().is_empty() || text.chars().count() > MAX_CAPABILITY_REASON {
|
||||
return Err(format!(
|
||||
"capabilities.reasons: the reason for {key:?} must be 1 to {MAX_CAPABILITY_REASON} characters"
|
||||
));
|
||||
}
|
||||
}
|
||||
for cap in self.capabilities.required.iter().chain(&self.capabilities.optional) {
|
||||
if matches!(
|
||||
cap,
|
||||
@@ -780,6 +816,33 @@ required = [\"lsp:phoxite\"]
|
||||
assert_eq!(m.capabilities.optional, [Capability::BuildRead]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capability_reasons_explain_declared_capabilities_from_api_1_19() {
|
||||
let caps = "[capabilities]\nrequired = [\"net:Example.com\"]\noptional = [\"clipboard.read\"]\n\
|
||||
[capabilities.reasons]\n\"net:Example.com\" = \"Fetches the schema.\"\n\
|
||||
\"clipboard.read\" = \"Imports a log you copied.\"\n";
|
||||
assert!(err(&format!("{}{caps}", BASE.replace("^1.2", "^1.18"))).contains("new in plugin API 1.19"));
|
||||
let src = |caps: &str| format!("{}{caps}", BASE.replace("^1.2", "^1.19"));
|
||||
let m = Manifest::parse(&src(caps)).unwrap();
|
||||
// Keyed as the capability prints.
|
||||
assert_eq!(m.capabilities.reason(&Capability::Net("example.com".into())), Some("Fetches the schema."));
|
||||
assert_eq!(m.capabilities.reason(&Capability::ClipboardRead), Some("Imports a log you copied."));
|
||||
assert_eq!(m.capabilities.reason(&Capability::ProjectRead), None);
|
||||
|
||||
let undeclared =
|
||||
"[capabilities]\nrequired = [\"project.read\"]\n[capabilities.reasons]\n\"project.write\" = \"x\"\n";
|
||||
assert!(err(&src(undeclared)).contains("not under `required` or `optional`"));
|
||||
let invalid = "[capabilities]\nrequired = [\"project.read\"]\n[capabilities.reasons]\n\"teleport\" = \"x\"\n";
|
||||
assert!(err(&src(invalid)).contains("capabilities.reasons"));
|
||||
let empty = "[capabilities]\nrequired = [\"project.read\"]\n[capabilities.reasons]\n\"project.read\" = \" \"\n";
|
||||
assert!(err(&src(empty)).contains("1 to 500 characters"));
|
||||
let long = format!(
|
||||
"[capabilities]\nrequired = [\"project.read\"]\n[capabilities.reasons]\n\"project.read\" = \"{}\"\n",
|
||||
"x".repeat(MAX_CAPABILITY_REASON + 1)
|
||||
);
|
||||
assert!(err(&src(&long)).contains("1 to 500 characters"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_clipboard_read_capability_needs_api_1_11() {
|
||||
let caps = "[capabilities]\noptional = [\"clipboard.read\"]\n";
|
||||
|
||||
@@ -10,7 +10,7 @@ use ide_extension::ledger::{Ledger, Subject};
|
||||
use ide_language::ProgramPin;
|
||||
use ide_plugin::{
|
||||
CommitChange, CommitDraft, EventKind, HostApi, HostError, HttpRequest, HttpResponse, NotificationLevel,
|
||||
ProcessChunk, ProcessCommand, ProcessOptions, ProcessOutput, Prompt, RepositoryStatus, StatusItem,
|
||||
ProcessChunk, ProcessCommand, ProcessOptions, ProcessOutput, Prompt, RepositoryStatus, SettingsTarget, StatusItem,
|
||||
};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
||||
@@ -2450,6 +2450,31 @@ impl HostApi for PluginApi {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn open_settings(&self, client: Option<&str>, target: SettingsTarget) -> Result<(), HostError> {
|
||||
let client = from_window(client, "open Settings")?;
|
||||
let (page, permissions) = match target {
|
||||
SettingsTarget::Permissions => (None, true),
|
||||
SettingsTarget::Page(page) => {
|
||||
let decls = self.shared.ui.items(super::ui_points::SETTINGS, Some(self.id()));
|
||||
let Some(decl) = decls.first().map(|i| &i.decl) else {
|
||||
return Err(HostError::NotFound("the plugin declares no [contributes.settings]".into()));
|
||||
};
|
||||
if let Some(page) = &page {
|
||||
let pages = decl.get("pages").and_then(|p| p.as_array());
|
||||
if !pages.is_some_and(|ps| ps.iter().any(|p| p.get("id").and_then(|id| id.as_str()) == Some(page)))
|
||||
{
|
||||
return Err(HostError::NotFound(format!("the plugin declares no settings page {page:?}")));
|
||||
}
|
||||
}
|
||||
(page, false)
|
||||
}
|
||||
};
|
||||
self.shared
|
||||
.sink
|
||||
.emit(Some(client), PluginEvent::OpenSettings { plugin_id: self.id().to_owned(), page, permissions });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn status_item(&self, id: &str, item: Option<StatusItem>) {
|
||||
let key = (self.id().to_owned(), id.to_owned());
|
||||
{
|
||||
|
||||
@@ -144,6 +144,24 @@ fn lookup_translation<'a>(catalog: &'a BTreeMap<String, String>, source: &str) -
|
||||
None
|
||||
}
|
||||
|
||||
/// Adds the plugin's own explanations (`[capabilities.reasons]`) to `capabilities`, with their
|
||||
/// translations from the package's `locales/<tag>.json`.
|
||||
pub fn explain_capabilities(capabilities: &mut [ide_extension::CapabilityInfo], pkg: &Package) {
|
||||
let reasons = &pkg.manifest.capabilities.reasons;
|
||||
if reasons.is_empty() {
|
||||
return;
|
||||
}
|
||||
let catalogs = read_locale_catalogs(pkg);
|
||||
for cap in capabilities.iter_mut() {
|
||||
let Some(reason) = reasons.get(&cap.id) else { continue };
|
||||
cap.reason_locales = catalogs
|
||||
.iter()
|
||||
.filter_map(|(tag, catalog)| Some((tag.clone(), lookup_translation(catalog, reason)?.to_owned())))
|
||||
.collect();
|
||||
cap.reason = Some(reason.clone());
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads and validates a plugin package's Overview (`description` / `description-file`)
|
||||
/// and What's New (`change-notes` / `change-notes-file`), along with their
|
||||
/// per-locale translations from `locales/<tag>.json` and localized Markdown siblings.
|
||||
@@ -234,6 +252,32 @@ mod tests {
|
||||
assert!(docs.files.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capability_reasons_come_with_their_translations() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
std::fs::create_dir_all(tmp.path().join("locales")).unwrap();
|
||||
std::fs::write(tmp.path().join("locales/zh-CN.json"), r#"{ "Imports a log you copied.": "导入复制的日志。" }"#)
|
||||
.unwrap();
|
||||
let src = "id = \"acme.docs\"\nname = \"Docs\"\nversion = \"1.0.0\"\nengines.openidea = \"^1.19\"\n\
|
||||
[capabilities]\nrequired = [\"project.read\"]\noptional = [\"clipboard.read\"]\n\
|
||||
[capabilities.reasons]\n\"clipboard.read\" = \"Imports a log you copied.\"\n";
|
||||
let pkg = Package::new(Manifest::parse(src).unwrap(), tmp.path().to_path_buf());
|
||||
let m = &pkg.manifest;
|
||||
let mut caps: Vec<_> = m
|
||||
.capabilities
|
||||
.all()
|
||||
.map(|c| ide_extension::CapabilityInfo::new(c, m.capabilities.is_optional(c), false))
|
||||
.collect();
|
||||
explain_capabilities(&mut caps, &pkg);
|
||||
let clipboard = caps.iter().find(|c| c.id == "clipboard.read").unwrap();
|
||||
assert_eq!(clipboard.reason.as_deref(), Some("Imports a log you copied."));
|
||||
assert_eq!(clipboard.reason_locales.get("zh-CN").map(String::as_str), Some("导入复制的日志。"));
|
||||
// The host's own description stays.
|
||||
assert_eq!(clipboard.description, ide_extension::Capability::ClipboardRead.describe());
|
||||
let read = caps.iter().find(|c| c.id == "project.read").unwrap();
|
||||
assert_eq!((read.reason.as_deref(), read.reason_locales.len()), (None, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn markdown_files_and_localized_siblings_are_loaded_and_tracked() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -66,7 +66,7 @@ mod websocket;
|
||||
|
||||
pub use api::{CredentialSecretStore, FileSecretStore, HostWorkspace, PluginWorkspace, SecretStore};
|
||||
pub use build_graph::{BuildGraph, GradleModule};
|
||||
pub use docs::{MAX_PLUGIN_DOC, PluginDocs, plugin_docs};
|
||||
pub use docs::{MAX_PLUGIN_DOC, PluginDocs, explain_capabilities, plugin_docs};
|
||||
pub(crate) use hover::merge as merge_hover;
|
||||
pub use icons::{
|
||||
MAX_PLUGIN_ICON, map_asset as icon_theme_map_asset, plugin_icon, sanitize_svg, svg_prefix as icon_theme_svg_prefix,
|
||||
@@ -950,6 +950,7 @@ impl PluginHost {
|
||||
}
|
||||
}
|
||||
annotate_java_agent_vm_options(&mut capabilities, m);
|
||||
explain_capabilities(&mut capabilities, &pkg);
|
||||
capabilities.sort_by(|a, b| b.risk.cmp(&a.risk).then(a.id.cmp(&b.id)));
|
||||
let signer_changed = self.signer_changed(&m.id, src);
|
||||
let answered = |c: &CapabilityInfo| {
|
||||
@@ -1811,7 +1812,12 @@ impl PluginHost {
|
||||
client.as_deref(),
|
||||
PluginEvent::ConsentRequested {
|
||||
plugin_id: id.to_owned(),
|
||||
capabilities: pending.iter().map(|c| CapabilityInfo::new(c, false, false)).collect(),
|
||||
capabilities: {
|
||||
let mut caps: Vec<CapabilityInfo> =
|
||||
pending.iter().map(|c| CapabilityInfo::new(c, false, false)).collect();
|
||||
explain_capabilities(&mut caps, &plugin.pkg);
|
||||
caps
|
||||
},
|
||||
},
|
||||
);
|
||||
return Err(IdeError::new(
|
||||
@@ -2765,13 +2771,12 @@ impl PluginHost {
|
||||
.map(|w| format!("{} is missing; build the plugin first", w.display())),
|
||||
};
|
||||
let docs = plugin_docs(&pkg).unwrap_or_else(|_| PluginDocs::from_manifest(&m));
|
||||
let mut capabilities: Vec<CapabilityInfo> =
|
||||
m.capabilities.all().map(|c| CapabilityInfo::new(c, m.capabilities.is_optional(c), false)).collect();
|
||||
explain_capabilities(&mut capabilities, &pkg);
|
||||
out.push(CatalogPlugin {
|
||||
has_code: m.wasm.is_some(),
|
||||
capabilities: m
|
||||
.capabilities
|
||||
.all()
|
||||
.map(|c| CapabilityInfo::new(c, m.capabilities.is_optional(c), false))
|
||||
.collect(),
|
||||
capabilities,
|
||||
contributions: counts(&m),
|
||||
id: m.id,
|
||||
name: m.name,
|
||||
@@ -3557,6 +3562,7 @@ impl PluginHost {
|
||||
}
|
||||
}
|
||||
annotate_java_agent_vm_options(&mut capabilities, m);
|
||||
explain_capabilities(&mut capabilities, &p.pkg);
|
||||
// Hosts remembered through `net:ask` are grants of their own: listed
|
||||
// separately so the user can revoke them one by one.
|
||||
let net_hosts = grant
|
||||
|
||||
@@ -169,6 +169,7 @@ pub fn forwarded(event: &PluginEvent) -> bool {
|
||||
| PluginEvent::PromptClosed { .. }
|
||||
| PluginEvent::PromptWaiting { .. }
|
||||
| PluginEvent::RevealView { .. }
|
||||
| PluginEvent::OpenSettings { .. }
|
||||
| PluginEvent::CommitRequested { .. }
|
||||
| PluginEvent::ClipboardRequested { .. }
|
||||
| PluginEvent::EndpointsChanged { .. }
|
||||
|
||||
@@ -384,6 +384,10 @@ pub enum PluginEvent {
|
||||
/// Bring the tool window of the plugin's view `view` to the front.
|
||||
#[serde(rename_all = "camelCase")]
|
||||
RevealView { plugin_id: String, view: String },
|
||||
/// Open Settings at the plugin's own page: its settings node (`page` none), the declared
|
||||
/// sub-page `page`, or (`permissions`) Settings › Plugins with its permissions in view.
|
||||
#[serde(rename_all = "camelCase")]
|
||||
OpenSettings { plugin_id: String, page: Option<String>, permissions: bool },
|
||||
/// A command needs the window's Commit view: answer with
|
||||
/// `plugin_answer_commit(request_id, …)`. Closed like a prompt (`PromptClosed`).
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
||||
@@ -1521,12 +1521,16 @@ mod tests {
|
||||
#[test]
|
||||
fn settings_pages_validate_manifest_files_commands_and_api() {
|
||||
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../ide-plugin/tests/fixtures/settings-pages");
|
||||
let source = std::fs::read_to_string(root.join("plugin.toml")).unwrap();
|
||||
let full = std::fs::read_to_string(root.join("plugin.toml")).unwrap();
|
||||
let check = |source: &str| {
|
||||
let manifest = ide_extension::Manifest::parse(source)?;
|
||||
let decl = manifest.declarations(SETTINGS).into_iter().next().unwrap();
|
||||
settings(&Package::new(manifest, root.clone()), decl)
|
||||
};
|
||||
check(&full).unwrap();
|
||||
// Pages need API 1.3: without the fixture's 1.19 `[capabilities]`, that is the gate.
|
||||
let (start, end) = (full.find("[capabilities]").unwrap(), full.find("[[contributes.commands]]").unwrap());
|
||||
let source = format!("{}{}", &full[..start], &full[end..]).replace("^1.19", "^1.3");
|
||||
let valid = check(&source).unwrap();
|
||||
assert_eq!(valid.json["pages"].as_array().unwrap().len(), 2);
|
||||
assert_eq!(valid.json["properties"].as_array().unwrap().len(), 3);
|
||||
|
||||
@@ -3555,6 +3555,43 @@ fn settings_actions_choose_their_layer_without_losing_the_project() {
|
||||
}
|
||||
}
|
||||
|
||||
/// API 1.19: a plugin opens Settings at its own node, one of its declared pages or its
|
||||
/// permissions, in the invoking window; it can't name a page it doesn't declare. Its
|
||||
/// `[capabilities.reasons]` come with the permissions, translated.
|
||||
#[test]
|
||||
fn plugins_open_their_own_settings_and_explain_their_permissions() {
|
||||
let f = fixture(Limits::default());
|
||||
let info = f.install(&sample("settings-pages"));
|
||||
let net = info.capabilities.iter().find(|c| c.id == "net:api.example.com").unwrap();
|
||||
assert_eq!(net.reason.as_deref(), Some("Tests a model profile against the provider's API."));
|
||||
assert_eq!(net.reason_locales.get("zh-CN").map(String::as_str), Some("用服务商的 API 测试模型配置。"));
|
||||
assert!(net.description.contains("api.example.com"), "the host's description stays: {}", net.description);
|
||||
|
||||
let opened = |f: &Fixture| {
|
||||
f.take_events().into_iter().find_map(|(client, e)| match e {
|
||||
PluginEvent::OpenSettings { plugin_id, page, permissions } => Some((client, plugin_id, page, permissions)),
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
f.take_events();
|
||||
let main = Some("main".to_owned());
|
||||
let id = "settings-pages".to_owned();
|
||||
f.run("settings-pages", "open-settings", None).unwrap();
|
||||
assert_eq!(opened(&f), Some((main.clone(), id.clone(), None, false)));
|
||||
f.run("settings-pages", "open-settings", Some("llm")).unwrap();
|
||||
assert_eq!(opened(&f), Some((main.clone(), id.clone(), Some("llm".into()), false)));
|
||||
f.run("settings-pages", "open-permissions", None).unwrap();
|
||||
assert_eq!(opened(&f), Some((main, id, None, true)));
|
||||
|
||||
let err = f.run("settings-pages", "open-settings", Some("Plugins")).unwrap_err();
|
||||
assert!(err.contains("declares no settings page"), "{err}");
|
||||
assert_eq!(opened(&f), None);
|
||||
// Without a window there is nowhere to open it.
|
||||
let no_window = Invocation { client: None, ..f.inv() };
|
||||
assert!(f.host.run_command("settings-pages", "open-permissions", None, no_window).is_err());
|
||||
assert_eq!(opened(&f), None);
|
||||
}
|
||||
|
||||
/// A tree filled from a pinned program's output, and a terminal for the
|
||||
/// activated entry in the invoking window, titled and sized by the plugin's
|
||||
/// settings (the `jobs` fixture).
|
||||
|
||||
@@ -421,8 +421,10 @@ mod tests {
|
||||
// `pip install`: a new top-level entry changes the folder's modification time.
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
write(dir.path(), "newpkg/__init__.py", "def installed_later(): pass\n");
|
||||
let file = fs::File::open(dir.path()).unwrap();
|
||||
file.set_modified(SystemTime::now() + Duration::from_secs(5)).ok();
|
||||
// Coarse file system clocks may not move within the test; push it forward. Windows can't
|
||||
// open a directory as a plain file (it needs backup semantics), and NTFS keeps fine times.
|
||||
#[cfg(unix)]
|
||||
fs::File::open(dir.path()).unwrap().set_modified(SystemTime::now() + Duration::from_secs(5)).ok();
|
||||
let second = libraries.index(&roots, &syntax, &cancel).unwrap();
|
||||
assert!(!Arc::ptr_eq(&first, &second));
|
||||
assert_eq!(candidates(&second, "installed_later"), ["from newpkg import installed_later"]);
|
||||
|
||||
@@ -19,7 +19,7 @@ mod wit_host;
|
||||
pub use actor::{Actor, ActorError, Pending};
|
||||
pub use runtime::{
|
||||
API_VERSION, CANCELLED, CallCancel, CallError, GuestError, HostApi, MAX_CLIPBOARD_BYTES, PluginEngine, Runtime,
|
||||
RuntimeSetup, check_api, component_api, host_api,
|
||||
RuntimeSetup, SettingsTarget, check_api, component_api, host_api,
|
||||
};
|
||||
pub use sandbox::{
|
||||
MAX_READ_BYTES, inside_root, inside_roots, read_text, resolve_in_root, resolve_in_roots, resolve_new_in_root,
|
||||
|
||||
@@ -64,7 +64,7 @@ use views_bindings::exports::openidea::plugin::view_provider as wit_view;
|
||||
use views_bindings::openidea::plugin::view_types as wit_vt;
|
||||
|
||||
/// The API version of the world above, `major.minor` of [`host_api`].
|
||||
pub const API_VERSION: &str = "1.18";
|
||||
pub const API_VERSION: &str = "1.19";
|
||||
const EPOCH_TICK: Duration = Duration::from_millis(10);
|
||||
pub(crate) const MAX_TEXT: usize = 1 << 20;
|
||||
/// The most text, and the most PNG bytes, `ui.read-clipboard` returns.
|
||||
@@ -77,6 +77,15 @@ pub const CANCELLED: &str = "was cancelled";
|
||||
/// What plugin code may ask of the IDE, per plugin. Implemented by the host,
|
||||
/// which routes notifications and status items to windows and edits to open
|
||||
/// documents. Capabilities are already checked when these are called.
|
||||
/// Where `settings.open` / `settings.open-permissions` take the user.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum SettingsTarget {
|
||||
/// The plugin's settings node, or the declared sub-page with this id.
|
||||
Page(Option<String>),
|
||||
/// Settings › Plugins with the plugin's permissions in view.
|
||||
Permissions,
|
||||
}
|
||||
|
||||
pub trait HostApi: Send + Sync {
|
||||
/// Creates/replaces this plugin's non-secret project connection settings.
|
||||
fn database_upsert(&self, root: &Path, source: crate::PluginDataSource) -> Result<(), HostError>;
|
||||
@@ -267,6 +276,9 @@ pub trait HostApi: Send + Sync {
|
||||
) -> Result<Option<Vec<String>>, HostError>;
|
||||
/// Brings the plugin's declared view to the front in `client`'s window.
|
||||
fn reveal_view(&self, client: Option<&str>, view: &str) -> Result<(), HostError>;
|
||||
/// Opens Settings in `client`'s window at one of the plugin's own pages
|
||||
/// (`settings.open`, `settings.open-permissions`).
|
||||
fn open_settings(&self, client: Option<&str>, target: SettingsTarget) -> Result<(), HostError>;
|
||||
/// Whether this stable id is a command declared by this plugin.
|
||||
fn owns_command(&self, id: &str) -> bool;
|
||||
/// Executes a stable command in the invoking window and waits for its result.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! types and the implementation of every import. Capabilities are checked
|
||||
//! here; a missing one returns `error::denied` (the plugin can degrade).
|
||||
|
||||
use crate::runtime::{MAX_TITLE, StoreData, clip};
|
||||
use crate::runtime::{MAX_TITLE, SettingsTarget, StoreData, clip};
|
||||
use crate::sandbox;
|
||||
use crate::types::{
|
||||
EditorContext, EventKind, HostError, HttpRequest, NotificationLevel, PickItem, ProcessChunk, ProcessCommand,
|
||||
@@ -2377,6 +2377,24 @@ impl settings::Host for StoreData {
|
||||
let root = if self.invocation.global_settings { None } else { self.invocation.workspace_root.clone() };
|
||||
Ok(self.host.setting(root.as_deref(), &clip(key, 128)))
|
||||
}
|
||||
|
||||
fn open(&mut self, page: Option<String>) -> Fallible<()> {
|
||||
self.open_settings(SettingsTarget::Page(page.map(|p| clip(p, 128))))
|
||||
}
|
||||
|
||||
fn open_permissions(&mut self) -> Fallible<()> {
|
||||
self.open_settings(SettingsTarget::Permissions)
|
||||
}
|
||||
}
|
||||
|
||||
impl StoreData {
|
||||
fn open_settings(&mut self, target: SettingsTarget) -> Fallible<()> {
|
||||
if let Err(e) = self.require_interactive() {
|
||||
return Ok(Err(e));
|
||||
}
|
||||
let client = self.invocation.client.clone();
|
||||
Ok(self.host.open_settings(client.as_deref(), target).map_err(to_wit))
|
||||
}
|
||||
}
|
||||
|
||||
impl views_bindings::openidea::plugin::view_types::Host for StoreData {}
|
||||
|
||||
@@ -98,7 +98,7 @@ fn the_sdk_carries_the_hosts_wit() {
|
||||
|
||||
#[test]
|
||||
fn the_version_check_runs_compatible_components_and_explains_the_rest() {
|
||||
let host = v("1.18.0");
|
||||
let host = v("1.19.0");
|
||||
for ok in [
|
||||
"1.0.0",
|
||||
"1.3.0",
|
||||
@@ -117,15 +117,16 @@ fn the_version_check_runs_compatible_components_and_explains_the_rest() {
|
||||
"1.16.0",
|
||||
"1.17.0",
|
||||
"1.18.0",
|
||||
"1.19.0",
|
||||
"1.0.0-rc.1",
|
||||
] {
|
||||
assert_eq!(check_api(&v(ok), &host), Ok(()), "{ok}");
|
||||
}
|
||||
let newer = check_api(&v("1.19.0"), &host).unwrap_err();
|
||||
assert!(newer.contains("1.19") && newer.contains("update OpenIDEA"), "{newer}");
|
||||
let newer = check_api(&v("1.20.0"), &host).unwrap_err();
|
||||
assert!(newer.contains("1.20") && newer.contains("update OpenIDEA"), "{newer}");
|
||||
assert!(check_api(&v("2.0.0"), &host).unwrap_err().contains("update OpenIDEA"));
|
||||
let older = check_api(&v("0.2.0"), &host).unwrap_err();
|
||||
assert!(older.contains("rebuild it with the 1.18 SDK"), "{older}");
|
||||
assert!(older.contains("rebuild it with the 1.19 SDK"), "{older}");
|
||||
// 0.x: every minor is its own API.
|
||||
assert_eq!(check_api(&v("0.2.0"), &v("0.2.5")), Ok(()));
|
||||
assert!(check_api(&v("0.1.0"), &v("0.2.0")).is_err());
|
||||
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
ba019d950ae83c45845a5cfcb2e890eca25c6f102b78f8cd3090f604c56aaf17
|
||||
1e6a4ba99409620e9bf3ceb51387704018737f186a89037b05bcbcee1e38a967
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
926ca24c9a08166e34fb8a6b2c6dd06a92cf3370dc01ff3054b533356314c84b
|
||||
667622767aa8c75a44c1348f6d07979ecb7a2db7ede9613999b61658a58557f5
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
dd7e4dcc429bf44b839cabe682f36cb3951a3dcf535f500f90cb60ff749e31e6
|
||||
689a9f36b9d13e0b57bd1540321a06da65837510fd9a37225776abd8baccfd7c
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
1acae0035935e9f6e7b52826e9731aeb15dafb5cfcc561a2b98dae10676f53f8
|
||||
0316df8c6f5fd4523f077c1a12d2d8af9592729a66a5a99a155dde42bb331e96
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
d3b940a7899ed3a303b51c529d2771ec9ac20a22d996dbc9760dd118dc10dbc1
|
||||
6732e125bfefcfad1c5712516e05bdaff7ceea4e71994de45109086e252e5f72
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
955e804453e7e8ea37a49ab7b65289d31fef1216eda4f1834e912375196adb17
|
||||
bb6c942f198534adf96354dd670c175f73954782f516762c564d157f5004b744
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
42caf6ccd73e3d622894416b0fd5007b8a1d773d6bf7e81c0ff4d0e97f888e43
|
||||
fa0957c9041bc31f7dc5b58aa912fa83851e6f0058d055e9582950195a1015b4
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
5795a3b4a25a7563c3a43ed0d414d3e520badd09066d5e5d2bcbc23ba4b8e1c8
|
||||
00ac40b08a5a39d4e011e9391732f19c20eb439a6f980b8d96334a5547c28666
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
1e53f7713c294be551fa4641cfda5b2497d7a57a35116ca4dd29783e63a7a9f6
|
||||
82473da5332e96dc9ef3a82947cde59b0a5d6acd49f8baad7c4fcc46ed4284dc
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
650a8e88e4e6999e77159fb25516b5990f6ae7805167e89a8e3193d53fd57822
|
||||
8532a968b8522e9b1b6f0df3aed073191e2a441ab960f96af79d7132fda4090a
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
3f5a85c4e3802a93b74513c1981b4202ad5bc70566a5cfcca7a1be2573a03f24
|
||||
ee0f3be61a8684275dc15acfdfe374b6d1751078d15c92608ba39ccbc6e10c67
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
61f41c0d8ce0bf2243c8cb3b2d2a84037a07958fb18d6ebb016abb08b469a80c
|
||||
4a3602e6024dcbeccb59ef9b324bab3e3254c908a7513c4f08bcbd212e368f9f
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
e5877e2978f8d36c1d8b684e84bfd21f9047b0153bed952e89299a69968029c0
|
||||
bd6aa162f07d96a580a8891433fd042e08a976f0f3ce4aee7694957ad394057c
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
7fe7457184144c93b761b8fa26e45f1b8a55cc6753d91a7353bd67d7a5bd09a9
|
||||
edac72326d401c873394ff0de9a659d5f3642259df136b87fb9b6cfe632e60c5
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
19480e0dd6ae1e36aadabbda9ea49a34ee0aa37d4c7182c297b6d84c9b13991f
|
||||
7454788469a0c0662987a4a774d8fc59b20b0dfec9bbac754e8e4aa0a46a1b43
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
7bd6651b0fd45032847868c341bc815b115ac678dcaaf26e752ae72ac1b0549f
|
||||
268b18f9303602b00f5c0d7254967aeb95c377b5a85011ead539b4ccab5811e2
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
9c99195f1c7efdb27f3715158559218db2f7db03325cc04af455b8f60653da24
|
||||
9e8809f276ef27561fe337f8268b3cf4f06be7ac1707a61e6e41407ec932bbb1
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
875df930f71fa22112dbafddb6de460b9828d0aa10812ee1eeedc4052bc88061
|
||||
c4594d365423395722e7f8e14f6d9c32ad4ff579b2eb42f5e2c5650e7cfa6bdc
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
d10b1225ab4228d3906e88e79ef346302a4db89aa4dd5a82da694cec408e5496
|
||||
91b267d3845bbd199662c0857ee23634a1d1b287204ce81fa148f1ce43eace3b
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
12cb92d4b45279bbdc345dbdd4c8d4827abc5054d0324d35b85b648840d9c556
|
||||
8e5c91ab272fa1678fbef9607f12513f7a589ef3fd293cfd7a52497cf637de3d
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
e8c1116c94c82ea4ed0fd7e33070bc878e88dcfe8f08632cd700bb3418b712cc
|
||||
a2e19194ba5f42e9d02d996c77444e8a5267fecc99bb02933f35aabb22fddadd
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
9bd13ae90217e4355014512bce62de8b471a466484100abb7cc8b9197c008c93
|
||||
78a9be879f2a07417c26a0818d2896ba6d93ea60bed69f3ebaf963ea1842147b
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
f3d78da579d47985908f8e7ce63793ff58b2d255992df97a0acdec1c56a039ee
|
||||
2cc25b5de5003300b686ecc47a9f2379dcb61ed954c0b41db6b5945c865fffb7
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
123a768fd0e531c6f8ce63648f10ddef2d309d01e5e8ac1386c16e45a9c0329b
|
||||
a1167c3620a2fd143d94cbb235139f7f428f5360dcab65730f5abf0c5944b061
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
6a57f349ba434cdc10ddbdd2fedb1578a18dcada080f6d8b9096a95174a2ab79
|
||||
57062a5c91e85524e22d61ef7cdda9f5241f760ccb47b3fd7a53c7bbd86ce58a
|
||||
@@ -5,9 +5,9 @@ wit_bindgen::generate!({
|
||||
inline: "
|
||||
package fixture:misbehave;
|
||||
world misbehave {
|
||||
include openidea:plugin/plugin-syntax@1.18.0;
|
||||
export openidea:plugin/providers@1.18.0;
|
||||
export openidea:plugin/file-actions@1.18.0;
|
||||
include openidea:plugin/plugin-syntax@1.19.0;
|
||||
export openidea:plugin/providers@1.19.0;
|
||||
export openidea:plugin/file-actions@1.19.0;
|
||||
}
|
||||
",
|
||||
path: "../../../../../wit",
|
||||
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
db06d81fb37a51711e2b76ab0192eb23293ef498e8ff6e5e46e0b5099d6ba038
|
||||
4ede6078038216c3c81de9732c32d653669a06c55b3482f7640cae3a2eab6b8c
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
a689eca7666880c1096bf9bcaaba3d355a76666a7abe7524e5bb6f641a7d67fd
|
||||
1f1b4a5aa2913ab087224d152df4c308e7b572c746ffabee18786fce78c50f9d
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
eff2b16fcdf47f7f0a204bb229438b585917c3be62fd9ea9a02898b415530d6e
|
||||
37ace7bb2fece14d1178166c3b81c938bebdf3938399384dff319eaa6dbc964f
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
97177d6d25b9a205c1cf1cf9bd8e50ad88a119e9876dddd786d72575d2cbae5c
|
||||
679aa7de740ef9c777fee6c72ed586ce9a8dc1b1f2d553214c080c0003626971
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
14559c777048bef5ec800dc6ea4e3f263268a6bd16000023c27f1f82a0d89ca6
|
||||
7a7eb7e96053b06c75b4881619370b2faeca9da042fb6b54a75b38a98a1b8ad8
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
24060000f8040dbd6ba007b8da84e2800f93f3090aaafc0fb864ecc03266df82
|
||||
fee91a25750bc82ef5f44e85891466229da3884bbeca737331e72bd6f533c082
|
||||
@@ -1,4 +1,4 @@
|
||||
# Multi-page settings example (API 1.3)
|
||||
# Multi-page settings example (API 1.3, 1.19)
|
||||
|
||||
Two IDE-rendered pages demonstrate grouped string lists and an editable model
|
||||
profile table. `Test` first applies pending settings, then runs the declared
|
||||
@@ -6,6 +6,11 @@ profile table. `Test` first applies pending settings, then runs the declared
|
||||
it reads the saved JSON array and reports success through a notification.
|
||||
This fixture checks the settings/action flow; it does not contact a provider.
|
||||
|
||||
API 1.19: `[capabilities.reasons]` explains the optional `net:` permission
|
||||
below the host's own description (translated by `locales/zh-CN.json`), and the
|
||||
`open-settings` (argument: a page id, or none for the plugin's node) and
|
||||
`open-permissions` commands open Settings there.
|
||||
|
||||
Build with `plugins/build.sh crates/ide-plugin/tests/fixtures/settings-pages`.
|
||||
Install or link this directory with `openidea-plugin link` and open
|
||||
Settings › Plugins › Model Profiles. Edit without Apply and Cancel to discard;
|
||||
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
ce8e3742bdfa1e9f232b01af7569a72a2349c93e16866436d6a4d051a5aa9fdf
|
||||
3f7c0bd15b37966fb6dd400ce32f6310c19aedfcdc8adfd90d6af4d1a409c96a
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"Tests a model profile against the provider's API.": "用服务商的 API 测试模型配置。"
|
||||
}
|
||||
@@ -1,14 +1,30 @@
|
||||
id = "settings-pages"
|
||||
name = "Model Profiles"
|
||||
version = "0.1.0"
|
||||
engines.openidea = "^1.3"
|
||||
engines.openidea = "^1.19"
|
||||
wasm = "dist/plugin.wasm"
|
||||
activation = ["on-command:*"]
|
||||
|
||||
[capabilities]
|
||||
optional = ["net:api.example.com"]
|
||||
|
||||
# API 1.19: shown below the host's description of the permission.
|
||||
[capabilities.reasons]
|
||||
"net:api.example.com" = "Tests a model profile against the provider's API."
|
||||
|
||||
[[contributes.commands]]
|
||||
id = "test"
|
||||
title = "Test model profile"
|
||||
|
||||
# API 1.19: `settings.open` and `settings.open-permissions`.
|
||||
[[contributes.commands]]
|
||||
id = "open-settings"
|
||||
title = "Open Model Profiles settings"
|
||||
|
||||
[[contributes.commands]]
|
||||
id = "open-permissions"
|
||||
title = "Open Model Profiles permissions"
|
||||
|
||||
[contributes.settings]
|
||||
title = "Model Profiles"
|
||||
|
||||
|
||||
@@ -6,9 +6,13 @@ use openidea_plugin::{Error, Invocation, NotificationLevel, Plugin, host, regist
|
||||
pub struct Profiles;
|
||||
|
||||
impl Plugin for Profiles {
|
||||
fn run_command(&mut self, id: &str, ctx: &Invocation, _arg: Option<&str>) -> Result<Option<String>, Error> {
|
||||
if id != "test" {
|
||||
return Err(Error::Invalid("unknown command".into()));
|
||||
fn run_command(&mut self, id: &str, ctx: &Invocation, arg: Option<&str>) -> Result<Option<String>, Error> {
|
||||
match id {
|
||||
// A notice's "Change in Settings" / "Grant access" buttons go straight there.
|
||||
"open-settings" => return host::open_settings(arg).map(|()| None),
|
||||
"open-permissions" => return host::open_permissions().map(|()| None),
|
||||
"test" => {}
|
||||
_ => return Err(Error::Invalid("unknown command".into())),
|
||||
}
|
||||
let json = host::setting("profiles").unwrap_or_else(|| "[]".into());
|
||||
let profiles: serde_json::Value = serde_json::from_str(&json).map_err(|e| Error::Invalid(e.to_string()))?;
|
||||
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
687b349d2b55cbd0220fdd33cddf98d8bab735f5e6716d8b9a27029ab4973953
|
||||
54e09f6d2ae0bb4772661ec7d77f3b92e30da19f115847e456615af1d99ee608
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
00ae790cecb1fd107e407d0c6a1e149713b2969af220de0267dbe9b55fc628ef
|
||||
993bc87ead9037693e1f33a1d6ff20f08fb09ed5b0bb9a03641a6785f2a90f1c
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
d1d5e658f86af183a9ce21d3ad6230ddd00a05b7c3bd447b9fabfa171aa92920
|
||||
7b3456731392cca0aae6243689f7beab47d775a3f6adbadc0dd4bf1f23db8f5d
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
213aa998dfcc309f8abd24f12a44db4ac12b676bb7d3567309378ef650e05602
|
||||
5b2c9bb2a80ab7c7b777ce35bd5e86bd16c90085b6cfa5639eaa28850a7b828a
|
||||
Бінарний файл не відображається.
+1
-1
@@ -1 +1 @@
|
||||
ad698b8393a15b8af0065d97a73ade1cc98626ffe5ffd20cb1de6c06aef4611a
|
||||
6a40da7abf14285fb3274a6e2ace582373e5f96689360428c6db1287c62da043
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
046020f3a6500bedba728a132353024201e7c59cbe5fa819dfe8b8aba3a87bab
|
||||
5b86ed9e234d07d2c824719ec30e3705cfed1ae873e38be1c417c0a2623c95e2
|
||||
Бінарний файл не відображається.
@@ -1 +1 @@
|
||||
8c0718c8d732965a6a87a68695a22c37c6ebdd26877019d47c8e2de3dfc7b10d
|
||||
a0170f44828c31babcdae54fcaefb1546d7f7dfecb8145c21ad293a90acfaac7
|
||||
@@ -142,7 +142,11 @@ impl Watcher {
|
||||
/// Explicit refresh for writes to Git common metadata outside the watched root.
|
||||
pub fn reload_ignore_rules(&self) {
|
||||
self.rules.reload_repo_level();
|
||||
self.rules.invalidate_tree(self.rules.repo_root().unwrap_or(Path::new("/")));
|
||||
// Outside a repository, everything cached up to the filesystem root may have probed for a
|
||||
// `.git` that now exists (`git init`). `/` is no ancestor of `C:\…` on Windows, so take
|
||||
// the watch root's own topmost ancestor.
|
||||
let top = self.root.ancestors().last().unwrap_or(&self.root);
|
||||
self.rules.invalidate_tree(self.rules.repo_root().unwrap_or(top));
|
||||
}
|
||||
|
||||
/// The watched directory (canonical).
|
||||
|
||||
@@ -350,6 +350,27 @@ fn watcher_read_dir_reuses_its_ignore_rules() {
|
||||
assert!(watcher.read_dir(&other, &[]).unwrap().iter().all(|e| !e.ignored));
|
||||
}
|
||||
|
||||
/// A repository made after the watch started (`git init` in an open project) and the ignore
|
||||
/// entries written into it are seen by the next listing once the rules are reloaded.
|
||||
#[test]
|
||||
fn watcher_read_dir_sees_a_repository_made_after_it_started() {
|
||||
let (_t, r) = root();
|
||||
write(&r.join("shared.ignore-me"), "x");
|
||||
write(&r.join("private.ignore-me"), "x");
|
||||
let sink: SharedSink = Arc::new(|_| {});
|
||||
let watcher = Watcher::start(&r, vec![], sink, Box::new(|_| {})).unwrap();
|
||||
assert_eq!(watcher.repo_root(), None);
|
||||
// Listed once before `git init`: the rules remember that no repository encloses the folder.
|
||||
assert!(watcher.read_dir(&r, &[]).unwrap().iter().all(|e| !e.ignored));
|
||||
write(&r.join(".git/HEAD"), "ref: refs/heads/main\n");
|
||||
write(&r.join(".gitignore"), "/shared.ignore-me\n");
|
||||
write(&r.join(".git/info/exclude"), "/private.ignore-me\n");
|
||||
watcher.reload_ignore_rules();
|
||||
let ignored: BTreeSet<String> =
|
||||
watcher.read_dir(&r, &[]).unwrap().into_iter().filter(|e| e.ignored).map(|e| e.name).collect();
|
||||
assert_eq!(ignored, BTreeSet::from(["private.ignore-me".to_string(), "shared.ignore-me".to_string()]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn watcher_reports_changes() {
|
||||
let (_t, r) = root();
|
||||
|
||||
Loaded 100 of 216 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Заблокувати користувача