дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 10:07:11 +02:00
JS/TS inlay hints default as in WebStorm: inferred types for variables and fields, enum values, and parameter names for literal and anonymous-function arguments. The Editor toggle now reaches the typescript-language-server fallback too. Long hints are cut with the full label in the tooltip, which also refreshes when the server changes it. Closes #7326 Co-authored-by: wildcatDownstairs <[email protected]>
637 рядки
26 KiB
Rust
637 рядки
26 KiB
Rust
use crate::{Host, Project};
|
||
use ide_command::command;
|
||
use ide_core::settings::Settings;
|
||
use ide_core::{IdeEvent, IdeResult, RequestId, TaskId};
|
||
use ide_workspace::settings::SettingsScope;
|
||
use serde::{Deserialize, Serialize};
|
||
use specta::Type;
|
||
use std::path::{Path, PathBuf};
|
||
use std::sync::Arc;
|
||
|
||
#[derive(Serialize, Deserialize, Type)]
|
||
#[serde(rename_all = "camelCase")]
|
||
pub struct ProjectInfo {
|
||
pub trusted: bool,
|
||
pub root: ide_core::IpcPath,
|
||
pub name: String,
|
||
#[serde(default)]
|
||
pub display_name: String,
|
||
pub is_git: bool,
|
||
pub settings: Settings,
|
||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||
pub workspace: Option<ide_workspace::workspace::Workspace>,
|
||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||
pub unity: Option<ide_workspace::unity::UnityProjectInfo>,
|
||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||
pub unreal: Option<ide_workspace::unreal::UnrealProjectInfo>,
|
||
}
|
||
|
||
pub fn info(project: &Project) -> ProjectInfo {
|
||
let settings = project.settings.effective();
|
||
let custom = settings.general.project_name.trim();
|
||
let primary = if custom.is_empty() {
|
||
project.root.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default()
|
||
} else {
|
||
custom.to_owned()
|
||
};
|
||
let workspace = ide_workspace::workspace::Workspace::load(&project.root).ok().flatten();
|
||
ProjectInfo {
|
||
trusted: project.is_trusted(),
|
||
display_name: workspace
|
||
.as_ref()
|
||
.map(|w| w.display_name(&project.root, &primary))
|
||
.unwrap_or_else(|| primary.clone()),
|
||
name: workspace.as_ref().filter(|w| w.is_container(&project.root)).map(|w| w.name.clone()).unwrap_or(primary),
|
||
is_git: !project.repos.read().is_empty(),
|
||
settings,
|
||
root: project.root.clone().into(),
|
||
workspace,
|
||
unity: ide_workspace::unity::detect(&project.root),
|
||
unreal: ide_workspace::unreal::detect(&project.root),
|
||
}
|
||
}
|
||
|
||
/// Opens `path` in `window` (off the async workers: it touches the disk).
|
||
pub async fn open(host: &Arc<Host>, window: &str, path: &Path) -> IdeResult<Arc<Project>> {
|
||
let (h, window, path) = (host.clone(), window.to_owned(), path.to_path_buf());
|
||
host.blocking(move || h.open_project(&window, &path)).await
|
||
}
|
||
|
||
#[command(trust = always, desktop_body = async)]
|
||
pub async fn open_project(host: &Arc<Host>, window: &str, path: PathBuf) -> IdeResult<ProjectInfo> {
|
||
let project = open(host, window, &path).await?;
|
||
Ok(info(&project))
|
||
}
|
||
|
||
/// The project open in this window (a settings window: its parent's), if any.
|
||
#[command(trust = always, desktop_body = sync)]
|
||
pub fn project_current(host: &Host, window: &str) -> Option<ProjectInfo> {
|
||
host.project(window).ok().filter(|p| !p.light).map(|p| info(&p))
|
||
}
|
||
|
||
#[command(trust = always, desktop_body = spawn)]
|
||
pub fn close_project(host: &Host, window: &str) {
|
||
host.close_project(window);
|
||
}
|
||
|
||
/// Effective settings for the window's project, or global settings without one.
|
||
#[command(trust = always, desktop_body = sync)]
|
||
pub fn settings_get(host: &Host, window: &str) -> Settings {
|
||
host.with_proxy_password(match host.project(window) {
|
||
Ok(p) => p.settings.effective(),
|
||
Err(_) => host.global_settings.effective(),
|
||
})
|
||
}
|
||
|
||
/// Defaults plus the global layer, without any project's values: what new
|
||
/// projects (and projects without their own value) get.
|
||
#[command(trust = always)]
|
||
pub fn settings_get_global(host: &Host) -> Settings {
|
||
host.with_proxy_password(host.global_settings.effective())
|
||
}
|
||
|
||
/// Read the same host-wide value for the close dialog and the idle timer: another project's
|
||
/// daemon may have edited the file since this host loaded its settings.
|
||
#[command(trust = always)]
|
||
pub async fn remote_idle_timeout_minutes(host: &Arc<Host>) -> IdeResult<u16> {
|
||
let h = host.clone();
|
||
host.blocking(move || Ok(h.global_settings.layer(SettingsScope::Global).remote_development.idle_timeout_minutes))
|
||
.await
|
||
}
|
||
|
||
/// The removed built-in theme id a settings file of this window still names, if any:
|
||
/// `settings_get` reports the built-in that stands in for it, so the notice about
|
||
/// a theme that moved to a plugin can address the installs it concerns.
|
||
#[command(trust = always, desktop_body = sync)]
|
||
pub fn settings_removed_theme(host: &Host, window: &str) -> Option<String> {
|
||
match host.project(window) {
|
||
Ok(p) => p.settings.named_removed_theme().or_else(|| host.global_settings.named_removed_theme()),
|
||
Err(_) => host.global_settings.named_removed_theme(),
|
||
}
|
||
}
|
||
|
||
/// What a changed setting `key` starts or stops right away. Both `settings_set` commands (this
|
||
/// crate's and the desktop's) call it after writing the value.
|
||
pub fn apply_setting(host: &Arc<Host>, window: &str, key: &str) {
|
||
if key == "mcpServer" || key.starts_with("mcpServer.") {
|
||
host.mcp.apply(host);
|
||
}
|
||
if key == "agents" || key == "agents.automations" || key.starts_with("agents.automations.") {
|
||
let h = host.clone();
|
||
host.runtime.spawn_blocking(move || {
|
||
h.automations.sync_boot_service(&h);
|
||
h.automations.broadcast_changed(&h);
|
||
});
|
||
}
|
||
if key == "terminal" || key.starts_with("terminal.") {
|
||
super::term::apply_output_rate(host, window);
|
||
}
|
||
if "languages.typescript.watchProblems".starts_with(key)
|
||
&& let Some(watch) = host.project(window).ok().and_then(|p| p.tsc_watch.clone())
|
||
{
|
||
watch.apply(&host.runtime);
|
||
}
|
||
}
|
||
|
||
/// `value` is JSON text, e.g. `14` or `"dark"`. Every window (for a project
|
||
/// value: that project's windows) is told (`IdeEvent::SettingsChanged`) so it
|
||
/// re-reads its effective settings.
|
||
#[command(trust = always, desktop_body = sync)]
|
||
pub fn settings_set(
|
||
host: &Arc<Host>,
|
||
window: &str,
|
||
scope: SettingsScope,
|
||
key: String,
|
||
value: String,
|
||
) -> IdeResult<Settings> {
|
||
let applied = set_settings(host, window, scope, &key, &value)?;
|
||
apply_setting(host, window, &key);
|
||
let sink = host.window_sink(window);
|
||
sink.emit(IdeEvent::SettingsChanged { key });
|
||
if let Some(root) = applied.roots_changed {
|
||
sink.emit(IdeEvent::ProjectRootsChanged { root });
|
||
}
|
||
Ok(applied.settings)
|
||
}
|
||
|
||
/// Effective source / test / resource / excluded roots of the window's project:
|
||
/// auto-detected from build files, overridden by Settings › Project Structure.
|
||
/// Off the UI thread: Gradle source roots may walk the project for builds, slow on a share.
|
||
#[command(trust = always, desktop_body = spawn)]
|
||
pub fn project_roots(host: &Host, window: &str) -> IdeResult<ide_workspace::ProjectRoots> {
|
||
Ok(host.project(window)?.roots())
|
||
}
|
||
|
||
/// A project attached to the window's project, with its own Project Structure.
|
||
#[derive(Serialize, Type)]
|
||
#[serde(rename_all = "camelCase")]
|
||
pub struct WorkspaceMember {
|
||
pub root: ide_core::IpcPath,
|
||
/// Its project settings' Project Structure (not merged with the user settings).
|
||
pub structure: ide_core::settings::ProjectStructureSettings,
|
||
/// Roots detected from its build files.
|
||
pub detected: Vec<ide_workspace::SourceFolder>,
|
||
}
|
||
|
||
/// The workspace projects outside the window's project folder, for Mark Directory as there.
|
||
/// Each member's `for_project().layer(Project)` re-parses both settings layers and validates the
|
||
/// merged tree against `Settings`; that stack-hungry work must not run on the IPC (main) thread,
|
||
/// whose 1 MiB stack overflows on project open (STATUS_STACK_OVERFLOW).
|
||
#[command(trust = always, desktop_body = spawn)]
|
||
pub fn project_workspace_members(host: &Host, window: &str) -> IdeResult<Vec<WorkspaceMember>> {
|
||
let project = host.project(window)?;
|
||
Ok(project
|
||
.attached_roots()
|
||
.into_iter()
|
||
.map(|root| WorkspaceMember {
|
||
structure: project.settings.for_project(&root).layer(SettingsScope::Project).project_structure,
|
||
detected: ide_workspace::roots::detect(&root),
|
||
root: root.into(),
|
||
})
|
||
.collect())
|
||
}
|
||
|
||
/// Sets a `projectStructure.*` key in the settings of `root`, a project attached to the window's
|
||
/// project (Mark Directory as there). Every open window holding that project follows.
|
||
/// Like `project_workspace_members`, its `for_project` settings re-parse runs off the IPC thread.
|
||
#[command(trust = always, desktop_body = spawn)]
|
||
pub fn project_workspace_member_set(
|
||
host: &Arc<Host>,
|
||
window: &str,
|
||
root: PathBuf,
|
||
key: String,
|
||
value: String,
|
||
) -> IdeResult<()> {
|
||
let project = host.project(window)?;
|
||
if !project.attached_roots().contains(&root) {
|
||
return Err(ide_core::IdeError::invalid("Not a project attached to this one"));
|
||
}
|
||
if !key.starts_with("projectStructure.") {
|
||
return Err(ide_core::IdeError::invalid(format!("{key} is not a Project Structure setting")));
|
||
}
|
||
let value: serde_json::Value =
|
||
serde_json::from_str(&value).map_err(|e| ide_core::IdeError::invalid(e.to_string()))?;
|
||
project.settings.for_project(&root).set(SettingsScope::Project, &key, value)?;
|
||
let affected: Vec<_> = host
|
||
.projects()
|
||
.into_iter()
|
||
.filter(|p| p.root == root || p.member_excludes.read().contains_key(&root))
|
||
.collect();
|
||
host.runtime.spawn_blocking(move || {
|
||
for p in affected {
|
||
if p.root == root {
|
||
p.settings.reload();
|
||
p.sink.emit(IdeEvent::SettingsChanged { key: key.clone() });
|
||
}
|
||
p.refresh_index_scope();
|
||
p.sink.emit(IdeEvent::ProjectRootsChanged { root: p.root.clone().into() });
|
||
}
|
||
});
|
||
Ok(())
|
||
}
|
||
|
||
#[command(trust = always)]
|
||
pub fn cancel_request(host: &Host, id: RequestId) {
|
||
host.cancel_request(id);
|
||
}
|
||
|
||
/// Stops a background task the backend reported with `cancellable` set; false when it
|
||
/// has ended or can't be cancelled.
|
||
#[command(trust = always)]
|
||
pub fn cancel_task(id: TaskId) -> bool {
|
||
ide_core::task::cancel(id)
|
||
}
|
||
|
||
#[command(trust = always)]
|
||
pub fn project_trust_status(host: &Host, path: PathBuf) -> IdeResult<crate::trust::TrustStatus> {
|
||
host.trust.status(&path)
|
||
}
|
||
|
||
#[command(trust = always)]
|
||
pub fn project_trust_list(host: &Host) -> IdeResult<crate::trust::TrustDecisions> {
|
||
host.trust.decisions()
|
||
}
|
||
|
||
#[command(trust = always, desktop_body = async)]
|
||
pub async fn project_trust_set(host: &Host, path: PathBuf, trusted: bool, folder: bool) -> IdeResult<()> {
|
||
host.set_project_trust(&path, trusted, folder).await
|
||
}
|
||
|
||
#[command(trust = always, desktop_body = async)]
|
||
pub async fn project_trust_remove_location(host: &Host, path: PathBuf) -> IdeResult<()> {
|
||
host.trust.remove_location(&path)?;
|
||
host.refresh_project_trust().await
|
||
}
|
||
|
||
pub fn save_workspace(host: &Host, window: &str, name: &str, paths: Vec<std::path::PathBuf>) -> IdeResult<ProjectInfo> {
|
||
let project = host.project(window)?;
|
||
let previous = ide_workspace::workspace::Workspace::load(&project.root)?
|
||
.ok_or_else(|| ide_core::IdeError::invalid("This folder is not a workspace"))?;
|
||
for path in paths.iter().filter(|p| !previous.projects.contains(p)) {
|
||
require_attachment_trust(host, path)?;
|
||
}
|
||
if !previous.is_container(&project.root) && paths.first() != Some(&project.root) {
|
||
return Err(ide_core::IdeError::invalid("The primary project cannot be detached"));
|
||
}
|
||
if !previous.is_container(&project.root) && paths == [project.root.clone()] {
|
||
std::fs::remove_file(project.root.join(ide_workspace::workspace::FILE))?;
|
||
} else {
|
||
let workspace = ide_workspace::workspace::Workspace::save(&project.root, name, paths, false)?;
|
||
keep_attachment_private(&project.root, &workspace)?;
|
||
}
|
||
refresh_workspace(&project);
|
||
Ok(info(&project))
|
||
}
|
||
|
||
fn require_attachment_trust(host: &Host, path: &Path) -> IdeResult<()> {
|
||
if !host.trust.trusted(path)? {
|
||
return Err(ide_core::IdeError::invalid("Trust the project before attaching it"));
|
||
}
|
||
Ok(())
|
||
}
|
||
|
||
fn keep_attachment_private(root: &Path, workspace: &ide_workspace::workspace::Workspace) -> IdeResult<()> {
|
||
if !workspace.is_container(root) {
|
||
ide_vcs::changelists::ensure_ignored(&root.join(".openidea"), &["/workspace.json"])?;
|
||
}
|
||
Ok(())
|
||
}
|
||
|
||
fn refresh_workspace(project: &Project) {
|
||
project.settings.reload();
|
||
project.refresh_index_scope();
|
||
project.refresh_repositories();
|
||
project.sink.emit(ide_core::IdeEvent::ProjectRootsChanged { root: project.root.clone().into() });
|
||
}
|
||
|
||
/// Records `project` in `recent` (its branch, unless attached to a workspace, and display name).
|
||
pub fn record_recent(recent: &ide_workspace::RecentProjects, project: &Project) -> IdeResult<()> {
|
||
let info = info(project);
|
||
let attached = info.workspace.as_ref().is_some_and(|w| !w.is_container(&project.root));
|
||
let branch = if attached {
|
||
None
|
||
} else {
|
||
project.repos.read().primary().and_then(|r| r.branch_info().ok()).and_then(|b| b.head)
|
||
};
|
||
recent.touch(&project.root, branch)?;
|
||
recent.rename(&project.root, Some(&info.display_name))?;
|
||
Ok(())
|
||
}
|
||
|
||
/// File › Rename Project…: the display name of `window`'s project; an empty `name` restores the
|
||
/// folder name. A workspace container renames the workspace, else it is stored in project settings.
|
||
pub fn rename(host: &Host, window: &str, name: &str) -> IdeResult<Arc<Project>> {
|
||
let project = host.project(window)?;
|
||
let name = name.trim();
|
||
if let Some(workspace) = ide_workspace::workspace::Workspace::load(&project.root)?
|
||
&& workspace.is_container(&project.root)
|
||
{
|
||
save_workspace(host, window, name, workspace.projects)?;
|
||
} else {
|
||
let value = if name.is_empty() { serde_json::Value::Null } else { serde_json::Value::String(name.to_owned()) };
|
||
project.settings.set(SettingsScope::Project, "general.projectName", value)?;
|
||
}
|
||
Ok(project)
|
||
}
|
||
|
||
/// Attaches a trusted folder without replacing the current project.
|
||
pub fn attach_workspace(host: &Host, window: &str, path: &Path) -> IdeResult<ide_core::IpcPath> {
|
||
let project = host.project(window)?;
|
||
let path = dunce::canonicalize(path)?;
|
||
if project.light {
|
||
return Err(ide_core::IdeError::invalid("Open a project before attaching a folder"));
|
||
}
|
||
if path == project.root {
|
||
return Ok(project.root.clone().into());
|
||
}
|
||
require_attachment_trust(host, &path)?;
|
||
if let Some(mut workspace) = ide_workspace::workspace::Workspace::load(&project.root)? {
|
||
if !workspace.projects.contains(&path) {
|
||
workspace.projects.push(path);
|
||
save_workspace(host, window, &workspace.name, workspace.projects)?;
|
||
}
|
||
} else {
|
||
let workspace = ide_workspace::workspace::Workspace::attach(
|
||
&project.root,
|
||
&info(&project).name,
|
||
vec![project.root.clone(), path],
|
||
)?;
|
||
keep_attachment_private(&project.root, &workspace)?;
|
||
refresh_workspace(&project);
|
||
}
|
||
Ok(project.root.clone().into())
|
||
}
|
||
|
||
/// What [`set_settings`] changed; the caller tells the windows.
|
||
pub struct SettingsApplied {
|
||
pub settings: Settings,
|
||
/// A project value (else a global one).
|
||
pub project_scope: bool,
|
||
/// The project's root, when its content roots changed.
|
||
pub roots_changed: Option<ide_core::IpcPath>,
|
||
}
|
||
|
||
/// Sets `key` to `value` (JSON text, e.g. `14` or `"dark"`) for the window's
|
||
/// project or globally, and applies it to the open projects: file defaults,
|
||
/// file types, language servers, index scope, SSH configurations and the HTTP proxy
|
||
/// (whose password goes to the saved passwords, not the settings file).
|
||
pub fn set_settings(
|
||
host: &Host,
|
||
window: &str,
|
||
scope: SettingsScope,
|
||
key: &str,
|
||
value: &str,
|
||
) -> IdeResult<SettingsApplied> {
|
||
let value: serde_json::Value =
|
||
serde_json::from_str(value).map_err(|e| ide_core::IdeError::invalid(e.to_string()))?;
|
||
let current = host.project(window).ok();
|
||
// A LightEdit window has no project layer: its values are global.
|
||
let project_scope = matches!(scope, SettingsScope::Project) && current.as_ref().is_some_and(|p| !p.light);
|
||
let is_proxy = key == "proxy" || key.starts_with("proxy.");
|
||
let Some(mut value) = host.take_proxy_password(key, value)? else {
|
||
host.apply_proxy();
|
||
return Ok(SettingsApplied { settings: settings_get(host, window), project_scope, roots_changed: None });
|
||
};
|
||
// One canonical spelling per linked POM, including a project outside the opened root.
|
||
if project_scope
|
||
&& key == "languages.java.maven.linkedProjects"
|
||
&& let Some(project) = current.as_ref()
|
||
&& let Some(list) = value.as_array()
|
||
{
|
||
let poms: Vec<String> = list.iter().filter_map(|item| item.as_str().map(str::to_owned)).collect();
|
||
if poms.len() == list.len() {
|
||
value = serde_json::json!(ide_build::maven::normalize_linked_poms(&project.root, &poms));
|
||
}
|
||
}
|
||
let settings = match ¤t {
|
||
Some(p) if project_scope => p.settings.set(scope, key, value)?,
|
||
Some(p) => {
|
||
host.global_settings.set(SettingsScope::Global, key, value)?;
|
||
p.settings.reload()
|
||
}
|
||
None => host.global_settings.set(SettingsScope::Global, key, value)?,
|
||
};
|
||
if let Some(p) = ¤t {
|
||
p.documents.set_file_defaults(ide_workspace::FileDefaults::from_settings(&settings, Some(&p.root)));
|
||
}
|
||
// A global value reaches every other open project too.
|
||
if !project_scope {
|
||
for project in host.projects() {
|
||
if current.as_ref().is_some_and(|c| Arc::ptr_eq(c, &project)) {
|
||
continue;
|
||
}
|
||
let effective = project.settings.reload();
|
||
project
|
||
.documents
|
||
.set_file_defaults(ide_workspace::FileDefaults::from_settings(&effective, Some(&project.root)));
|
||
}
|
||
}
|
||
let affected = || if project_scope { current.iter().cloned().collect() } else { host.projects() };
|
||
if key == "editor" || key == "editor.encodings" || key == "editor.encodings.nativeToAscii" {
|
||
let affected = affected();
|
||
host.runtime.spawn_blocking(move || {
|
||
for project in affected {
|
||
project.documents.reload_properties();
|
||
}
|
||
});
|
||
}
|
||
// File type associations re-detect open documents (off the command thread).
|
||
if key == "files" || key.starts_with("files.fileType") {
|
||
let affected = affected();
|
||
host.runtime.spawn_blocking(move || {
|
||
for project in affected {
|
||
project.apply_file_types(&project.settings.effective());
|
||
}
|
||
});
|
||
}
|
||
// Directory Mappings and Enable Git integration change which repositories the project has.
|
||
if key == "vcs"
|
||
|| key == "vcs.mappings"
|
||
|| key.starts_with("vcs.mappings.")
|
||
|| key == "vcs.git"
|
||
|| key == "vcs.git.enabled"
|
||
{
|
||
let affected = affected();
|
||
host.runtime.spawn_blocking(move || {
|
||
for project in affected {
|
||
project.refresh_repositories();
|
||
}
|
||
});
|
||
}
|
||
if key == "ssh" || key.starts_with("ssh.") {
|
||
host.ssh.set_configs(host.global_settings.effective().ssh.configs);
|
||
}
|
||
if key == "languages" || key == "languages.java" || key.starts_with("languages.java.addedJdks") {
|
||
host.apply_added_jdks();
|
||
}
|
||
if key == "vcs" || key == "vcs.git" || key == "vcs.git.executable" {
|
||
host.apply_git_executable();
|
||
}
|
||
if key == "vcs" || key == "vcs.github" || key.starts_with("vcs.github.") {
|
||
let affected = affected();
|
||
host.runtime.spawn_blocking(move || {
|
||
for project in affected {
|
||
crate::github_auth::apply_to_project(&project);
|
||
}
|
||
});
|
||
}
|
||
if ["languages", "languages.swift", "languages.swift.xcode"].contains(&key) {
|
||
// An untrusted project keeps no Xcode of its own (see `xcode_env`).
|
||
for project in affected().into_iter().filter(|p| p.is_trusted()) {
|
||
host.runtime.spawn(async move { crate::xcode_env::apply_and_restart(&project).await });
|
||
}
|
||
}
|
||
// `flutter daemon` and DevTools run on the Flutter SDK; the next request starts DevTools again.
|
||
if ["languages", "languages.flutter", "languages.flutter.sdk"].contains(&key) {
|
||
for project in affected() {
|
||
project.flutter.sdk_changed();
|
||
project.devtools.stop();
|
||
}
|
||
}
|
||
if is_proxy {
|
||
host.apply_proxy();
|
||
}
|
||
if key == "agents" || key == "agents.mcpServers" || key.starts_with("agents.mcpServers.") {
|
||
for project in affected() {
|
||
project.agents.notify_mcp_servers_changed();
|
||
}
|
||
}
|
||
// A skill, memory, or agent-plugin policy change re-resolves the modes; an idle session restarts to pick them up.
|
||
if key == "agents"
|
||
|| key == "agents.skills"
|
||
|| key.starts_with("agents.skills.")
|
||
|| key == "agents.memory"
|
||
|| key.starts_with("agents.memory.")
|
||
|| key == "agents.plugins"
|
||
|| key.starts_with("agents.plugins.")
|
||
{
|
||
for project in affected() {
|
||
project.agents.notify_mcp_servers_changed();
|
||
}
|
||
}
|
||
// A new interpreter / toolchain / server executable restarts the language servers it affects.
|
||
// So do inspections that are compiler options (`ide-sdk` `configure_java_compiler`).
|
||
let code_style = key == "editor"
|
||
|| key == "editor.codeStyle"
|
||
|| key.starts_with("editor.codeStyle.")
|
||
|| key == "editor.inlay"
|
||
|| key.starts_with("editor.inlay.")
|
||
|| key == "inspections"
|
||
|| key.starts_with("inspections.")
|
||
|| key == "files"
|
||
|| key == "files.composeFileOverrides"
|
||
|| key.starts_with("files.composeFileOverrides.")
|
||
// JSON Schema Mappings reach the JSON and YAML servers as settings.
|
||
|| key == "jsonSchemas"
|
||
|| key.starts_with("jsonSchemas.");
|
||
let toolchain = ["languages", "tools", "languageServers", "projectStructure"]
|
||
.iter()
|
||
.any(|k| key == *k || key.starts_with(&format!("{k}.")));
|
||
// A run target chosen as the Python interpreter (or changed) needs a snapshot of its libraries.
|
||
if ["languages", "languages.python", "languages.python.interpreter", "runTargets"].contains(&key) {
|
||
for project in affected() {
|
||
crate::ops::sdk::container_python::ensure(host, &project);
|
||
}
|
||
}
|
||
// Code style only reaches servers as settings (e.g. jdtls' formatter profile); builds don't depend on it.
|
||
if code_style || toolchain {
|
||
for project in affected() {
|
||
if toolchain && let Some(bridge) = &project.kotlin_bridge {
|
||
bridge.schedule();
|
||
}
|
||
let lsp = project.lsp.clone();
|
||
host.runtime.spawn(async move { lsp.reconfigure().await });
|
||
}
|
||
}
|
||
let roots_changed = key == "projectStructure"
|
||
|| key.starts_with("projectStructure.")
|
||
|| "languages.java.maven.unlinkedProjects".starts_with(key)
|
||
|| "languages.java.maven.linkedProjects".starts_with(key)
|
||
|| "languages.java.gradle.linkedProjects".starts_with(key);
|
||
// Content roots and excludes (files.exclude, ignored names, excluded folders) reach the
|
||
// index and the watchers without reopening the project (the rescan runs in the background).
|
||
if roots_changed || key == "files" || key.starts_with("files.") {
|
||
let mut affected = affected();
|
||
// A workspace open in another window may hold this project: its excluded folders apply there.
|
||
if roots_changed
|
||
&& project_scope
|
||
&& let Some(own) = ¤t
|
||
{
|
||
affected.extend(host.projects().into_iter().filter(|p| p.member_excludes.read().contains_key(&own.root)));
|
||
}
|
||
host.runtime.spawn_blocking(move || {
|
||
for project in affected {
|
||
project.refresh_index_scope();
|
||
}
|
||
});
|
||
}
|
||
let roots_changed = current.as_ref().filter(|_| roots_changed && project_scope).map(|p| p.root.clone().into());
|
||
Ok(SettingsApplied { settings: host.with_proxy_password(settings), project_scope, roots_changed })
|
||
}
|
||
|
||
/// Reads the GitHub CLI (`gh`) keyring accounts and which account applies to `window`'s project.
|
||
#[command(trust = outside_restricted)]
|
||
pub async fn gh_project_account_status(
|
||
host: &Arc<Host>,
|
||
window: &str,
|
||
) -> IdeResult<crate::github_auth::GhProjectAccountStatus> {
|
||
host.require_trust_if_project(window)?;
|
||
let current = host.project(window).ok().filter(|p| !p.light);
|
||
let global_account = host.global_settings.effective().vcs.github.account;
|
||
host.blocking(move || match current {
|
||
Some(project) => Ok(crate::github_auth::project_status(&project)),
|
||
None => Ok(crate::github_auth::global_status(global_account)),
|
||
})
|
||
.await
|
||
}
|
||
|
||
/// Sets `vcs.github.account` for `window`'s project (or globally when no project is open),
|
||
/// updates the project's `GH_TOKEN` environment immediately, and returns the updated status.
|
||
#[command(trust = outside_restricted)]
|
||
pub async fn gh_set_project_account(
|
||
host: &Arc<Host>,
|
||
window: &str,
|
||
account: String,
|
||
) -> IdeResult<crate::github_auth::GhProjectAccountStatus> {
|
||
host.require_trust_if_project(window)?;
|
||
let trimmed = account.trim().to_owned();
|
||
if !trimmed.is_empty() && !crate::github_auth::is_valid_github_login(&trimmed) {
|
||
return Err(ide_core::IdeError::invalid(format!("invalid GitHub account login: {trimmed}")));
|
||
}
|
||
let current = host.project(window).ok().filter(|p| !p.light);
|
||
let scope = if current.is_some() { SettingsScope::Project } else { SettingsScope::Global };
|
||
let json = serde_json::to_string(&trimmed).map_err(|e| ide_core::IdeError::internal(e.to_string()))?;
|
||
set_settings(host, window, scope, "vcs.github.account", &json)?;
|
||
let sink = host.window_sink(window);
|
||
sink.emit(IdeEvent::SettingsChanged { key: "vcs.github.account".into() });
|
||
let global_account = host.global_settings.effective().vcs.github.account;
|
||
host.blocking(move || match current {
|
||
Some(project) => Ok(crate::github_auth::project_status(&project)),
|
||
None => Ok(crate::github_auth::global_status(global_account)),
|
||
})
|
||
.await
|
||
}
|
||
|
||
ide_command::domain!(
|
||
project:
|
||
cancel_request,
|
||
cancel_task,
|
||
close_project,
|
||
gh_project_account_status,
|
||
gh_set_project_account,
|
||
open_project,
|
||
project_current,
|
||
project_roots,
|
||
project_trust_list,
|
||
project_trust_remove_location,
|
||
project_trust_set,
|
||
project_trust_status,
|
||
project_workspace_member_set,
|
||
project_workspace_members,
|
||
remote_idle_timeout_minutes,
|
||
settings_get,
|
||
settings_get_global,
|
||
settings_removed_theme,
|
||
settings_set,
|
||
);
|