дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Порівняти коміти
17
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
08d87c3903 | ||
|
|
1652866769 | ||
|
|
be5a6f62ad | ||
|
|
f5e8d77dcf | ||
|
|
c3ea376899 | ||
|
|
fde075457b | ||
|
|
135723bca6 | ||
|
|
03a660354c | ||
|
|
1572fc36ea | ||
|
|
4f74f22624 | ||
|
|
1309ce10e4 | ||
|
|
49be259232 | ||
|
|
6a8016b888 | ||
|
|
b8f422d451 | ||
|
|
c868ec8b68 | ||
|
|
059a5193ff | ||
|
|
0f7008391c |
No files matched your search
Створено
+26
-26
@@ -3962,7 +3962,7 @@ checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "ide-analysis"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ast-grep-core",
|
||||
"ide-core",
|
||||
@@ -3976,7 +3976,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-build"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"dunce",
|
||||
@@ -3991,7 +3991,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-core"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"serde",
|
||||
@@ -4003,7 +4003,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-coverage"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-run",
|
||||
@@ -4017,7 +4017,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-dap"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-jsonrpc",
|
||||
@@ -4034,7 +4034,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-db"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"futures",
|
||||
@@ -4054,7 +4054,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-docker"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"libc",
|
||||
@@ -4067,7 +4067,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-github"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-vcs",
|
||||
@@ -4081,7 +4081,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-http"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"parking_lot",
|
||||
@@ -4099,7 +4099,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-index"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"criterion",
|
||||
@@ -4121,7 +4121,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-jsonrpc"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"ide-core",
|
||||
@@ -4136,7 +4136,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-language"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"criterion",
|
||||
@@ -4188,7 +4188,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-lsp"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"globset",
|
||||
@@ -4211,7 +4211,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-plugin"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-language",
|
||||
@@ -4229,7 +4229,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-profiler"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-run",
|
||||
@@ -4242,7 +4242,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-run"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"ide-core",
|
||||
@@ -4260,7 +4260,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-sdk"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"ide-core",
|
||||
@@ -4277,7 +4277,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-search"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"globset",
|
||||
@@ -4296,7 +4296,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-syntax"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-language",
|
||||
@@ -4311,7 +4311,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-terminal"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"libc",
|
||||
@@ -4324,7 +4324,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-text"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"ide-core",
|
||||
@@ -4336,7 +4336,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-tools"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"hex",
|
||||
@@ -4356,7 +4356,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-vcs"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"gix",
|
||||
@@ -4373,7 +4373,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-vfs"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"chardetng",
|
||||
"dunce",
|
||||
@@ -4393,7 +4393,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-workspace"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"dunce",
|
||||
@@ -5817,7 +5817,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "openidea"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"dunce",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "3"
|
||||
members = ["crates/*", "src-tauri"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
edition = "2024"
|
||||
rust-version = "1.96"
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -19,7 +19,7 @@ fn main() {
|
||||
eprintln!("synced in {:?}: {r:?}", started.elapsed());
|
||||
}
|
||||
let started = std::time::Instant::now();
|
||||
let model = ide_build::load(&root, &cache);
|
||||
let model = ide_build::load(&root, &cache, None);
|
||||
println!("{}", serde_json::to_string_pretty(&model).unwrap());
|
||||
eprintln!("loaded in {:?}", started.elapsed());
|
||||
}
|
||||
@@ -225,6 +225,7 @@ fn maven_steps(root: &Path, model: &BuildModel, kind: BuildKind, module: Option<
|
||||
}
|
||||
let step = |p: &maven::MavenProject, extra: &[String]| {
|
||||
let mut s = BuildStep::new(&p.command, &["-B", "-Dstyle.color=never"], &subdir(root, &p.dir), Format::Maven);
|
||||
s.args.extend(p.options.iter().cloned());
|
||||
s.args.extend(extra.iter().cloned());
|
||||
s.args.extend(goals.iter().map(|g| (*g).to_owned()));
|
||||
s.env = p.env.clone();
|
||||
@@ -671,7 +672,7 @@ mod tests {
|
||||
);
|
||||
write(&root, "core/pom.xml", "<project><artifactId>core</artifactId></project>");
|
||||
write(&root, "core/src/main/java/A.java", "class A {}");
|
||||
let model = crate::load(&root, &tmp.path().join("cache"));
|
||||
let model = crate::load(&root, &tmp.path().join("cache"), None);
|
||||
let p = plan(&root, &model, BuildKind::Build, None).unwrap();
|
||||
assert_eq!(p.system, BuildSystem::Maven);
|
||||
assert_eq!(p.title, "demo");
|
||||
@@ -685,7 +686,7 @@ mod tests {
|
||||
let g = tmp.path().join("g");
|
||||
write(&g, "settings.gradle", "include 'app'");
|
||||
write(&g, "app/build.gradle", "apply plugin: 'java'");
|
||||
let model = crate::load(&g, &tmp.path().join("cache2"));
|
||||
let model = crate::load(&g, &tmp.path().join("cache2"), None);
|
||||
let p = plan(&g, &model, BuildKind::Build, Some(&g.join("app/src/A.java"))).unwrap();
|
||||
assert_eq!(p.system, BuildSystem::Gradle);
|
||||
assert_eq!(p.steps[0].args, ["--console=plain", ":app:classes", ":app:testClasses"]);
|
||||
|
||||
@@ -18,7 +18,7 @@ pub use sync::{SyncOptions, SyncProgress, sync_gradle, sync_maven};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -36,9 +36,10 @@ pub struct BuildModel {
|
||||
}
|
||||
|
||||
/// Static model of the builds under `root`, merged with the sync results cached in `cache_dir`.
|
||||
pub fn load(root: &Path, cache_dir: &Path) -> BuildModel {
|
||||
/// Parent POMs are looked up in `maven_repo` (the configured local repository), else the default one.
|
||||
pub fn load(root: &Path, cache_dir: &Path, maven_repo: Option<PathBuf>) -> BuildModel {
|
||||
let maven = maven::is_maven_project(root).then(|| {
|
||||
let mut m = maven::load(root);
|
||||
let mut m = maven::load_with_repo(root, maven_repo.or_else(maven::default_local_repo));
|
||||
sync::apply_maven_cache(root, cache_dir, &mut m);
|
||||
m
|
||||
});
|
||||
@@ -68,10 +69,10 @@ mod tests {
|
||||
let cache = tmp.path().join("cache");
|
||||
let root = tmp.path().join("p");
|
||||
std::fs::create_dir_all(root.join("svc")).unwrap();
|
||||
assert_eq!(load(&root, &cache), BuildModel::default());
|
||||
assert_eq!(load(&root, &cache, None), BuildModel::default());
|
||||
std::fs::write(root.join("svc/pom.xml"), "<project><artifactId>svc</artifactId></project>").unwrap();
|
||||
std::fs::write(root.join("build.gradle"), "").unwrap();
|
||||
let m = load(&root, &cache);
|
||||
let m = load(&root, &cache, None);
|
||||
assert_eq!(m.maven.unwrap().projects[0].pom, "svc/pom.xml");
|
||||
assert_eq!(m.gradle.unwrap().projects[0].path, ":");
|
||||
assert!(affects_build(Path::new("a/pom.xml")) && affects_build(Path::new("settings.gradle.kts")));
|
||||
|
||||
@@ -92,6 +92,8 @@ pub struct MavenProject {
|
||||
pub java_version: Option<u32>,
|
||||
/// Maven launcher: the nearest `mvnw` up to the project root (absolute), else `mvn`.
|
||||
pub command: String,
|
||||
/// Options before the goals (`-s`, `-Dmaven.repo.local=`); filled in by the shell from settings.
|
||||
pub options: Vec<String>,
|
||||
/// Environment for runs (`JAVA_HOME` of the matching JDK); filled in by the shell.
|
||||
pub env: BTreeMap<String, String>,
|
||||
}
|
||||
@@ -410,7 +412,7 @@ struct Resolver {
|
||||
}
|
||||
|
||||
/// `~/.m2/repository`, or `<localRepository>` from `~/.m2/settings.xml`.
|
||||
fn default_local_repo() -> Option<PathBuf> {
|
||||
pub(crate) fn default_local_repo() -> Option<PathBuf> {
|
||||
let m2 = dirs::home_dir()?.join(".m2");
|
||||
if let Some(settings) = std::fs::read_to_string(m2.join("settings.xml")).ok().and_then(|t| xml::parse(&t))
|
||||
&& let Some(repo) = settings.text_of("localRepository")
|
||||
@@ -924,6 +926,7 @@ pub(crate) fn load_with_repo(root: &Path, local_repo: Option<PathBuf>) -> MavenM
|
||||
profiles: pom.profiles.iter().map(|p| p.id.clone()).collect(),
|
||||
java_version: jv,
|
||||
command: wrapper(root, &dir),
|
||||
options: Vec::new(),
|
||||
env: BTreeMap::new(),
|
||||
});
|
||||
for m in modules.into_iter().rev() {
|
||||
|
||||
@@ -29,6 +29,10 @@ pub struct SyncOptions {
|
||||
pub profiles: Vec<String>,
|
||||
/// Extra environment (`JAVA_HOME`).
|
||||
pub env: BTreeMap<String, String>,
|
||||
/// Maven launcher replacing the project's `mvnw` / `mvn` (Settings › Maven home).
|
||||
pub maven_command: Option<String>,
|
||||
/// Maven options before the goals (`-s`, `-Dmaven.repo.local=`).
|
||||
pub maven_options: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
@@ -184,6 +188,7 @@ pub fn sync_maven(
|
||||
let effective = cache_dir.join(format!("effective-pom-{n}.xml"));
|
||||
let _ = std::fs::remove_file(&effective);
|
||||
let mut args: Vec<String> = vec!["-B".into(), "-fae".into(), "-Dstyle.color=never".into()];
|
||||
args.extend(options.maven_options.iter().cloned());
|
||||
if options.offline {
|
||||
args.push("-o".into());
|
||||
}
|
||||
@@ -194,7 +199,8 @@ pub fn sync_maven(
|
||||
args.push(format!("-Doutput={}", effective.to_string_lossy()));
|
||||
args.push("dependency:tree".into());
|
||||
progress(SyncProgress { message: format!("Reading {}", top.display_name), fraction: None });
|
||||
let out = run(&top.command, &args, &root.join(&top.dir), &options.env, cancel, |line| {
|
||||
let command = options.maven_command.as_deref().unwrap_or(&top.command);
|
||||
let out = run(command, &args, &root.join(&top.dir), &options.env, cancel, |line| {
|
||||
if let Some((name, i, total)) = maven_building(line) {
|
||||
let fraction = (i.saturating_sub(1) as f32 / total.max(1) as f32).min(1.0);
|
||||
progress(SyncProgress { message: format!("Building model of {name}"), fraction: Some(fraction) });
|
||||
|
||||
@@ -37,6 +37,23 @@ pub struct Settings {
|
||||
pub terminal: TerminalSettings,
|
||||
pub actions_on_save: ActionsOnSaveSettings,
|
||||
pub external_tools: Vec<ExternalTool>,
|
||||
/// Language servers / debug adapters at a user-chosen location, by the
|
||||
/// command the language definition launches (`elixir-ls`, `codelldb`).
|
||||
pub tools: BTreeMap<String, ToolSettings>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct ToolSettings {
|
||||
/// Executable to launch instead of the managed / `PATH` one; empty = auto-detect.
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
/// The configured executable for `command`, if any (`~/` not yet expanded).
|
||||
pub fn tool_path(&self, command: &str) -> Option<&str> {
|
||||
self.tools.get(command).map(|t| t.path.trim()).filter(|p| !p.is_empty())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
@@ -59,6 +76,7 @@ impl Default for Settings {
|
||||
terminal: TerminalSettings::default(),
|
||||
actions_on_save: ActionsOnSaveSettings::default(),
|
||||
external_tools: Vec::new(),
|
||||
tools: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -401,9 +419,26 @@ pub struct GoSettings {
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, Type)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct JavaSettings {
|
||||
/// Project JDK home; empty = per module, the installed JDK matching the
|
||||
/// Java version it targets.
|
||||
pub jdk: String,
|
||||
/// Extra JVM options for the Java language server (jdtls), space-separated
|
||||
/// (VS Code's `java.jdt.ls.vmargs`).
|
||||
pub jdtls_vm_args: String,
|
||||
/// Build Tools › Maven.
|
||||
pub maven: MavenSettings,
|
||||
}
|
||||
|
||||
/// Build Tools › Maven.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, Type)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct MavenSettings {
|
||||
/// Maven home (or its `mvn` executable); empty = the project's `mvnw`, else `mvn` on `PATH`.
|
||||
pub home: String,
|
||||
/// User `settings.xml` (`-s`); empty = `~/.m2/settings.xml`.
|
||||
pub user_settings: String,
|
||||
/// Local repository (`-Dmaven.repo.local`); empty = from `settings.xml`.
|
||||
pub local_repository: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)]
|
||||
|
||||
@@ -522,6 +522,17 @@ impl DebugManager {
|
||||
/// waits for `initialized`, sends breakpoints, then `configurationDone`.
|
||||
/// Events of the session (including cargo build output) go to `owner` only.
|
||||
pub async fn start(&self, config: LaunchConfig, owner: SessionOwner) -> IdeResult<DebugSessionId> {
|
||||
self.start_with(config, owner, |_| None).await
|
||||
}
|
||||
|
||||
/// [`start`](Self::start) with the adapter executable chosen by `custom_command`
|
||||
/// (the configured command → a user-chosen executable, from settings).
|
||||
pub async fn start_with(
|
||||
&self,
|
||||
config: LaunchConfig,
|
||||
owner: SessionOwner,
|
||||
custom_command: impl FnOnce(&str) -> Option<String>,
|
||||
) -> IdeResult<DebugSessionId> {
|
||||
let mut arguments = launch_arguments(&config)?;
|
||||
let cwd = config
|
||||
.cwd
|
||||
@@ -531,6 +542,9 @@ impl DebugManager {
|
||||
let dbg = adapter::find_config(&self.languages, &config.adapter)
|
||||
.ok_or_else(|| IdeError::unavailable(format!("unknown debug adapter `{}`", config.adapter)))?;
|
||||
let mut spec = adapter::resolve(&dbg, cwd.clone());
|
||||
if let Some(command) = custom_command(&spec.command) {
|
||||
spec.command = command;
|
||||
}
|
||||
// debugpy: run the adapter with the debuggee's interpreter (venvs carry their own debugpy).
|
||||
if config.adapter == "debugpy" {
|
||||
let python = match arguments.get("python") {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
; GraphQL highlighting (the grammar crate ships no query). Later patterns win.
|
||||
|
||||
(comment) @comment
|
||||
(description (string_value) @comment.doc)
|
||||
(string_value) @string
|
||||
(int_value) @number
|
||||
(float_value) @number
|
||||
[(boolean_value) (null_value)] @keyword
|
||||
(enum_value (name) @constant)
|
||||
|
||||
(variable) @variable
|
||||
(argument (name) @variable.parameter)
|
||||
(input_value_definition (name) @variable.parameter)
|
||||
(object_field (name) @property)
|
||||
|
||||
(field (name) @property)
|
||||
(alias (name) @property)
|
||||
(field_definition (name) @property)
|
||||
(enum_value_definition (enum_value (name) @constant))
|
||||
|
||||
(named_type (name) @type)
|
||||
(object_type_definition (name) @type)
|
||||
(interface_type_definition (name) @type)
|
||||
(union_type_definition (name) @type)
|
||||
(enum_type_definition (name) @type)
|
||||
(input_object_type_definition (name) @type)
|
||||
(scalar_type_definition (name) @type)
|
||||
(object_type_extension (name) @type)
|
||||
(interface_type_extension (name) @type)
|
||||
(union_type_extension (name) @type)
|
||||
(enum_type_extension (name) @type)
|
||||
(input_object_type_extension (name) @type)
|
||||
(scalar_type_extension (name) @type)
|
||||
|
||||
(operation_definition (name) @function)
|
||||
(fragment_name (name) @function)
|
||||
(directive_definition (name) @attribute)
|
||||
(directive (name) @attribute)
|
||||
"@" @attribute
|
||||
(directive_location) @constant
|
||||
|
||||
(operation_type) @keyword
|
||||
[
|
||||
"query" "mutation" "subscription" "fragment" "on" "type" "interface" "union"
|
||||
"enum" "input" "scalar" "schema" "extend" "implements" "directive" "repeatable"
|
||||
] @keyword
|
||||
|
||||
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
||||
[":" "=" "|" "&" "!" "..."] @punctuation.delimiter
|
||||
@@ -0,0 +1,29 @@
|
||||
; HCL / Terraform highlighting (the grammar crate ships no query). Later patterns win.
|
||||
|
||||
(comment) @comment
|
||||
(string_lit) @string
|
||||
(quoted_template) @string
|
||||
(heredoc_template) @string
|
||||
[(heredoc_start) (heredoc_identifier)] @string.special
|
||||
(template_literal) @string
|
||||
(numeric_lit) @number
|
||||
[(bool_lit) (null_lit)] @keyword
|
||||
|
||||
(identifier) @variable
|
||||
(attribute (identifier) @property)
|
||||
(object_elem key: (expression (variable_expr (identifier) @property)))
|
||||
(get_attr (identifier) @property)
|
||||
(function_call (identifier) @function)
|
||||
; `resource "aws_instance" "web" {`
|
||||
(block (identifier) @keyword)
|
||||
(block (string_lit (template_literal) @type))
|
||||
|
||||
(template_interpolation) @embedded
|
||||
[(template_interpolation_start) (template_interpolation_end)] @punctuation.special
|
||||
[(template_directive_start) (template_directive_end) (strip_marker)] @punctuation.special
|
||||
["for" "in" "if" "else" "endfor" "endif"] @keyword
|
||||
|
||||
(operation) @operator
|
||||
["!" "!=" "%" "&&" "*" "+" "-" "/" "<" "<=" "==" ">" ">=" "||" "?" "=>"] @operator
|
||||
["=" ":" "," "."] @punctuation.delimiter
|
||||
["(" ")" "[" "]" "{" "}" "[*]" ".*"] @punctuation.bracket
|
||||
@@ -12,7 +12,10 @@ use std::collections::BTreeMap;
|
||||
mod registry;
|
||||
mod syntax;
|
||||
pub use registry::LanguageRegistry;
|
||||
pub use syntax::{MAX_CACHED_TREES, MAX_PARSE_BYTES, ParsedTree, Syntax, SyntaxCache, SyntaxCacheStats, TreeError};
|
||||
pub use syntax::{
|
||||
MAX_CACHED_TREES, MAX_PARSE_BYTES, ParsedTree, Syntax, SyntaxCache, SyntaxCacheStats, SyntaxHighlightKind,
|
||||
SyntaxHighlights, TreeError,
|
||||
};
|
||||
|
||||
/// Parsed form of `languages/<id>.toml`. Backend-only; the UI gets [`LanguageInfo`].
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
//! Structure / folding / Extend Selection on a large file cost an incremental
|
||||
//! parse instead of a full one.
|
||||
|
||||
use super::{Grammar, MAX_PARSE_BYTES, ParsedTree, Syntax, TreeError, folding, outline, parse_cancellable, selection};
|
||||
use super::{
|
||||
Grammar, MAX_PARSE_BYTES, ParsedTree, Syntax, SyntaxHighlights, TreeError, folding, highlight, outline,
|
||||
parse_cancellable, selection,
|
||||
};
|
||||
use crate::FoldRange;
|
||||
use ide_core::{DocId, LanguageId, OutlineItem, Range};
|
||||
use ide_text::ByteEdit;
|
||||
@@ -59,6 +62,7 @@ struct Memo {
|
||||
key: Option<(u32, LanguageId)>,
|
||||
outline: Option<Arc<Vec<OutlineItem>>>,
|
||||
folding: Option<Arc<Vec<FoldRange>>>,
|
||||
highlights: Option<Arc<Vec<u32>>>,
|
||||
}
|
||||
|
||||
impl Memo {
|
||||
@@ -211,6 +215,21 @@ impl SyntaxCache {
|
||||
)
|
||||
}
|
||||
|
||||
/// Highlighting from the grammar's own query; empty without one.
|
||||
pub fn highlights(&self, doc: DocId, lang: &LanguageId, version: u32, text: &str) -> SyntaxHighlights {
|
||||
SyntaxHighlights::new(self.memoized(
|
||||
doc,
|
||||
lang,
|
||||
version,
|
||||
|m| &mut m.highlights,
|
||||
|| {
|
||||
self.with_tree(doc, lang, version, text, |g, tree, text| {
|
||||
Some(highlight::highlights(g.highlight_query()?, tree, text))
|
||||
})
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
/// `compute()` once per document version; `None` (no grammar / query) is not memoized.
|
||||
fn memoized<T: Clone>(
|
||||
&self,
|
||||
|
||||
@@ -9,6 +9,8 @@ pub(crate) struct Spec {
|
||||
pub language: LanguageFn,
|
||||
/// `queries/<name>/outline.scm`; see `queries/README.md` for the capture vocabulary.
|
||||
pub outline: &'static str,
|
||||
/// The grammar's `highlights.scm`, for languages without a CodeMirror mode.
|
||||
pub highlights: Option<Highlights>,
|
||||
/// Node kinds folded when they span several lines (in addition to every
|
||||
/// bracket-delimited node, which is folded generically).
|
||||
pub fold_nodes: &'static [&'static str],
|
||||
@@ -20,6 +22,21 @@ pub(crate) struct Spec {
|
||||
pub constructors: &'static [&'static str],
|
||||
}
|
||||
|
||||
/// A highlights query and how its patterns rank against each other.
|
||||
pub(crate) struct Highlights {
|
||||
pub query: &'static str,
|
||||
/// For the same node, the first matching pattern wins (tree-sitter CLI /
|
||||
/// GitHub queries) instead of the last one (nvim / Zed queries).
|
||||
pub first_wins: bool,
|
||||
}
|
||||
|
||||
/// Our own `queries/<name>/highlights.scm`, for grammars that ship none.
|
||||
macro_rules! highlights {
|
||||
($name:literal) => {
|
||||
include_str!(concat!("../../queries/", $name, "/highlights.scm"))
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! outline {
|
||||
($name:literal) => {
|
||||
include_str!(concat!("../../queries/", $name, "/outline.scm"))
|
||||
@@ -33,6 +50,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "rust",
|
||||
language: tree_sitter_rust::LANGUAGE,
|
||||
outline: outline!("rust"),
|
||||
highlights: None,
|
||||
fold_nodes: NONE,
|
||||
fold_bodies: NONE,
|
||||
imports: &["use_declaration", "extern_crate_declaration"],
|
||||
@@ -42,6 +60,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "typescript",
|
||||
language: tree_sitter_typescript::LANGUAGE_TYPESCRIPT,
|
||||
outline: outline!("typescript"),
|
||||
highlights: None,
|
||||
fold_nodes: &["template_string"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["import_statement"],
|
||||
@@ -51,6 +70,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "tsx",
|
||||
language: tree_sitter_typescript::LANGUAGE_TSX,
|
||||
outline: outline!("typescript"),
|
||||
highlights: None,
|
||||
fold_nodes: &["template_string", "jsx_element"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["import_statement"],
|
||||
@@ -60,6 +80,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "javascript",
|
||||
language: tree_sitter_javascript::LANGUAGE,
|
||||
outline: outline!("javascript"),
|
||||
highlights: None,
|
||||
fold_nodes: &["template_string", "jsx_element"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["import_statement"],
|
||||
@@ -69,6 +90,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "python",
|
||||
language: tree_sitter_python::LANGUAGE,
|
||||
outline: outline!("python"),
|
||||
highlights: None,
|
||||
fold_nodes: &["string"],
|
||||
fold_bodies: &["block"],
|
||||
imports: &["import_statement", "import_from_statement", "future_import_statement"],
|
||||
@@ -78,6 +100,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "go",
|
||||
language: tree_sitter_go::LANGUAGE,
|
||||
outline: outline!("go"),
|
||||
highlights: None,
|
||||
fold_nodes: &["raw_string_literal"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["import_declaration"],
|
||||
@@ -87,6 +110,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "java",
|
||||
language: tree_sitter_java::LANGUAGE,
|
||||
outline: outline!("java"),
|
||||
highlights: None,
|
||||
fold_nodes: &["text_block"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["import_declaration"],
|
||||
@@ -96,6 +120,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "kotlin",
|
||||
language: tree_sitter_kotlin_ng::LANGUAGE,
|
||||
outline: outline!("kotlin"),
|
||||
highlights: None,
|
||||
fold_nodes: &["string_literal"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["import"],
|
||||
@@ -105,6 +130,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "scala",
|
||||
language: tree_sitter_scala::LANGUAGE,
|
||||
outline: outline!("scala"),
|
||||
highlights: None,
|
||||
fold_nodes: &["string"],
|
||||
fold_bodies: &["indented_block", "template_body"],
|
||||
imports: &["import_declaration"],
|
||||
@@ -114,6 +140,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "c",
|
||||
language: tree_sitter_c::LANGUAGE,
|
||||
outline: outline!("c"),
|
||||
highlights: None,
|
||||
fold_nodes: &["preproc_if", "preproc_ifdef", "preproc_function_def"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["preproc_include"],
|
||||
@@ -123,6 +150,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "cpp",
|
||||
language: tree_sitter_cpp::LANGUAGE,
|
||||
outline: outline!("cpp"),
|
||||
highlights: None,
|
||||
fold_nodes: &["preproc_if", "preproc_ifdef", "preproc_function_def", "raw_string_literal"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["preproc_include", "using_declaration"],
|
||||
@@ -132,6 +160,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "csharp",
|
||||
language: tree_sitter_c_sharp::LANGUAGE,
|
||||
outline: outline!("csharp"),
|
||||
highlights: None,
|
||||
fold_nodes: &["preproc_region", "raw_string_literal", "verbatim_string_literal"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["using_directive"],
|
||||
@@ -141,6 +170,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "swift",
|
||||
language: tree_sitter_swift::LANGUAGE,
|
||||
outline: outline!("swift"),
|
||||
highlights: None,
|
||||
// Control-flow statements hold `{ statements }` without a block node of their own.
|
||||
fold_nodes: &[
|
||||
"multi_line_string_literal",
|
||||
@@ -160,6 +190,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "ruby",
|
||||
language: tree_sitter_ruby::LANGUAGE,
|
||||
outline: outline!("ruby"),
|
||||
highlights: None,
|
||||
fold_nodes: &[
|
||||
"method",
|
||||
"singleton_method",
|
||||
@@ -185,6 +216,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "php",
|
||||
language: tree_sitter_php::LANGUAGE_PHP,
|
||||
outline: outline!("php"),
|
||||
highlights: None,
|
||||
fold_nodes: &["heredoc", "nowdoc"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["namespace_use_declaration"],
|
||||
@@ -194,6 +226,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "lua",
|
||||
language: tree_sitter_lua::LANGUAGE,
|
||||
outline: outline!("lua"),
|
||||
highlights: None,
|
||||
fold_nodes: &[
|
||||
"function_declaration",
|
||||
"function_definition",
|
||||
@@ -212,6 +245,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "dart",
|
||||
language: tree_sitter_dart::LANGUAGE,
|
||||
outline: outline!("dart"),
|
||||
highlights: None,
|
||||
fold_nodes: NONE,
|
||||
fold_bodies: NONE,
|
||||
imports: &["import_or_export", "library_name", "part_directive", "part_of_directive"],
|
||||
@@ -221,6 +255,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "zig",
|
||||
language: tree_sitter_zig::LANGUAGE,
|
||||
outline: outline!("zig"),
|
||||
highlights: Some(Highlights { query: tree_sitter_zig::HIGHLIGHTS_QUERY, first_wins: false }),
|
||||
fold_nodes: NONE,
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -230,6 +265,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "elixir",
|
||||
language: tree_sitter_elixir::LANGUAGE,
|
||||
outline: outline!("elixir"),
|
||||
highlights: Some(Highlights { query: tree_sitter_elixir::HIGHLIGHTS_QUERY, first_wins: false }),
|
||||
fold_nodes: &["do_block", "anonymous_function", "string", "sigil"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -239,6 +275,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "haskell",
|
||||
language: tree_sitter_haskell::LANGUAGE,
|
||||
outline: outline!("haskell"),
|
||||
highlights: None,
|
||||
// `bind`: equations without arguments (`main = do …`).
|
||||
fold_nodes: &["function", "bind", "data_type", "newtype", "class", "instance", "signature"],
|
||||
fold_bodies: NONE,
|
||||
@@ -249,6 +286,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "ocaml",
|
||||
language: tree_sitter_ocaml::LANGUAGE_OCAML,
|
||||
outline: outline!("ocaml"),
|
||||
highlights: None,
|
||||
fold_nodes: &[
|
||||
"value_definition",
|
||||
"type_definition",
|
||||
@@ -266,6 +304,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "ocaml_interface",
|
||||
language: tree_sitter_ocaml::LANGUAGE_OCAML_INTERFACE,
|
||||
outline: outline!("ocaml_interface"),
|
||||
highlights: None,
|
||||
fold_nodes: &["module_definition", "module_type_definition", "signature", "type_definition"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["open_module"],
|
||||
@@ -275,6 +314,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "bash",
|
||||
language: tree_sitter_bash::LANGUAGE,
|
||||
outline: outline!("bash"),
|
||||
highlights: None,
|
||||
fold_nodes: &["do_group", "if_statement", "case_statement", "heredoc_body"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -284,6 +324,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "html",
|
||||
language: tree_sitter_html::LANGUAGE,
|
||||
outline: outline!("html"),
|
||||
highlights: None,
|
||||
fold_nodes: &["element", "script_element", "style_element"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -293,6 +334,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "xml",
|
||||
language: tree_sitter_xml::LANGUAGE_XML,
|
||||
outline: outline!("xml"),
|
||||
highlights: None,
|
||||
fold_nodes: &["element", "CDSect"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -302,6 +344,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "css",
|
||||
language: tree_sitter_css::LANGUAGE,
|
||||
outline: outline!("css"),
|
||||
highlights: None,
|
||||
fold_nodes: NONE,
|
||||
fold_bodies: NONE,
|
||||
imports: &["import_statement"],
|
||||
@@ -311,6 +354,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "json",
|
||||
language: tree_sitter_json::LANGUAGE,
|
||||
outline: outline!("json"),
|
||||
highlights: None,
|
||||
fold_nodes: NONE,
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -320,6 +364,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "yaml",
|
||||
language: tree_sitter_yaml::LANGUAGE,
|
||||
outline: outline!("yaml"),
|
||||
highlights: None,
|
||||
fold_nodes: &["block_mapping_pair", "block_sequence_item", "block_scalar"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -329,6 +374,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "toml",
|
||||
language: tree_sitter_toml_ng::LANGUAGE,
|
||||
outline: outline!("toml"),
|
||||
highlights: None,
|
||||
fold_nodes: &["table", "table_array_element", "string"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -338,6 +384,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "markdown",
|
||||
language: tree_sitter_md::LANGUAGE,
|
||||
outline: outline!("markdown"),
|
||||
highlights: None,
|
||||
fold_nodes: &["section", "fenced_code_block", "list", "block_quote", "html_block"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -347,6 +394,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "hcl",
|
||||
language: tree_sitter_hcl::LANGUAGE,
|
||||
outline: outline!("hcl"),
|
||||
highlights: Some(Highlights { query: highlights!("hcl"), first_wins: false }),
|
||||
fold_nodes: &["block", "heredoc_template"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -356,6 +404,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "nix",
|
||||
language: tree_sitter_nix::LANGUAGE,
|
||||
outline: outline!("nix"),
|
||||
highlights: Some(Highlights { query: tree_sitter_nix::HIGHLIGHTS_QUERY, first_wins: true }),
|
||||
fold_nodes: &["let_expression", "indented_string_expression"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -365,6 +414,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "proto",
|
||||
language: tree_sitter_proto::LANGUAGE,
|
||||
outline: outline!("proto"),
|
||||
highlights: None,
|
||||
fold_nodes: NONE,
|
||||
fold_bodies: NONE,
|
||||
imports: &["import"],
|
||||
@@ -374,6 +424,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "graphql",
|
||||
language: tree_sitter_graphql::LANGUAGE,
|
||||
outline: outline!("graphql"),
|
||||
highlights: Some(Highlights { query: highlights!("graphql"), first_wins: false }),
|
||||
fold_nodes: NONE,
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
@@ -383,6 +434,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "make",
|
||||
language: tree_sitter_make::LANGUAGE,
|
||||
outline: outline!("make"),
|
||||
highlights: Some(Highlights { query: tree_sitter_make::HIGHLIGHTS_QUERY, first_wins: false }),
|
||||
fold_nodes: &["rule", "conditional", "define_directive"],
|
||||
fold_bodies: NONE,
|
||||
imports: &["include_directive"],
|
||||
@@ -392,6 +444,7 @@ pub(crate) static SPECS: &[Spec] = &[
|
||||
name: "cmake",
|
||||
language: tree_sitter_cmake::LANGUAGE,
|
||||
outline: outline!("cmake"),
|
||||
highlights: None,
|
||||
fold_nodes: &["function_def", "macro_def", "if_condition", "foreach_loop", "while_loop", "block_def"],
|
||||
fold_bodies: NONE,
|
||||
imports: NONE,
|
||||
|
||||
@@ -0,0 +1,483 @@
|
||||
//! Syntax highlighting from a grammar's own `highlights.scm`, for languages the
|
||||
//! UI has no CodeMirror mode for.
|
||||
//!
|
||||
//! Capture names follow the nvim-treesitter / Zed conventions (`@keyword`,
|
||||
//! `@string.special.symbol`, ...) and are folded into [`SyntaxHighlightKind`] by
|
||||
//! their longest known dotted prefix. Overlaps resolve the way those editors
|
||||
//! do: a smaller node wins over the node containing it, and for the same node
|
||||
//! the later pattern wins (the first one for tree-sitter CLI style queries). `@embedded` (string interpolation) clears the
|
||||
//! surrounding colour. Besides tree-sitter's own text predicates, nvim's
|
||||
//! `#lua-match?` is understood; patterns with other predicates never match.
|
||||
|
||||
use super::lines::LineIndex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
use tree_sitter::{Language, Query, QueryCursor, QueryMatch, QueryPredicateArg, StreamingIterator, Tree};
|
||||
|
||||
/// Highlight classes sent to the UI, which maps each onto a Lezer tag.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum SyntaxHighlightKind {
|
||||
Keyword,
|
||||
String,
|
||||
StringSpecial,
|
||||
Escape,
|
||||
Regexp,
|
||||
Atom,
|
||||
Number,
|
||||
Constant,
|
||||
Comment,
|
||||
DocComment,
|
||||
Function,
|
||||
FunctionCall,
|
||||
Builtin,
|
||||
Type,
|
||||
Namespace,
|
||||
Variable,
|
||||
SelfVariable,
|
||||
Property,
|
||||
Attribute,
|
||||
Macro,
|
||||
Label,
|
||||
Tag,
|
||||
Operator,
|
||||
Punctuation,
|
||||
}
|
||||
|
||||
impl SyntaxHighlightKind {
|
||||
/// Every kind, in `as u32` order: the legend for [`SyntaxHighlights::data`].
|
||||
pub const ALL: [Self; 24] = [
|
||||
Self::Keyword,
|
||||
Self::String,
|
||||
Self::StringSpecial,
|
||||
Self::Escape,
|
||||
Self::Regexp,
|
||||
Self::Atom,
|
||||
Self::Number,
|
||||
Self::Constant,
|
||||
Self::Comment,
|
||||
Self::DocComment,
|
||||
Self::Function,
|
||||
Self::FunctionCall,
|
||||
Self::Builtin,
|
||||
Self::Type,
|
||||
Self::Namespace,
|
||||
Self::Variable,
|
||||
Self::SelfVariable,
|
||||
Self::Property,
|
||||
Self::Attribute,
|
||||
Self::Macro,
|
||||
Self::Label,
|
||||
Self::Tag,
|
||||
Self::Operator,
|
||||
Self::Punctuation,
|
||||
];
|
||||
}
|
||||
|
||||
/// Highlighted ranges of a whole document, packed like LSP semantic tokens.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SyntaxHighlights {
|
||||
/// Legend: `data` kind `i` is `kinds[i]`.
|
||||
pub kinds: Vec<SyntaxHighlightKind>,
|
||||
/// `[from, to, kind]` triples: sorted, non-overlapping UTF-16 offsets.
|
||||
pub data: Vec<u32>,
|
||||
}
|
||||
|
||||
impl SyntaxHighlights {
|
||||
pub(crate) fn new(data: Vec<u32>) -> Self {
|
||||
Self { kinds: SyntaxHighlightKind::ALL.to_vec(), data }
|
||||
}
|
||||
}
|
||||
|
||||
/// What a capture paints over its node.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Paint {
|
||||
Kind(SyntaxHighlightKind),
|
||||
/// `@embedded`: code inside a string, uncoloured unless captured itself.
|
||||
Clear,
|
||||
}
|
||||
|
||||
/// Capture name prefixes, most specific first within each family.
|
||||
const CAPTURES: &[(&str, Paint)] = {
|
||||
use Paint::{Clear, Kind};
|
||||
use SyntaxHighlightKind as K;
|
||||
&[
|
||||
("embedded", Clear),
|
||||
("keyword", Kind(K::Keyword)),
|
||||
("include", Kind(K::Keyword)),
|
||||
("import", Kind(K::Keyword)),
|
||||
("conditional", Kind(K::Keyword)),
|
||||
("repeat", Kind(K::Keyword)),
|
||||
("exception", Kind(K::Keyword)),
|
||||
("boolean", Kind(K::Keyword)),
|
||||
("string.escape", Kind(K::Escape)),
|
||||
("escape", Kind(K::Escape)),
|
||||
("string.regex", Kind(K::Regexp)),
|
||||
("string.regexp", Kind(K::Regexp)),
|
||||
("string.special.symbol", Kind(K::Atom)),
|
||||
("symbol", Kind(K::Atom)),
|
||||
("string.special", Kind(K::StringSpecial)),
|
||||
("string", Kind(K::String)),
|
||||
("character", Kind(K::String)),
|
||||
("number", Kind(K::Number)),
|
||||
("float", Kind(K::Number)),
|
||||
("constant.builtin", Kind(K::Constant)),
|
||||
("constant.macro", Kind(K::Macro)),
|
||||
("constant", Kind(K::Constant)),
|
||||
// nvim greys out unused bindings (`_acc`); IDEA shows them as variables.
|
||||
("comment.unused", Kind(K::Variable)),
|
||||
("comment.doc", Kind(K::DocComment)),
|
||||
("comment.documentation", Kind(K::DocComment)),
|
||||
("comment", Kind(K::Comment)),
|
||||
("function.builtin", Kind(K::Builtin)),
|
||||
("function.macro", Kind(K::Macro)),
|
||||
("function.definition", Kind(K::Function)),
|
||||
("function", Kind(K::FunctionCall)),
|
||||
("method", Kind(K::FunctionCall)),
|
||||
("constructor", Kind(K::Type)),
|
||||
("type.builtin", Kind(K::Builtin)),
|
||||
("type", Kind(K::Type)),
|
||||
("module", Kind(K::Namespace)),
|
||||
("namespace", Kind(K::Namespace)),
|
||||
("variable.builtin", Kind(K::SelfVariable)),
|
||||
("variable.member", Kind(K::Property)),
|
||||
("variable.field", Kind(K::Property)),
|
||||
("variable", Kind(K::Variable)),
|
||||
("parameter", Kind(K::Variable)),
|
||||
("property", Kind(K::Property)),
|
||||
("field", Kind(K::Property)),
|
||||
("attribute", Kind(K::Attribute)),
|
||||
("label", Kind(K::Label)),
|
||||
("tag", Kind(K::Tag)),
|
||||
("operator", Kind(K::Operator)),
|
||||
("punctuation", Kind(K::Punctuation)),
|
||||
]
|
||||
};
|
||||
|
||||
/// The paint for a capture name: its longest prefix (on `.` boundaries) in
|
||||
/// [`CAPTURES`]. Private captures (`@__name__`) and unknown names paint nothing.
|
||||
fn paint_for(name: &str) -> Option<Paint> {
|
||||
if name.starts_with('_') {
|
||||
return None;
|
||||
}
|
||||
let mut prefix = name;
|
||||
loop {
|
||||
if let Some((_, p)) = CAPTURES.iter().find(|(n, _)| *n == prefix) {
|
||||
return Some(*p);
|
||||
}
|
||||
prefix = &prefix[..prefix.rfind('.')?];
|
||||
}
|
||||
}
|
||||
|
||||
/// A predicate tree-sitter leaves to the caller.
|
||||
enum Check {
|
||||
/// `#lua-match?` / `#not-lua-match?` on a capture's text.
|
||||
Matches {
|
||||
capture: u32,
|
||||
regex: regex_lite::Regex,
|
||||
negate: bool,
|
||||
},
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
pub(crate) struct HighlightQuery {
|
||||
query: Query,
|
||||
/// By capture index.
|
||||
paints: Vec<Option<Paint>>,
|
||||
/// By pattern index.
|
||||
checks: Vec<Vec<Check>>,
|
||||
first_wins: bool,
|
||||
}
|
||||
|
||||
impl HighlightQuery {
|
||||
pub(crate) fn new(language: &Language, source: &str, first_wins: bool) -> Result<Self, tree_sitter::QueryError> {
|
||||
let query = Query::new(language, source)?;
|
||||
let paints = query.capture_names().iter().map(|n| paint_for(n)).collect();
|
||||
let checks = (0..query.pattern_count())
|
||||
.map(|i| {
|
||||
query
|
||||
.general_predicates(i)
|
||||
.iter()
|
||||
.filter_map(|p| match (&*p.operator, &*p.args) {
|
||||
// Locals are not tracked: builtins are assumed not to be shadowed.
|
||||
("is-not?", [QueryPredicateArg::String(s)]) if &**s == "local" => None,
|
||||
(
|
||||
op @ ("lua-match?" | "not-lua-match?"),
|
||||
[QueryPredicateArg::Capture(c), QueryPredicateArg::String(pat)],
|
||||
) => Some(match regex_lite::Regex::new(&lua_pattern_to_regex(pat)) {
|
||||
Ok(regex) => Check::Matches { capture: *c, regex, negate: op.starts_with("not-") },
|
||||
Err(_) => Check::Unsupported,
|
||||
}),
|
||||
_ => Some(Check::Unsupported),
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
Ok(Self { query, paints, checks, first_wins })
|
||||
}
|
||||
|
||||
fn accepts(&self, m: &QueryMatch<'_, '_>, text: &str) -> bool {
|
||||
self.checks[m.pattern_index].iter().all(|check| match check {
|
||||
Check::Matches { capture, regex, negate } => m
|
||||
.captures
|
||||
.iter()
|
||||
.filter(|c| c.index == *capture)
|
||||
.all(|c| regex.is_match(&text[c.node.byte_range()]) != *negate),
|
||||
Check::Unsupported => false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Translates the Lua patterns used by nvim queries (`^[A-Z][A-Z_0-9]+$`, `^//!`) to regex syntax.
|
||||
fn lua_pattern_to_regex(pat: &str) -> String {
|
||||
let class = |c: char| match c {
|
||||
'a' => Some("A-Za-z"),
|
||||
'd' => Some("0-9"),
|
||||
'l' => Some("a-z"),
|
||||
'u' => Some("A-Z"),
|
||||
'w' => Some("A-Za-z0-9"),
|
||||
's' => Some("\\s"),
|
||||
'x' => Some("0-9A-Fa-f"),
|
||||
'p' => Some("[:punct:]"),
|
||||
_ => None,
|
||||
};
|
||||
let mut out = String::with_capacity(pat.len() + 8);
|
||||
let mut in_set = false;
|
||||
let mut chars = pat.chars();
|
||||
while let Some(c) = chars.next() {
|
||||
match c {
|
||||
'%' => {
|
||||
let Some(next) = chars.next() else { break };
|
||||
match class(next) {
|
||||
Some(set) if in_set => out.push_str(set),
|
||||
Some(set) => {
|
||||
out.push('[');
|
||||
out.push_str(set);
|
||||
out.push(']');
|
||||
}
|
||||
None => out.push_str(®ex_lite::escape(&next.to_string())),
|
||||
}
|
||||
}
|
||||
'[' if !in_set => {
|
||||
in_set = true;
|
||||
out.push(c);
|
||||
}
|
||||
']' if in_set => {
|
||||
in_set = false;
|
||||
out.push(c);
|
||||
}
|
||||
// Lua's lazy `*` (inside a set, `-` is a range).
|
||||
'-' if !in_set => out.push_str("*?"),
|
||||
'\\' | '{' | '}' | '|' => {
|
||||
out.push('\\');
|
||||
out.push(c);
|
||||
}
|
||||
_ => out.push(c),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Byte value for "no colour" in the paint buffer; kinds are `1 + index`.
|
||||
const NONE: u8 = 0;
|
||||
|
||||
/// `[from, to, kind]` UTF-16 triples for `text`; see [`SyntaxHighlights::data`].
|
||||
pub(crate) fn highlights(q: &HighlightQuery, tree: &Tree, text: &str) -> Vec<u32> {
|
||||
// (byte len, rank, start, end, paint): painted largest first, then by rank,
|
||||
// so inner nodes and winning patterns overwrite.
|
||||
let mut captures: Vec<(usize, usize, usize, usize, Paint)> = Vec::new();
|
||||
let mut cursor = QueryCursor::new();
|
||||
let mut matches = cursor.matches(&q.query, tree.root_node(), text.as_bytes());
|
||||
while let Some(m) = matches.next() {
|
||||
if !q.accepts(m, text) {
|
||||
continue;
|
||||
}
|
||||
for c in m.captures {
|
||||
if let Some(paint) = q.paints[c.index as usize] {
|
||||
let r = c.node.byte_range();
|
||||
if r.start < r.end {
|
||||
let rank = if q.first_wins { usize::MAX - m.pattern_index } else { m.pattern_index };
|
||||
captures.push((r.end - r.start, rank, r.start, r.end, paint));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
captures.sort_by(|a, b| b.0.cmp(&a.0).then(a.1.cmp(&b.1)));
|
||||
|
||||
let mut painted = vec![NONE; text.len()];
|
||||
for &(_, _, start, end, paint) in &captures {
|
||||
let v = match paint {
|
||||
Paint::Kind(k) => 1 + k as u8,
|
||||
Paint::Clear => NONE,
|
||||
};
|
||||
painted[start..end].fill(v);
|
||||
}
|
||||
|
||||
let lines = LineIndex::new(text);
|
||||
let mut data = Vec::new();
|
||||
let mut i = 0;
|
||||
while i < painted.len() {
|
||||
let v = painted[i];
|
||||
let start = i;
|
||||
while i < painted.len() && painted[i] == v {
|
||||
i += 1;
|
||||
}
|
||||
// Node boundaries are char boundaries; whitespace-only runs stay uncoloured.
|
||||
if v != NONE && text.is_char_boundary(start) && text.is_char_boundary(i) && !text[start..i].trim().is_empty() {
|
||||
data.extend([lines.utf16_at(start) as u32, lines.utf16_at(i) as u32, (v - 1) as u32]);
|
||||
}
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn capture_names_fold_to_the_longest_known_prefix() {
|
||||
use SyntaxHighlightKind as K;
|
||||
assert_eq!(paint_for("keyword.function"), Some(Paint::Kind(K::Keyword)));
|
||||
assert_eq!(paint_for("string.special.symbol"), Some(Paint::Kind(K::Atom)));
|
||||
assert_eq!(paint_for("string.special.path"), Some(Paint::Kind(K::StringSpecial)));
|
||||
assert_eq!(paint_for("comment.doc.__attribute__"), Some(Paint::Kind(K::DocComment)));
|
||||
assert_eq!(paint_for("punctuation.bracket"), Some(Paint::Kind(K::Punctuation)));
|
||||
assert_eq!(paint_for("embedded"), Some(Paint::Clear));
|
||||
assert_eq!(paint_for("__name__"), None);
|
||||
assert_eq!(paint_for("spell"), None);
|
||||
}
|
||||
|
||||
/// `(text, kind)` of every highlighted range.
|
||||
fn spans(lang: &str, text: &str) -> Vec<(String, SyntaxHighlightKind)> {
|
||||
let h = crate::Syntax::new().highlights(&ide_core::LanguageId::new(lang), text).unwrap();
|
||||
let units: Vec<u16> = text.encode_utf16().collect();
|
||||
h.data
|
||||
.chunks(3)
|
||||
.map(|t| (String::from_utf16(&units[t[0] as usize..t[1] as usize]).unwrap(), h.kinds[t[2] as usize]))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn highlights_elixir() {
|
||||
use SyntaxHighlightKind as K;
|
||||
let src = "defmodule Greeter do\n @moduledoc \"Hi\"\n # 😀 note\n def hello(name, _opts) do\n IO.puts(\"Hello #{name}\")\n :ok\n end\nend\n";
|
||||
let got = spans("elixir", src);
|
||||
let kind = |t: &str| got.iter().find(|(s, _)| s == t).map(|(_, k)| *k);
|
||||
assert_eq!(kind("defmodule"), Some(K::Keyword));
|
||||
assert_eq!(kind("Greeter"), Some(K::Namespace));
|
||||
assert_eq!(kind("\"Hi\""), Some(K::DocComment));
|
||||
assert_eq!(kind("# 😀 note"), Some(K::Comment));
|
||||
assert_eq!(kind("def"), Some(K::Keyword));
|
||||
assert_eq!(kind("hello"), Some(K::FunctionCall));
|
||||
assert_eq!(kind("_opts"), Some(K::Variable));
|
||||
assert_eq!(kind("puts"), Some(K::FunctionCall));
|
||||
// Interpolation clears the string colour; its contents are coloured on their own.
|
||||
assert_eq!(kind("\"Hello "), Some(K::String));
|
||||
assert_eq!(kind("#{"), Some(K::Punctuation));
|
||||
assert_eq!(kind(":ok"), Some(K::Atom));
|
||||
assert_eq!(kind("end"), Some(K::Keyword));
|
||||
// Sorted and non-overlapping.
|
||||
let h = crate::Syntax::new().highlights(&ide_core::LanguageId::new("elixir"), src).unwrap();
|
||||
assert!(h.data.chunks(3).zip(h.data.chunks(3).skip(1)).all(|(a, b)| a[0] < a[1] && a[1] <= b[0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn highlights_other_grammar_only_languages() {
|
||||
use SyntaxHighlightKind as K;
|
||||
type Expect<'a> = &'a [(&'a str, SyntaxHighlightKind)];
|
||||
let cases: &[(&str, &str, Expect)] = &[
|
||||
(
|
||||
"zig",
|
||||
"const std = @import(\"std\");\n// hi\npub fn main() void {\n var x: u32 = 42;\n _ = x;\n}\n",
|
||||
&[
|
||||
("const", K::Keyword),
|
||||
("\"std\"", K::String),
|
||||
("// hi", K::Comment),
|
||||
("42", K::Number),
|
||||
("u32", K::Builtin),
|
||||
],
|
||||
),
|
||||
(
|
||||
"nix",
|
||||
"{ pkgs ? import <nixpkgs> {} }:\n# hi\nlet x = 1; in pkgs.mkShell { name = \"dev\"; }\n",
|
||||
&[
|
||||
("let", K::Keyword),
|
||||
("# hi", K::Comment),
|
||||
("1", K::Number),
|
||||
("\"dev\"", K::String),
|
||||
("import", K::Builtin),
|
||||
],
|
||||
),
|
||||
(
|
||||
"graphql",
|
||||
"# hi\nquery Hero($id: ID!) @cached {\n hero(id: $id) { name ...Friends }\n}\nenum Episode { NEWHOPE }\n",
|
||||
&[
|
||||
("# hi", K::Comment),
|
||||
("query", K::Keyword),
|
||||
("Hero", K::FunctionCall),
|
||||
("$id", K::Variable),
|
||||
("ID", K::Type),
|
||||
("@cached", K::Attribute),
|
||||
("name", K::Property),
|
||||
("Friends", K::FunctionCall),
|
||||
("NEWHOPE", K::Constant),
|
||||
],
|
||||
),
|
||||
(
|
||||
"hcl",
|
||||
"# hi\nresource \"aws_instance\" \"web\" {\n ami = var.ami\n count = 2\n tags = { Name = \"web-${var.env}\" }\n name = upper(\"x\")\n}\n",
|
||||
&[
|
||||
("# hi", K::Comment),
|
||||
("resource", K::Keyword),
|
||||
("aws_instance", K::Type),
|
||||
("ami", K::Property),
|
||||
("2", K::Number),
|
||||
("upper", K::FunctionCall),
|
||||
("\"web-", K::String),
|
||||
("env", K::Property),
|
||||
("var", K::Variable),
|
||||
],
|
||||
),
|
||||
("make", "# hi\nCC := gcc\nall: main.o\n\t$(CC) -o app main.o\n", &[("# hi", K::Comment)]),
|
||||
];
|
||||
for (lang, src, expect) in cases {
|
||||
let got = spans(lang, src);
|
||||
for (text, kind) in *expect {
|
||||
assert!(got.iter().any(|(s, k)| s == text && k == kind), "{lang}: {text:?} as {kind:?} in {got:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn languages_without_a_query_have_none() {
|
||||
assert_eq!(crate::Syntax::new().highlights(&ide_core::LanguageId::new("rust"), "fn a() {}"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_highlights_query_compiles() {
|
||||
for spec in super::super::grammars::SPECS {
|
||||
if let Some(h) = &spec.highlights {
|
||||
let lang = Language::new(spec.language);
|
||||
if let Err(e) = HighlightQuery::new(&lang, h.query, h.first_wins) {
|
||||
panic!("{}: {e}", spec.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lua_patterns_translate() {
|
||||
assert_eq!(lua_pattern_to_regex("^[A-Z][A-Z_0-9]+$"), "^[A-Z][A-Z_0-9]+$");
|
||||
assert_eq!(lua_pattern_to_regex("^//!"), "^//!");
|
||||
assert_eq!(lua_pattern_to_regex("^%u[%w_]*$"), "^[A-Z][A-Za-z0-9_]*$");
|
||||
assert_eq!(lua_pattern_to_regex("a.-b%."), "a.*?b\\.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legend_matches_discriminants() {
|
||||
for (i, k) in SyntaxHighlightKind::ALL.iter().enumerate() {
|
||||
assert_eq!(*k as usize, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ impl<'a> LineIndex<'a> {
|
||||
}
|
||||
|
||||
/// UTF-16 offset of a char-boundary byte offset.
|
||||
fn utf16_at(&self, byte: usize) -> usize {
|
||||
pub(crate) fn utf16_at(&self, byte: usize) -> usize {
|
||||
if self.checkpoints.is_empty() {
|
||||
return byte;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//! Tree-sitter driven structure: outline, folding, symbol tags, selection ranges.
|
||||
//! Tree-sitter driven structure: outline, folding, symbol tags, selection ranges, highlighting.
|
||||
|
||||
mod cache;
|
||||
mod folding;
|
||||
mod grammars;
|
||||
mod highlight;
|
||||
pub(crate) mod lines;
|
||||
mod outline;
|
||||
mod selection;
|
||||
@@ -10,6 +11,7 @@ mod selection;
|
||||
use crate::{FoldRange, LanguageConfig, LanguageRegistry, SymbolTag};
|
||||
pub use cache::{MAX_CACHED_TREES, SyntaxCache, SyntaxCacheStats};
|
||||
use grammars::{SPECS, Spec};
|
||||
pub use highlight::{SyntaxHighlightKind, SyntaxHighlights};
|
||||
use ide_core::{LanguageId, OutlineItem, Range};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
@@ -31,6 +33,7 @@ pub(crate) struct Grammar {
|
||||
pub(crate) spec: &'static Spec,
|
||||
pub(crate) language: Language,
|
||||
outline: OnceLock<Option<outline::OutlineQuery>>,
|
||||
highlights: OnceLock<Option<highlight::HighlightQuery>>,
|
||||
kinds: OnceLock<folding::KindTable>,
|
||||
}
|
||||
|
||||
@@ -50,6 +53,17 @@ impl Grammar {
|
||||
})
|
||||
.as_ref()
|
||||
}
|
||||
|
||||
fn highlight_query(&self) -> Option<&highlight::HighlightQuery> {
|
||||
self.highlights
|
||||
.get_or_init(|| {
|
||||
let h = self.spec.highlights.as_ref()?;
|
||||
highlight::HighlightQuery::new(&self.language, h.query, h.first_wins)
|
||||
.inspect_err(|e| tracing::error!("highlights query for {} is invalid: {e}", self.spec.name))
|
||||
.ok()
|
||||
})
|
||||
.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
@@ -72,6 +86,7 @@ impl Syntax {
|
||||
spec,
|
||||
language: Language::new(spec.language),
|
||||
outline: OnceLock::new(),
|
||||
highlights: OnceLock::new(),
|
||||
kinds: OnceLock::new(),
|
||||
})
|
||||
.collect();
|
||||
@@ -150,6 +165,13 @@ impl Syntax {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Highlighting from the grammar's own query; `None` without one.
|
||||
pub fn highlights(&self, lang: &LanguageId, text: &str) -> Option<SyntaxHighlights> {
|
||||
self.analyze(lang, text, |g, tree, text| {
|
||||
Some(SyntaxHighlights::new(highlight::highlights(g.highlight_query()?, tree, text)))
|
||||
})
|
||||
}
|
||||
|
||||
/// Syntax-aware selection ranges for IDEA "Extend Selection" (⌥↑), innermost first.
|
||||
pub fn selection_ranges(&self, lang: &LanguageId, text: &str, offset_utf16: u32) -> Vec<Range> {
|
||||
match self.analyze(lang, text, |_, tree, text| Some(selection::selection_ranges(tree, text, offset_utf16))) {
|
||||
|
||||
@@ -16,7 +16,7 @@ fn non_empty(s: &str) -> Option<&str> {
|
||||
}
|
||||
|
||||
/// Resolves `~/` and project-relative paths of a setting.
|
||||
fn setting_path(root: &Path, s: &str) -> Option<PathBuf> {
|
||||
pub fn setting_path(root: &Path, s: &str) -> Option<PathBuf> {
|
||||
let s = non_empty(s)?;
|
||||
let p = match s.strip_prefix("~/") {
|
||||
Some(rest) => crate::home_dir()?.join(rest),
|
||||
@@ -56,6 +56,55 @@ fn goroot(root: &Path, s: &Settings) -> Option<PathBuf> {
|
||||
setting_path(root, &s.languages.go.goroot)
|
||||
}
|
||||
|
||||
/// The project JDK (`languages.java.jdk`): a JDK home, its `bin` or its `bin/java`.
|
||||
pub fn project_jdk(root: &Path, s: &Settings) -> Option<crate::java::Jdk> {
|
||||
let p = setting_path(root, &s.languages.java.jdk)?;
|
||||
let jdk = p.ancestors().take(3).find_map(crate::java::jdk_at);
|
||||
if jdk.is_none() {
|
||||
tracing::warn!("project JDK {} is not a JDK home", p.display());
|
||||
}
|
||||
jdk
|
||||
}
|
||||
|
||||
/// `mvn` of the configured Maven home (`languages.java.maven.home`): the
|
||||
/// executable itself, `<home>/bin/mvn` or `<bin>/mvn`.
|
||||
pub fn maven_command(root: &Path, s: &Settings) -> Option<PathBuf> {
|
||||
let p = setting_path(root, &s.languages.java.maven.home)?;
|
||||
let name = if cfg!(windows) { "mvn.cmd" } else { "mvn" };
|
||||
let found = [p.clone(), p.join("bin").join(name), p.join(name)].into_iter().find(|c| c.is_file());
|
||||
if found.is_none() {
|
||||
tracing::warn!("Maven home {} has no {name}", p.display());
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
/// Maven options from settings, placed before the goals: `-s <settings.xml>`
|
||||
/// and `-Dmaven.repo.local=<dir>`.
|
||||
pub fn maven_options(root: &Path, s: &Settings) -> Vec<String> {
|
||||
let m = &s.languages.java.maven;
|
||||
let mut out = Vec::new();
|
||||
if let Some(file) = setting_path(root, &m.user_settings) {
|
||||
out.extend(["-s".to_owned(), file.to_string_lossy().into_owned()]);
|
||||
}
|
||||
if let Some(dir) = setting_path(root, &m.local_repository) {
|
||||
out.push(format!("-Dmaven.repo.local={}", dir.to_string_lossy()));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The Maven local repository from settings: the configured one, else
|
||||
/// `<localRepository>` of the configured user `settings.xml`; `None` = Maven's default.
|
||||
pub fn maven_local_repository(root: &Path, s: &Settings) -> Option<PathBuf> {
|
||||
let m = &s.languages.java.maven;
|
||||
setting_path(root, &m.local_repository).or_else(|| {
|
||||
let text = std::fs::read_to_string(setting_path(root, &m.user_settings)?).ok()?;
|
||||
let repo = crate::java::xml_value(&crate::lombok::strip_xml_comments(&text), "localRepository")?;
|
||||
let home = crate::home_dir().map(|h| h.to_string_lossy().into_owned()).unwrap_or_default();
|
||||
let repo = repo.replace("${user.home}", &home);
|
||||
(!repo.is_empty() && !repo.contains("${")).then(|| PathBuf::from(repo))
|
||||
})
|
||||
}
|
||||
|
||||
/// TypeScript `lib` directory for the selected version; `None` = the server's bundled one.
|
||||
pub fn tsdk(root: &Path, s: &Settings) -> Option<PathBuf> {
|
||||
match s.languages.typescript.version.trim() {
|
||||
@@ -104,6 +153,9 @@ pub(crate) fn merge_init_options(cfg: &mut LanguageServerConfig, layer: Value) {
|
||||
/// server settings (`python.pythonPath`, rust-analyzer `check.command`, `typescript.tsdk`).
|
||||
/// `root` is the project root, `server_root` the server's workspace root.
|
||||
pub fn configure_server(cfg: &mut LanguageServerConfig, root: &Path, server_root: &Path, s: &Settings) {
|
||||
if let Some(custom) = s.tool_path(&cfg.command).and_then(|p| setting_path(root, p)) {
|
||||
cfg.command = custom.to_string_lossy().into_owned();
|
||||
}
|
||||
let mut path_dirs: Vec<PathBuf> = Vec::new();
|
||||
let name = cfg.name.clone();
|
||||
let name = name.as_str();
|
||||
@@ -170,6 +222,14 @@ pub fn configure_server(cfg: &mut LanguageServerConfig, root: &Path, server_root
|
||||
// The jdtls launcher forwards `--jvm-arg=` values to the JVM it starts.
|
||||
let args = s.languages.java.jdtls_vm_args.split_whitespace().map(|a| format!("--jvm-arg={a}"));
|
||||
cfg.args.extend(args);
|
||||
// m2e (the Maven import) reads mirrors, servers and `<localRepository>` from it.
|
||||
if let Some(file) = setting_path(root, &s.languages.java.maven.user_settings) {
|
||||
let file = file.to_string_lossy();
|
||||
merge_init_options(
|
||||
cfg,
|
||||
json!({ "settings": { "java": { "configuration": { "maven": { "userSettings": file } } } } }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(lib) = tsdk(server_root, s).or_else(|| tsdk(root, s)) {
|
||||
@@ -206,7 +266,8 @@ const PY_RUNNERS: [&str; 3] = ["uv", "poetry", "pdm"];
|
||||
|
||||
/// Points run configurations at the selected toolchains: Python configs use the
|
||||
/// project interpreter, npm scripts the chosen package manager and Node.js,
|
||||
/// cargo / go configs the selected toolchain.
|
||||
/// cargo / go configs the selected toolchain, Maven / Gradle the project JDK
|
||||
/// (and Maven the configured home and options).
|
||||
pub fn apply_to_run_configs(configs: &mut [RunConfig], root: &Path, s: &Settings) {
|
||||
let explicit_python = setting_path(root, &s.languages.python.interpreter);
|
||||
let python = python_interpreter(root, s);
|
||||
@@ -215,6 +276,9 @@ pub fn apply_to_run_configs(configs: &mut [RunConfig], root: &Path, s: &Settings
|
||||
let rust = rust_bin(root, s);
|
||||
let go = goroot(root, s);
|
||||
let gopath = setting_path(root, &s.languages.go.gopath);
|
||||
let jdk = project_jdk(root, s);
|
||||
let mvn = maven_command(root, s);
|
||||
let mvn_options = maven_options(root, s);
|
||||
|
||||
for c in configs.iter_mut() {
|
||||
let mut path_dirs: Vec<PathBuf> = Vec::new();
|
||||
@@ -281,6 +345,19 @@ pub fn apply_to_run_configs(configs: &mut [RunConfig], root: &Path, s: &Settings
|
||||
c.env.entry("GOPATH".into()).or_insert_with(|| gopath.to_string_lossy().into_owned());
|
||||
}
|
||||
}
|
||||
"maven" | "gradle" => {
|
||||
if let Some(jdk) = &jdk {
|
||||
c.env.entry("JAVA_HOME".into()).or_insert_with(|| jdk.home.to_string_lossy().into_owned());
|
||||
}
|
||||
if c.kind == "maven" && c.detected {
|
||||
if let Some(mvn) = &mvn {
|
||||
c.command = mvn.to_string_lossy().into_owned();
|
||||
}
|
||||
if !c.args.starts_with(&mvn_options) {
|
||||
c.args.splice(0..0, mvn_options.iter().cloned());
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if !path_dirs.is_empty() && !c.env.contains_key("PATH") {
|
||||
|
||||
@@ -18,6 +18,8 @@ pub fn detect(kind: SdkKind, root: Option<&Path>) -> Vec<Sdk> {
|
||||
SdkKind::Rust => rust(),
|
||||
SdkKind::Go => go(),
|
||||
SdkKind::TypeScript => typescript(root),
|
||||
SdkKind::Jdk => jdk(),
|
||||
SdkKind::Maven => maven(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,3 +384,108 @@ fn typescript(root: Option<&Path>) -> Vec<Sdk> {
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ jdk
|
||||
|
||||
/// `KEY="value"` of a JDK `release` file.
|
||||
fn release_value(release: &str, key: &str) -> Option<String> {
|
||||
let line = release.lines().find_map(|l| l.trim().strip_prefix(key)?.strip_prefix('='))?;
|
||||
Some(line.trim().trim_matches('"').to_owned()).filter(|v| !v.is_empty())
|
||||
}
|
||||
|
||||
fn jdk() -> Vec<Sdk> {
|
||||
let java_home = std::env::var_os("JAVA_HOME").and_then(|h| dunce::canonicalize(h).ok());
|
||||
crate::java::rescan_jdks()
|
||||
.iter()
|
||||
.map(|j| {
|
||||
let release = std::fs::read_to_string(j.home.join("release")).unwrap_or_default();
|
||||
let version = release_value(&release, "JAVA_VERSION").unwrap_or_else(|| j.major.to_string());
|
||||
let name = match release_value(&release, "IMPLEMENTOR") {
|
||||
Some(vendor) => format!("{vendor} {version}"),
|
||||
None => format!("JDK {version}"),
|
||||
};
|
||||
let source = if java_home.as_ref() == Some(&j.home) { "JAVA_HOME" } else { "system" };
|
||||
Sdk {
|
||||
path: j.home.clone().into(),
|
||||
name,
|
||||
version: Some(version),
|
||||
source: source.to_owned(),
|
||||
home: Some(j.home.clone().into()),
|
||||
extra: None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ maven
|
||||
|
||||
/// Maven version from `lib/maven-core-<version>.jar`.
|
||||
fn maven_version(home: &Path) -> Option<String> {
|
||||
std::fs::read_dir(home.join("lib")).ok()?.flatten().find_map(|e| {
|
||||
let name = e.file_name().to_string_lossy().into_owned();
|
||||
Some(name.strip_prefix("maven-core-")?.strip_suffix(".jar")?.to_owned())
|
||||
})
|
||||
}
|
||||
|
||||
/// A Maven home (`bin/mvn` and `lib/`); Homebrew's formula keeps it in `libexec`.
|
||||
fn maven_home(dir: &Path) -> Option<PathBuf> {
|
||||
let mvn = if cfg!(windows) { "mvn.cmd" } else { "mvn" };
|
||||
[dir.join("libexec"), dir.to_path_buf()]
|
||||
.into_iter()
|
||||
.find(|h| h.join("bin").join(mvn).is_file() && h.join("lib").is_dir())
|
||||
}
|
||||
|
||||
fn maven() -> Vec<Sdk> {
|
||||
let mut found: Vec<(PathBuf, &'static str)> = Vec::new();
|
||||
// Windows' Maven ships `mvn.cmd` only (`which` looks for `mvn.exe`).
|
||||
let on_path = if cfg!(windows) {
|
||||
std::env::split_paths(&search_path()).map(|d| d.join("mvn.cmd")).find(|p| p.is_file())
|
||||
} else {
|
||||
which("mvn")
|
||||
};
|
||||
if let Some(mvn) = on_path.and_then(|p| dunce::canonicalize(p).ok())
|
||||
&& let Some(home) = mvn.parent().and_then(Path::parent)
|
||||
{
|
||||
found.push((home.to_path_buf(), "path"));
|
||||
}
|
||||
for var in ["MAVEN_HOME", "M2_HOME"] {
|
||||
if let Some(h) = std::env::var_os(var) {
|
||||
found.push((PathBuf::from(h), "env"));
|
||||
}
|
||||
}
|
||||
for p in ["/opt/homebrew/opt/maven", "/usr/local/opt/maven", "/usr/share/maven", "/opt/maven"] {
|
||||
found.push((PathBuf::from(p), "system"));
|
||||
}
|
||||
if let Some(home) = home_dir() {
|
||||
for d in subdirs(&home.join(".sdkman/candidates/maven")) {
|
||||
found.push((d, "sdkman"));
|
||||
}
|
||||
// Distributions the Maven wrapper downloaded: `dists/apache-maven-3.9.6-bin/<hash>/apache-maven-3.9.6`,
|
||||
// or since wrapper 3.3 the home itself, `dists/apache-maven-3.9.6/<hash>`.
|
||||
for dist in subdirs(&home.join(".m2/wrapper/dists")) {
|
||||
for hash in subdirs(&dist) {
|
||||
found.extend(subdirs(&hash).into_iter().map(|d| (d, "wrapper")));
|
||||
found.push((hash, "wrapper"));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut seen = HashSet::new();
|
||||
let mut out = Vec::new();
|
||||
for (dir, source) in found {
|
||||
let Some(home) = maven_home(&dir) else { continue };
|
||||
let home = dunce::canonicalize(&home).unwrap_or(home);
|
||||
if !seen.insert(home.clone()) {
|
||||
continue;
|
||||
}
|
||||
let version = maven_version(&home);
|
||||
out.push(Sdk {
|
||||
path: home.clone().into(),
|
||||
name: format!("Maven {}", version.clone().unwrap_or_default()).trim().to_owned(),
|
||||
version,
|
||||
source: source.to_owned(),
|
||||
home: Some(home.into()),
|
||||
extra: None,
|
||||
});
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -25,7 +25,8 @@ pub fn parse_release(release: &str) -> Option<u32> {
|
||||
if first == 1 { parts.next()?.parse().ok() } else { Some(first) }
|
||||
}
|
||||
|
||||
fn jdk_at(home: &Path) -> Option<Jdk> {
|
||||
/// The JDK at `home`, if it is one (a `release` file and `bin/java`).
|
||||
pub fn jdk_at(home: &Path) -> Option<Jdk> {
|
||||
let release = std::fs::read_to_string(home.join("release")).ok()?;
|
||||
if !home.join("bin").join(crate::exe("java")).is_file() {
|
||||
return None;
|
||||
@@ -117,6 +118,11 @@ fn rescan(slot: &mut Option<Scan>) -> Arc<[Jdk]> {
|
||||
slot.insert(Scan { at: Instant::now(), jdks: scan().into() }).jdks.clone()
|
||||
}
|
||||
|
||||
/// Scans for installed JDKs again (Settings › Detect again).
|
||||
pub fn rescan_jdks() -> Arc<[Jdk]> {
|
||||
rescan(&mut JDKS.lock().unwrap_or_else(|e| e.into_inner()))
|
||||
}
|
||||
|
||||
/// Installed JDKs (scanned on first use; [`jdtls_jdks`] may refresh them).
|
||||
pub fn installed_jdks() -> Arc<[Jdk]> {
|
||||
let mut slot = JDKS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
@@ -258,12 +264,15 @@ const METADATA_PROPERTY: &str = "java.import.generatesMetadataFilesAtProjectRoot
|
||||
/// directory, one per server root, and no Eclipse metadata is written into
|
||||
/// the project; it runs on a JDK `min_java`+ (via `JAVA_HOME`, which its
|
||||
/// launcher reads), installed JDKs are registered as runtimes and `bundles`
|
||||
/// (e.g. the java-debug plugin jar) are loaded into the server.
|
||||
/// (e.g. the java-debug plugin jar) are loaded into the server. The project
|
||||
/// JDK, when set, is the default runtime and preferred for running the server.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn configure_jdtls(
|
||||
cfg: &mut LanguageServerConfig,
|
||||
server_root: &Path,
|
||||
data_dir: &Path,
|
||||
jdks: &[Jdk],
|
||||
project_jdk: Option<&Jdk>,
|
||||
min_java: u32,
|
||||
bundles: &[PathBuf],
|
||||
lombok: Option<&Path>,
|
||||
@@ -294,6 +303,9 @@ pub fn configure_jdtls(
|
||||
{
|
||||
cfg.args.push(format!("--jvm-arg=-javaagent:{}", jar.to_string_lossy()));
|
||||
}
|
||||
let jdks: Vec<Jdk> =
|
||||
project_jdk.into_iter().chain(jdks.iter().filter(|j| Some(*j) != project_jdk)).cloned().collect();
|
||||
let jdks = jdks.as_slice();
|
||||
if !cfg.env.contains_key("JAVA_HOME") {
|
||||
match jdtls_runtime(jdks, min_java) {
|
||||
Some(jdk) => {
|
||||
@@ -302,7 +314,15 @@ pub fn configure_jdtls(
|
||||
None => cfg.launch_error = Some(missing_runtime_message(jdks, min_java)),
|
||||
}
|
||||
}
|
||||
let runtimes = runtimes(jdks);
|
||||
let mut runtimes = runtimes(jdks);
|
||||
if let Some(project) = project_jdk {
|
||||
let home = project.home.to_string_lossy();
|
||||
for r in &mut runtimes {
|
||||
if r["path"] == *home {
|
||||
r["default"] = json!(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !runtimes.is_empty() {
|
||||
merge_init_options(cfg, json!({ "settings": { "java": { "configuration": { "runtimes": runtimes } } } }));
|
||||
}
|
||||
@@ -424,7 +444,16 @@ mod tests {
|
||||
Jdk { major: 8, home: PathBuf::from("/jdk8") },
|
||||
];
|
||||
let bundles = [PathBuf::from("/tools/java-debug/bin/com.microsoft.java.debug.plugin.jar")];
|
||||
configure_jdtls(&mut cfg, Path::new("/p/demo"), Path::new("/data"), &jdks, JDTLS_MIN_JAVA, &bundles, None);
|
||||
configure_jdtls(
|
||||
&mut cfg,
|
||||
Path::new("/p/demo"),
|
||||
Path::new("/data"),
|
||||
&jdks,
|
||||
None,
|
||||
JDTLS_MIN_JAVA,
|
||||
&bundles,
|
||||
None,
|
||||
);
|
||||
assert_eq!(cfg.args[0], "-data");
|
||||
assert!(cfg.args[1].starts_with("/data/lsp/jdtls/"), "{}", cfg.args[1]);
|
||||
assert_eq!(cfg.args[2], "--jvm-arg=-Djava.import.generatesMetadataFilesAtProjectRoot=false");
|
||||
@@ -439,11 +468,38 @@ mod tests {
|
||||
|
||||
// Deterministic (reconfigure compares configs) and idempotent.
|
||||
let before = cfg.clone();
|
||||
configure_jdtls(&mut cfg, Path::new("/p/demo"), Path::new("/data"), &jdks, JDTLS_MIN_JAVA, &bundles, None);
|
||||
configure_jdtls(
|
||||
&mut cfg,
|
||||
Path::new("/p/demo"),
|
||||
Path::new("/data"),
|
||||
&jdks,
|
||||
None,
|
||||
JDTLS_MIN_JAVA,
|
||||
&bundles,
|
||||
None,
|
||||
);
|
||||
assert_eq!(cfg, before);
|
||||
|
||||
// The project JDK is the default runtime, and runs the server when new enough.
|
||||
let project = Jdk { major: 21, home: PathBuf::from("/jdk21b") };
|
||||
let mut cfg: LanguageServerConfig = toml::from_str("name = \"jdtls\"\ncommand = \"jdtls\"").unwrap();
|
||||
configure_jdtls(
|
||||
&mut cfg,
|
||||
Path::new("/p"),
|
||||
Path::new("/data"),
|
||||
&jdks,
|
||||
Some(&project),
|
||||
JDTLS_MIN_JAVA,
|
||||
&[],
|
||||
None,
|
||||
);
|
||||
let opts = serde_json::to_value(cfg.initialization_options.clone().unwrap()).unwrap();
|
||||
let rt = &opts["settings"]["java"]["configuration"]["runtimes"];
|
||||
assert_eq!(rt[1], json!({ "name": "JavaSE-21", "path": "/jdk21b", "default": true }));
|
||||
assert_eq!(cfg.env["JAVA_HOME"], "/jdk21b");
|
||||
|
||||
let mut other: LanguageServerConfig = toml::from_str("name = \"pyright\"\ncommand = \"x\"").unwrap();
|
||||
configure_jdtls(&mut other, Path::new("/p"), Path::new("/data"), &jdks, JDTLS_MIN_JAVA, &bundles, None);
|
||||
configure_jdtls(&mut other, Path::new("/p"), Path::new("/data"), &jdks, None, JDTLS_MIN_JAVA, &bundles, None);
|
||||
assert!(other.args.is_empty() && other.initialization_options.is_none());
|
||||
}
|
||||
|
||||
@@ -452,23 +508,23 @@ mod tests {
|
||||
let jdtls = || -> LanguageServerConfig { toml::from_str("name = \"jdtls\"\ncommand = \"jdtls\"").unwrap() };
|
||||
let jar = Path::new("/m2/lombok-1.18.48.jar");
|
||||
let mut cfg = jdtls();
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &[], JDTLS_MIN_JAVA, &[], Some(jar));
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &[], None, JDTLS_MIN_JAVA, &[], Some(jar));
|
||||
let agent = format!("--jvm-arg=-javaagent:{}", jar.to_string_lossy());
|
||||
assert!(cfg.args.contains(&agent), "{:?}", cfg.args);
|
||||
let mut plain = jdtls();
|
||||
configure_jdtls(&mut plain, Path::new("/p"), Path::new("/data"), &[], JDTLS_MIN_JAVA, &[], None);
|
||||
configure_jdtls(&mut plain, Path::new("/p"), Path::new("/data"), &[], None, JDTLS_MIN_JAVA, &[], None);
|
||||
assert_ne!(cfg.args[1], plain.args[1], "a separate workspace, so everything is rebuilt with the agent");
|
||||
let before = cfg.clone();
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &[], JDTLS_MIN_JAVA, &[], Some(jar));
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &[], None, JDTLS_MIN_JAVA, &[], Some(jar));
|
||||
assert_eq!(cfg, before, "idempotent");
|
||||
|
||||
let mut cfg = jdtls();
|
||||
cfg.args.push("--jvm-arg=-javaagent:/own/lombok.jar".into());
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &[], JDTLS_MIN_JAVA, &[], Some(jar));
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &[], None, JDTLS_MIN_JAVA, &[], Some(jar));
|
||||
assert!(!cfg.args.contains(&agent), "the user's agent wins");
|
||||
let mut own = jdtls();
|
||||
own.args.push("--jvm-arg=-javaagent:/own/lombok.jar".into());
|
||||
configure_jdtls(&mut own, Path::new("/p"), Path::new("/data"), &[], JDTLS_MIN_JAVA, &[], None);
|
||||
configure_jdtls(&mut own, Path::new("/p"), Path::new("/data"), &[], None, JDTLS_MIN_JAVA, &[], None);
|
||||
assert_eq!(cfg.args, own.args, "its workspace follows the agent in use");
|
||||
}
|
||||
|
||||
@@ -477,19 +533,19 @@ mod tests {
|
||||
let jdtls = || -> LanguageServerConfig { toml::from_str("name = \"jdtls\"\ncommand = \"jdtls\"").unwrap() };
|
||||
let old = [Jdk { major: 17, home: PathBuf::from("/jdk17") }, Jdk { major: 8, home: PathBuf::from("/jdk8") }];
|
||||
let mut cfg = jdtls();
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &old, JDTLS_MIN_JAVA, &[], None);
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &old, None, JDTLS_MIN_JAVA, &[], None);
|
||||
assert!(!cfg.env.contains_key("JAVA_HOME"));
|
||||
let err = cfg.launch_error.unwrap();
|
||||
assert!(err.contains("JDK 21 or newer") && err.contains("found JDK 8, 17"), "{err}");
|
||||
|
||||
let mut cfg = jdtls();
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &[], JDTLS_MIN_JAVA, &[], None);
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &[], None, JDTLS_MIN_JAVA, &[], None);
|
||||
assert!(cfg.launch_error.unwrap().contains("no JDK was found"));
|
||||
|
||||
// An explicit JAVA_HOME is the user's call.
|
||||
let mut cfg = jdtls();
|
||||
cfg.env.insert("JAVA_HOME".into(), "/custom".into());
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &old, JDTLS_MIN_JAVA, &[], None);
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &old, None, JDTLS_MIN_JAVA, &[], None);
|
||||
assert_eq!((cfg.env["JAVA_HOME"].as_str(), cfg.launch_error), ("/custom", None));
|
||||
|
||||
let mixed = [old[0].clone(), Jdk { major: 21, home: PathBuf::from("/jdk21") }];
|
||||
@@ -497,7 +553,7 @@ mod tests {
|
||||
|
||||
// A jdtls whose bundles need 25 doesn't start on 21, and says what it needs.
|
||||
let mut cfg = jdtls();
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &mixed, 25, &[], None);
|
||||
configure_jdtls(&mut cfg, Path::new("/p"), Path::new("/data"), &mixed, None, 25, &[], None);
|
||||
let err = cfg.launch_error.unwrap();
|
||||
assert!(err.contains("JDK 25 or newer") && err.contains("found JDK 17, 21"), "{err}");
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ pub enum SdkKind {
|
||||
Rust,
|
||||
Go,
|
||||
TypeScript,
|
||||
/// JDK homes.
|
||||
Jdk,
|
||||
/// Maven homes.
|
||||
Maven,
|
||||
}
|
||||
|
||||
/// One installed interpreter / toolchain.
|
||||
|
||||
@@ -64,8 +64,14 @@ pub fn agent_in_args<'a>(args: impl IntoIterator<Item = &'a str>) -> Option<Path
|
||||
}
|
||||
|
||||
/// The Lombok agent for the project at `root`: the user's own (`own`, from the JVM
|
||||
/// options) wins, then `managed` (the IDE-installed jar), then the build caches.
|
||||
pub fn lombok_agent(root: &Path, own: Option<PathBuf>, managed: Option<PathBuf>) -> LombokAgent {
|
||||
/// options) wins, then `managed` (the IDE-installed jar), then the build caches
|
||||
/// (`maven_repo`, the configured Maven local repository, else the default one).
|
||||
pub fn lombok_agent(
|
||||
root: &Path,
|
||||
own: Option<PathBuf>,
|
||||
managed: Option<PathBuf>,
|
||||
maven_repo: Option<PathBuf>,
|
||||
) -> LombokAgent {
|
||||
if let Some(jar) = own {
|
||||
let version = jar
|
||||
.file_stem()
|
||||
@@ -82,7 +88,7 @@ pub fn lombok_agent(root: &Path, own: Option<PathBuf>, managed: Option<PathBuf>)
|
||||
}
|
||||
let home = home_dir();
|
||||
let mut dirs = Vec::new();
|
||||
if let Some(repo) = maven_repository(home.as_deref()) {
|
||||
if let Some(repo) = maven_repo.or_else(|| maven_repository(home.as_deref())) {
|
||||
dirs.push(repo.join("org").join("projectlombok").join("lombok"));
|
||||
}
|
||||
if let Some(gradle) =
|
||||
@@ -137,7 +143,7 @@ fn maven_repository(home: Option<&Path>) -> Option<PathBuf> {
|
||||
Some(custom.unwrap_or_else(|| m2.join("repository")))
|
||||
}
|
||||
|
||||
fn strip_xml_comments(text: &str) -> String {
|
||||
pub(crate) fn strip_xml_comments(text: &str) -> String {
|
||||
let mut out = String::with_capacity(text.len());
|
||||
let mut rest = text;
|
||||
while let Some(i) = rest.find("<!--") {
|
||||
@@ -249,10 +255,10 @@ mod tests {
|
||||
let own = agent_in_args(["--jvm-arg=-Xmx2g", "--jvm-arg=-javaagent:/opt/lombok-1.18.26.jar"]);
|
||||
assert_eq!(own.as_deref(), Some(Path::new("/opt/lombok-1.18.26.jar")));
|
||||
assert_eq!(agent_in_args(["-javaagent:/opt/other.jar"]), None);
|
||||
let agent = lombok_agent(tmp.path(), own, Some("/managed/lombok.jar".into()));
|
||||
let agent = lombok_agent(tmp.path(), own, Some("/managed/lombok.jar".into()), None);
|
||||
assert_eq!(agent.jar(), Some(Path::new("/opt/lombok-1.18.26.jar")));
|
||||
assert!(agent.outdated(), "its version is read from the file name");
|
||||
let plain = lombok_agent(tmp.path(), agent_in_args(["-javaagent:/opt/lombok.jar"]), None);
|
||||
let plain = lombok_agent(tmp.path(), agent_in_args(["-javaagent:/opt/lombok.jar"]), None, None);
|
||||
assert_eq!(plain.problem(), None, "a user agent is never reported missing");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::apply::{apply_to_run_configs, configure_server, python_interpreter, terminal_activation, tsdk};
|
||||
use crate::apply::{
|
||||
apply_to_run_configs, configure_server, maven_command, maven_options, project_jdk, python_interpreter,
|
||||
terminal_activation, tsdk,
|
||||
};
|
||||
use crate::python::parse_pip_list;
|
||||
use crate::{bin_dir, exe, venv_of};
|
||||
use ide_core::settings::Settings;
|
||||
@@ -153,6 +156,52 @@ fn run_configs_use_selected_interpreter_and_package_manager() {
|
||||
assert_eq!(configs[4].command, "python3", "shell configs are left alone");
|
||||
}
|
||||
|
||||
fn fake_jdk(dir: &Path) {
|
||||
std::fs::create_dir_all(dir.join("bin")).unwrap();
|
||||
std::fs::write(dir.join("bin").join(exe("java")), "").unwrap();
|
||||
std::fs::write(dir.join("release"), "JAVA_VERSION=\"17.0.9\"\n").unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_jdk_and_maven_settings() {
|
||||
if cfg!(windows) {
|
||||
return; // Unix paths and shells
|
||||
}
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let jdk = tmp.path().join("jdk17");
|
||||
fake_jdk(&jdk);
|
||||
let maven = tmp.path().join("maven");
|
||||
std::fs::create_dir_all(maven.join("bin")).unwrap();
|
||||
std::fs::write(maven.join("bin/mvn"), "").unwrap();
|
||||
|
||||
let mut s = Settings::default();
|
||||
assert_eq!(project_jdk(tmp.path(), &s), None);
|
||||
assert_eq!(maven_command(tmp.path(), &s), None);
|
||||
assert!(maven_options(tmp.path(), &s).is_empty());
|
||||
|
||||
// Project-relative paths, a JDK's `bin/java`, a Maven home.
|
||||
s.languages.java.jdk = "jdk17/bin/java".into();
|
||||
s.languages.java.maven.home = maven.to_string_lossy().into_owned();
|
||||
s.languages.java.maven.user_settings = "/m2/settings.xml".into();
|
||||
s.languages.java.maven.local_repository = "/m2/repo".into();
|
||||
assert_eq!(project_jdk(tmp.path(), &s).map(|j| j.major), Some(17));
|
||||
assert_eq!(maven_command(tmp.path(), &s), Some(maven.join("bin/mvn")));
|
||||
assert_eq!(maven_options(tmp.path(), &s), ["-s", "/m2/settings.xml", "-Dmaven.repo.local=/m2/repo"]);
|
||||
|
||||
let mut configs = vec![run("maven", "./mvnw", &["package"]), run("gradle", "./gradlew", &["build"])];
|
||||
apply_to_run_configs(&mut configs, tmp.path(), &s);
|
||||
let home = project_jdk(tmp.path(), &s).unwrap().home.to_string_lossy().into_owned();
|
||||
assert_eq!(configs[0].command, maven.join("bin/mvn").to_string_lossy());
|
||||
assert_eq!(configs[0].args, ["-s", "/m2/settings.xml", "-Dmaven.repo.local=/m2/repo", "package"]);
|
||||
assert_eq!(configs[0].env["JAVA_HOME"], home);
|
||||
assert_eq!(configs[1].env["JAVA_HOME"], home);
|
||||
apply_to_run_configs(&mut configs, tmp.path(), &s);
|
||||
assert_eq!(configs[0].args.len(), 4, "applied once");
|
||||
|
||||
s.languages.java.jdk = "missing".into();
|
||||
assert_eq!(project_jdk(tmp.path(), &s), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn terminal_activation_for_project_venv() {
|
||||
if cfg!(windows) {
|
||||
@@ -206,3 +255,18 @@ fn detect_on_this_machine() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_tool_path_replaces_the_command() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let mut s = Settings::default();
|
||||
s.tools.insert("elixir-ls".into(), ide_core::settings::ToolSettings { path: "tools/ls/language_server.sh".into() });
|
||||
s.tools.insert("zls".into(), ide_core::settings::ToolSettings { path: " ".into() });
|
||||
let mut cfg = server("elixir-ls");
|
||||
configure_server(&mut cfg, tmp.path(), tmp.path(), &s);
|
||||
assert_eq!(Path::new(&cfg.command), tmp.path().join("tools/ls/language_server.sh"));
|
||||
// A blank path keeps auto-detection.
|
||||
let mut cfg = server("zls");
|
||||
configure_server(&mut cfg, tmp.path(), tmp.path(), &s);
|
||||
assert_eq!(cfg.command, "zls");
|
||||
}
|
||||
@@ -177,6 +177,27 @@ pub fn locate(root: &Path, names: &[String]) -> Option<PathBuf> {
|
||||
|
||||
/// Creates `bin_dir/<command>` that runs `target`: a shell wrapper on Unix
|
||||
/// (keeps the target's own directory layout intact), a `.cmd` shim on Windows.
|
||||
/// Like [`link_executable`], with `env` set for `target`.
|
||||
pub fn env_wrapper(bin_dir: &Path, command: &str, target: &Path, env: &[(&str, &Path)]) -> IdeResult<PathBuf> {
|
||||
fs::create_dir_all(bin_dir)?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let quote = |p: &Path| format!("'{}'", p.to_string_lossy().replace('\'', r"'\''"));
|
||||
let vars: String = env.iter().map(|(k, v)| format!("{k}={} ", quote(v))).collect();
|
||||
let link = bin_dir.join(command);
|
||||
fs::write(&link, format!("#!/bin/sh\n{vars}exec {} \"$@\"\n", quote(target)))?;
|
||||
make_executable(&link)?;
|
||||
Ok(link)
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
let link = bin_dir.join(format!("{command}.cmd"));
|
||||
let vars: String = env.iter().map(|(k, v)| format!("set \"{k}={}\"\r\n", v.display())).collect();
|
||||
fs::write(&link, format!("@echo off\r\nsetlocal\r\n{vars}\"{}\" %*\r\n", target.display()))?;
|
||||
Ok(link)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn link_executable(bin_dir: &Path, command: &str, target: &Path) -> IdeResult<PathBuf> {
|
||||
fs::create_dir_all(bin_dir)?;
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -39,6 +39,8 @@ pub enum ToolStatus {
|
||||
Installed,
|
||||
/// Found on the system `PATH`.
|
||||
OnPath,
|
||||
/// The executable chosen in settings.
|
||||
Custom,
|
||||
Missing,
|
||||
}
|
||||
|
||||
@@ -66,6 +68,8 @@ pub struct ToolInfo {
|
||||
/// Manual install instructions from the language definition.
|
||||
pub install_hint: Option<String>,
|
||||
pub homepage: Option<String>,
|
||||
/// Why the executable chosen in settings cannot be used (status is then `Missing`).
|
||||
pub custom_error: Option<String>,
|
||||
}
|
||||
|
||||
/// Streamed install progress.
|
||||
@@ -116,7 +120,9 @@ fn bin_dirs_in(root: &Path, platform: Platform) -> Vec<PathBuf> {
|
||||
fn managed_bin_dir(root: &Path, spec: &ToolSpec, platform: Platform) -> Option<PathBuf> {
|
||||
match spec.method {
|
||||
Method::Npm { .. } => Some(root.join("node_modules").join(".bin")),
|
||||
Method::Go { .. } | Method::Release { .. } => Some(root.join(spec.name).join("bin")),
|
||||
Method::Go { .. } | Method::Gem { .. } | Method::DotnetTool { .. } | Method::Release { .. } => {
|
||||
Some(root.join(spec.name).join("bin"))
|
||||
}
|
||||
Method::PipVenv { .. } => {
|
||||
Some(root.join(spec.name).join("venv").join(if platform.os == Os::Windows { "Scripts" } else { "bin" }))
|
||||
}
|
||||
@@ -212,8 +218,15 @@ fn usages(langs: &[LanguageConfig]) -> BTreeMap<String, Usage> {
|
||||
for s in &l.language_servers {
|
||||
add(&s.name, &s.command, ToolKind::LanguageServer, s.install_hint.as_ref(), &l.name);
|
||||
}
|
||||
}
|
||||
let servers: HashSet<&str> = langs.iter().flat_map(|l| &l.language_servers).map(|s| s.name.as_str()).collect();
|
||||
for l in langs {
|
||||
if let Some(d) = &l.debugger {
|
||||
add(&d.adapter, &d.command, ToolKind::Debugger, d.install_hint.as_ref(), &l.name);
|
||||
// An adapter named like a server but launched differently (ElixirLS's
|
||||
// `elixir-ls-debugger`) is a tool of its own, listed by its command.
|
||||
let name =
|
||||
if servers.contains(d.adapter.as_str()) && d.command != d.adapter { &d.command } else { &d.adapter };
|
||||
add(name, &d.command, ToolKind::Debugger, d.install_hint.as_ref(), &l.name);
|
||||
}
|
||||
}
|
||||
for (plugin, host) in registry::PLUGIN_HOSTS {
|
||||
@@ -260,6 +273,8 @@ pub struct Tools {
|
||||
/// `PATH` handed to installer child processes.
|
||||
child_path: OsString,
|
||||
platform: Platform,
|
||||
/// Executables chosen in settings, by command.
|
||||
custom: BTreeMap<String, PathBuf>,
|
||||
}
|
||||
|
||||
impl Tools {
|
||||
@@ -273,7 +288,13 @@ impl Tools {
|
||||
let system: Vec<PathBuf> = std::env::split_paths(&search_path).filter(|d| !ours.contains(d)).collect();
|
||||
let system_path = std::env::join_paths(&system).unwrap_or_default();
|
||||
let child_path = std::env::join_paths(ours.iter().chain(system.iter())).unwrap_or_default();
|
||||
Self { root, system_path, child_path, platform }
|
||||
Self { root, system_path, child_path, platform, custom: BTreeMap::new() }
|
||||
}
|
||||
|
||||
/// Reports the executables chosen in settings (command → path) as the tools' location.
|
||||
pub fn with_custom_paths(mut self, custom: BTreeMap<String, PathBuf>) -> Self {
|
||||
self.custom = custom;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn root(&self) -> &Path {
|
||||
@@ -343,6 +364,12 @@ impl Tools {
|
||||
|
||||
/// Requirement check for installing `spec` right now.
|
||||
fn unavailable_reason(&self, spec: &ToolSpec) -> Option<String> {
|
||||
self.installer_missing(spec)
|
||||
.or_else(|| spec.needs.iter().find(|(cmd, _)| self.which(cmd).is_none()).map(|(_, why)| why.to_string()))
|
||||
}
|
||||
|
||||
/// What the install method itself lacks (npm, a build for this platform, …).
|
||||
fn installer_missing(&self, spec: &ToolSpec) -> Option<String> {
|
||||
let need = |ok: bool, msg: &str| (!ok).then(|| msg.to_string());
|
||||
match spec.method {
|
||||
Method::Rustup { .. } => need(self.which("rustup").is_some(), "rustup is required (https://rustup.rs)"),
|
||||
@@ -351,6 +378,10 @@ impl Tools {
|
||||
"npm or pnpm is required: install Node.js (https://nodejs.org)",
|
||||
),
|
||||
Method::Go { .. } => need(self.which("go").is_some(), "Go is required (https://go.dev/dl)"),
|
||||
Method::Gem { .. } => need(self.which("gem").is_some(), "Ruby is required (https://www.ruby-lang.org)"),
|
||||
Method::DotnetTool { .. } => {
|
||||
need(self.which("dotnet").is_some(), ".NET SDK is required (https://dotnet.microsoft.com/download)")
|
||||
}
|
||||
Method::PipVenv { .. } => need(
|
||||
self.which("uv").is_some() || self.python().is_some(),
|
||||
"Python 3 or uv is required (https://www.python.org)",
|
||||
@@ -394,7 +425,9 @@ impl Tools {
|
||||
can_uninstall: false,
|
||||
install_hint,
|
||||
homepage: None,
|
||||
});
|
||||
custom_error: None,
|
||||
})
|
||||
.map(|info| self.apply_custom(info, None));
|
||||
};
|
||||
let (status, path, version) = self.detect(spec);
|
||||
let unavailable_reason = self.unavailable_reason(spec);
|
||||
@@ -414,7 +447,34 @@ impl Tools {
|
||||
can_uninstall,
|
||||
install_hint,
|
||||
homepage: Some(spec.homepage.to_string()),
|
||||
custom_error: None,
|
||||
})
|
||||
.map(|info| self.apply_custom(info, Some(spec)))
|
||||
}
|
||||
|
||||
/// Overrides the detected location with the executable chosen in settings.
|
||||
fn apply_custom(&self, mut info: ToolInfo, spec: Option<&ToolSpec>) -> ToolInfo {
|
||||
let Some(path) = self.custom.get(&info.command) else { return info };
|
||||
if !path.is_file() {
|
||||
info.status = ToolStatus::Missing;
|
||||
info.custom_error = Some(format!("{} does not exist", path.display()));
|
||||
info.path = None;
|
||||
info.version = None;
|
||||
return info;
|
||||
}
|
||||
info.version = spec.and_then(|spec| {
|
||||
let (cmd, args) = spec.version?;
|
||||
// The version command is the tool itself, whatever the chosen file is called.
|
||||
let program =
|
||||
if cmd == spec.commands[0] { path.clone() } else { path.parent().and_then(|d| self.exe_in(d, cmd))? };
|
||||
let mut c = self.command(program);
|
||||
c.args(args);
|
||||
let (ok, out) = run_quiet(c, Duration::from_secs(4))?;
|
||||
if ok { parse_version(&out) } else { None }
|
||||
});
|
||||
info.status = ToolStatus::Custom;
|
||||
info.path = Some(path.clone().into());
|
||||
info
|
||||
}
|
||||
|
||||
fn detect(&self, spec: &ToolSpec) -> (ToolStatus, Option<PathBuf>, Option<String>) {
|
||||
@@ -539,6 +599,8 @@ impl Tools {
|
||||
}
|
||||
Method::Npm { packages } => self.install_npm(packages, cancel, emit)?,
|
||||
Method::Go { module } => self.install_go(spec, module, cancel, emit)?,
|
||||
Method::Gem { gem } => self.install_gem(spec, gem, cancel, emit)?,
|
||||
Method::DotnetTool { package } => self.install_dotnet_tool(spec, package, cancel, emit)?,
|
||||
Method::PipVenv { package } => self.install_venv(spec, package, cancel, emit)?,
|
||||
Method::PipUser { package, .. } => self.install_pip_user(package, cancel, emit)?,
|
||||
Method::PipTarget { package, .. } => self.install_pip_target(spec, package, cancel, emit)?,
|
||||
@@ -618,6 +680,96 @@ impl Tools {
|
||||
self.write_manifest(spec.name, &Manifest { version, source: Some(module.to_string()) })
|
||||
}
|
||||
|
||||
fn install_gem(&self, spec: &ToolSpec, gem: &str, cancel: &CancellationToken, emit: Emit) -> IdeResult<()> {
|
||||
let dir = self.root.join(spec.name);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let home = dir.join("gems");
|
||||
std::fs::create_dir_all(&home)?;
|
||||
let mut c = self.command(self.which("gem").expect("checked"));
|
||||
c.args(["install", "--no-document", "--install-dir"]).arg(&home).arg("--bindir").arg(home.join("bin")).arg(gem);
|
||||
let result = run_streamed(c, cancel, emit).and_then(|_| {
|
||||
// RubyGems' stubs only find their gems through GEM_HOME / GEM_PATH.
|
||||
let env = [("GEM_HOME", home.as_path()), ("GEM_PATH", home.as_path())];
|
||||
for cmd in spec.commands {
|
||||
let stub = self
|
||||
.exe_in(&home.join("bin"), cmd)
|
||||
.ok_or_else(|| IdeError::new(ErrorKind::Io, format!("gem {gem} did not install `{cmd}`")))?;
|
||||
archive::env_wrapper(&dir.join("bin"), cmd, &stub, &env)?;
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
if let Err(e) = result {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
return Err(e);
|
||||
}
|
||||
// `gems/gems/<gem>-<version>/`
|
||||
let version = std::fs::read_dir(home.join("gems")).ok().and_then(|entries| {
|
||||
entries.flatten().find_map(|e| {
|
||||
let name = e.file_name().to_string_lossy().into_owned();
|
||||
name.strip_prefix(&format!("{gem}-"))
|
||||
.filter(|v| v.starts_with(|c: char| c.is_ascii_digit()))
|
||||
.map(String::from)
|
||||
})
|
||||
});
|
||||
self.write_manifest(spec.name, &Manifest { version, source: Some(format!("rubygems:{gem}")) })
|
||||
}
|
||||
|
||||
fn install_dotnet_tool(
|
||||
&self,
|
||||
spec: &ToolSpec,
|
||||
package: &str,
|
||||
cancel: &CancellationToken,
|
||||
emit: Emit,
|
||||
) -> IdeResult<()> {
|
||||
let dir = self.root.join(spec.name);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let tool = dir.join("tool");
|
||||
std::fs::create_dir_all(&tool)?;
|
||||
let dotnet = self.which("dotnet").expect("checked");
|
||||
let mut c = self.command(&dotnet);
|
||||
c.args(["tool", "install", package, "--tool-path"]).arg(&tool);
|
||||
let result = run_streamed(c, cancel, emit).and_then(|_| {
|
||||
// The tool's apphost looks for .NET in the default location only; a
|
||||
// Homebrew / user-local SDK must be named through DOTNET_ROOT.
|
||||
let root = self.dotnet_root(&dotnet);
|
||||
for cmd in spec.commands {
|
||||
let exe = self
|
||||
.exe_in(&tool, cmd)
|
||||
.ok_or_else(|| IdeError::new(ErrorKind::Io, format!("{package} did not install `{cmd}`")))?;
|
||||
match &root {
|
||||
Some(root) => archive::env_wrapper(&dir.join("bin"), cmd, &exe, &[("DOTNET_ROOT", root)])?,
|
||||
None => archive::link_executable(&dir.join("bin"), cmd, &exe)?,
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
if let Err(e) = result {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
return Err(e);
|
||||
}
|
||||
// `Package Id Version Commands` table.
|
||||
let mut c = self.command(&dotnet);
|
||||
c.args(["tool", "list", "--tool-path"]).arg(&tool);
|
||||
let version = run_quiet(c, Duration::from_secs(20)).and_then(|(_, out)| {
|
||||
out.lines().find_map(|l| {
|
||||
let mut cols = l.split_whitespace();
|
||||
cols.next().filter(|id| id.eq_ignore_ascii_case(package))?;
|
||||
cols.next().map(String::from)
|
||||
})
|
||||
});
|
||||
self.write_manifest(spec.name, &Manifest { version, source: Some(format!("nuget:{package}")) })
|
||||
}
|
||||
|
||||
/// The .NET install `dotnet` runs from: `Microsoft.NETCore.App 9.0.1 [<root>/shared/Microsoft.NETCore.App]`.
|
||||
fn dotnet_root(&self, dotnet: &Path) -> Option<PathBuf> {
|
||||
let mut c = self.command(dotnet);
|
||||
c.arg("--list-runtimes");
|
||||
let (_, out) = run_quiet(c, Duration::from_secs(20))?;
|
||||
let line = out.lines().find(|l| l.starts_with("Microsoft.NETCore.App "))?;
|
||||
let shared = line.rsplit_once('[')?.1.trim_end().strip_suffix(']')?;
|
||||
Path::new(shared).parent()?.parent().map(Path::to_path_buf)
|
||||
}
|
||||
|
||||
fn install_venv(&self, spec: &ToolSpec, package: &str, cancel: &CancellationToken, emit: Emit) -> IdeResult<()> {
|
||||
let dir = self.root.join(spec.name);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
@@ -897,7 +1049,12 @@ impl Tools {
|
||||
run_streamed(c, &cancel, &quiet)?;
|
||||
}
|
||||
}
|
||||
Method::Go { .. } | Method::PipVenv { .. } | Method::PipTarget { .. } | Method::Release { .. } => {
|
||||
Method::Go { .. }
|
||||
| Method::Gem { .. }
|
||||
| Method::DotnetTool { .. }
|
||||
| Method::PipVenv { .. }
|
||||
| Method::PipTarget { .. }
|
||||
| Method::Release { .. } => {
|
||||
let dir = self.root.join(spec.name);
|
||||
if dir.exists() {
|
||||
std::fs::remove_dir_all(&dir)?;
|
||||
|
||||
@@ -44,6 +44,11 @@ pub enum Method {
|
||||
/// A pure-Python package unpacked into `<tools>/<name>/lib` (`pip install --target`,
|
||||
/// universal wheel), put on `PYTHONPATH` of whichever interpreter runs it.
|
||||
PipTarget { package: &'static str, module: &'static str },
|
||||
/// `gem install` into `<tools>/<name>/gems`, launched through `GEM_HOME` wrappers in `bin/`.
|
||||
Gem { gem: &'static str },
|
||||
/// `dotnet tool install --tool-path <tools>/<name>/tool <package>`, launched
|
||||
/// through `DOTNET_ROOT` wrappers in `bin/`.
|
||||
DotnetTool { package: &'static str },
|
||||
/// Platform archive download into `<tools>/<name>/`.
|
||||
Release { source: ReleaseSource, assets: &'static [AssetRule], locate: &'static [&'static str] },
|
||||
}
|
||||
@@ -54,6 +59,8 @@ impl Method {
|
||||
Method::Rustup { .. } => "rustup",
|
||||
Method::Npm { .. } => "npm",
|
||||
Method::Go { .. } => "go install",
|
||||
Method::Gem { .. } => "gem",
|
||||
Method::DotnetTool { .. } => "dotnet tool",
|
||||
Method::PipVenv { .. } => "pip (virtualenv)",
|
||||
Method::PipUser { .. } => "pip --user",
|
||||
Method::PipTarget { .. } => "pip (private copy)",
|
||||
@@ -78,6 +85,8 @@ pub struct ToolSpec {
|
||||
/// Version query: a command (looked up next to the main binary first) and its args.
|
||||
pub version: Option<(&'static str, &'static [&'static str])>,
|
||||
pub homepage: &'static str,
|
||||
/// Runtimes the tool runs on, found on `PATH`: command and why it is needed.
|
||||
pub needs: &'static [(&'static str, &'static str)],
|
||||
}
|
||||
|
||||
impl ToolSpec {
|
||||
@@ -94,6 +103,11 @@ use Os::{Linux, Mac, Windows};
|
||||
use ToolKind::{Debugger, LanguageServer, Plugin};
|
||||
|
||||
const V: Option<(&str, &[&str])> = None;
|
||||
const JAVA: &[(&str, &str)] = &[("java", "Java is required (https://adoptium.net)")];
|
||||
const NODE: &[(&str, &str)] = &[("node", "Node.js is required (https://nodejs.org)")];
|
||||
const ELIXIR: &[(&str, &str)] = &[("elixir", "Elixir is required (https://elixir-lang.org/install.html)")];
|
||||
const ELIXIR_LS_ASSETS: &[AssetRule] =
|
||||
&[any_arch(Mac, "elixir-ls-v*.zip"), any_arch(Linux, "elixir-ls-v*.zip"), any_arch(Windows, "elixir-ls-v*.zip")];
|
||||
const fn ver(cmd: &'static str) -> Option<(&'static str, &'static [&'static str])> {
|
||||
Some((cmd, &["--version"]))
|
||||
}
|
||||
@@ -107,6 +121,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Rustup { component: "rust-analyzer" },
|
||||
version: ver("rust-analyzer"),
|
||||
homepage: "https://rust-analyzer.github.io",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "vtsls",
|
||||
@@ -116,6 +131,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["@vtsls/language-server"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/yioneko/vtsls",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "typescript-language-server",
|
||||
@@ -125,6 +141,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["typescript-language-server", "typescript"] },
|
||||
version: ver("typescript-language-server"),
|
||||
homepage: "https://github.com/typescript-language-server/typescript-language-server",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "pyright",
|
||||
@@ -134,6 +151,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["pyright"] },
|
||||
version: ver("pyright"),
|
||||
homepage: "https://github.com/microsoft/pyright",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "basedpyright",
|
||||
@@ -143,6 +161,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::PipVenv { package: "basedpyright" },
|
||||
version: ver("basedpyright"),
|
||||
homepage: "https://docs.basedpyright.com",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "bash-language-server",
|
||||
@@ -152,6 +171,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["bash-language-server"] },
|
||||
version: ver("bash-language-server"),
|
||||
homepage: "https://github.com/bash-lsp/bash-language-server",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "yaml-language-server",
|
||||
@@ -161,6 +181,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["yaml-language-server"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/redhat-developer/yaml-language-server",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "vscode-json-language-server",
|
||||
@@ -170,6 +191,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["vscode-langservers-extracted"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/hrsh7th/vscode-langservers-extracted",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "vscode-css-language-server",
|
||||
@@ -179,6 +201,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["vscode-langservers-extracted"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/hrsh7th/vscode-langservers-extracted",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "vscode-html-language-server",
|
||||
@@ -188,6 +211,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["vscode-langservers-extracted"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/hrsh7th/vscode-langservers-extracted",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "dockerfile-language-server",
|
||||
@@ -197,6 +221,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["dockerfile-language-server-nodejs"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/rcjsuen/dockerfile-language-server",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "svelte-language-server",
|
||||
@@ -206,6 +231,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["svelte-language-server"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/sveltejs/language-tools",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "vue-language-server",
|
||||
@@ -215,6 +241,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["@vue/language-server"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/vuejs/language-tools",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "graphql-lsp",
|
||||
@@ -224,6 +251,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["graphql-language-service-cli"] },
|
||||
version: V,
|
||||
homepage: "https://github.com/graphql/graphiql",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "intelephense",
|
||||
@@ -233,6 +261,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Npm { packages: &["intelephense"] },
|
||||
version: V,
|
||||
homepage: "https://intelephense.com",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "gopls",
|
||||
@@ -242,6 +271,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Go { module: "golang.org/x/tools/gopls@latest" },
|
||||
version: Some(("gopls", &["version"])),
|
||||
homepage: "https://pkg.go.dev/golang.org/x/tools/gopls",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "sqls",
|
||||
@@ -251,6 +281,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Go { module: "github.com/sqls-server/sqls@latest" },
|
||||
version: Some(("sqls", &["--version"])),
|
||||
homepage: "https://github.com/sqls-server/sqls",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "delve",
|
||||
@@ -260,6 +291,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::Go { module: "github.com/go-delve/delve/cmd/dlv@latest" },
|
||||
version: Some(("dlv", &["version"])),
|
||||
homepage: "https://github.com/go-delve/delve",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "debugpy",
|
||||
@@ -269,6 +301,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
method: Method::PipTarget { package: "debugpy", module: "debugpy" },
|
||||
version: V,
|
||||
homepage: "https://github.com/microsoft/debugpy",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "clangd",
|
||||
@@ -286,6 +319,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: ver("clangd"),
|
||||
homepage: "https://clangd.llvm.org",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "lua-language-server",
|
||||
@@ -305,6 +339,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: ver("lua-language-server"),
|
||||
homepage: "https://luals.github.io",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "marksman",
|
||||
@@ -323,6 +358,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: ver("marksman"),
|
||||
homepage: "https://github.com/artempyanykh/marksman",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "taplo",
|
||||
@@ -342,6 +378,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: ver("taplo"),
|
||||
homepage: "https://taplo.tamasfe.dev",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "zls",
|
||||
@@ -361,6 +398,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: ver("zls"),
|
||||
homepage: "https://github.com/zigtools/zls",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "terraform-ls",
|
||||
@@ -380,6 +418,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: Some(("terraform-ls", &["version"])),
|
||||
homepage: "https://github.com/hashicorp/terraform-ls",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "codelldb",
|
||||
@@ -404,6 +443,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/vadimcn/codelldb",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "js-debug",
|
||||
@@ -422,6 +462,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/microsoft/vscode-js-debug",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "jdtls",
|
||||
@@ -439,6 +480,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/eclipse-jdtls/eclipse.jdt.ls",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "java-debug",
|
||||
@@ -457,6 +499,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/microsoft/java-debug",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "lombok",
|
||||
@@ -475,6 +518,7 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://projectlombok.org",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "kotlin-lsp",
|
||||
@@ -498,6 +542,280 @@ pub static TOOLS: &[ToolSpec] = &[
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/Kotlin/kotlin-lsp",
|
||||
needs: &[],
|
||||
},
|
||||
// ElixirLS ships launcher scripts only: on first start they build the server
|
||||
// with the Elixir / OTP found for the project (Mix.install, needs network).
|
||||
ToolSpec {
|
||||
name: "elixir-ls",
|
||||
display: "ElixirLS",
|
||||
kind: LanguageServer,
|
||||
commands: &["elixir-ls"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "elixir-lsp/elixir-ls" },
|
||||
assets: ELIXIR_LS_ASSETS,
|
||||
locate: &["language_server.sh", "language_server.bat"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/elixir-lsp/elixir-ls",
|
||||
needs: ELIXIR,
|
||||
},
|
||||
ToolSpec {
|
||||
name: "elixir-ls-debugger",
|
||||
display: "ElixirLS Debugger",
|
||||
kind: Debugger,
|
||||
commands: &["elixir-ls-debugger"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "elixir-lsp/elixir-ls" },
|
||||
assets: ELIXIR_LS_ASSETS,
|
||||
locate: &["debug_adapter.sh", "debug_adapter.bat"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/elixir-lsp/elixir-ls",
|
||||
needs: ELIXIR,
|
||||
},
|
||||
ToolSpec {
|
||||
name: "buf",
|
||||
display: "Buf (Protocol Buffers)",
|
||||
kind: LanguageServer,
|
||||
commands: &["buf"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "bufbuild/buf" },
|
||||
assets: &[
|
||||
rule(Mac, Arm64, "buf-Darwin-arm64.tar.gz"),
|
||||
rule(Mac, X64, "buf-Darwin-x86_64.tar.gz"),
|
||||
rule(Linux, X64, "buf-Linux-x86_64.tar.gz"),
|
||||
rule(Linux, Arm64, "buf-Linux-aarch64.tar.gz"),
|
||||
rule(Windows, X64, "buf-Windows-x86_64.zip"),
|
||||
rule(Windows, Arm64, "buf-Windows-arm64.zip"),
|
||||
],
|
||||
locate: &["buf"],
|
||||
},
|
||||
version: ver("buf"),
|
||||
homepage: "https://buf.build",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "clojure-lsp",
|
||||
display: "clojure-lsp",
|
||||
kind: LanguageServer,
|
||||
commands: &["clojure-lsp"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "clojure-lsp/clojure-lsp" },
|
||||
assets: &[
|
||||
rule(Mac, Arm64, "clojure-lsp-native-macos-aarch64.zip"),
|
||||
rule(Mac, X64, "clojure-lsp-native-macos-amd64.zip"),
|
||||
rule(Linux, X64, "clojure-lsp-native-linux-amd64.zip"),
|
||||
rule(Linux, Arm64, "clojure-lsp-native-linux-aarch64.zip"),
|
||||
rule(Windows, X64, "clojure-lsp-native-windows-amd64.zip"),
|
||||
],
|
||||
locate: &["clojure-lsp"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://clojure-lsp.io",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "texlab",
|
||||
display: "TexLab (LaTeX)",
|
||||
kind: LanguageServer,
|
||||
commands: &["texlab"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "latex-lsp/texlab" },
|
||||
assets: &[
|
||||
rule(Mac, Arm64, "texlab-aarch64-macos.tar.gz"),
|
||||
rule(Mac, X64, "texlab-x86_64-macos.tar.gz"),
|
||||
rule(Linux, X64, "texlab-x86_64-linux.tar.gz"),
|
||||
rule(Linux, Arm64, "texlab-aarch64-linux.tar.gz"),
|
||||
rule(Windows, X64, "texlab-x86_64-windows.zip"),
|
||||
rule(Windows, Arm64, "texlab-aarch64-windows.zip"),
|
||||
],
|
||||
locate: &["texlab"],
|
||||
},
|
||||
version: ver("texlab"),
|
||||
homepage: "https://github.com/latex-lsp/texlab",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "neocmakelsp",
|
||||
display: "neocmakelsp (CMake)",
|
||||
kind: LanguageServer,
|
||||
commands: &["neocmakelsp"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "Decodetalkers/neocmakelsp" },
|
||||
assets: &[
|
||||
any_arch(Mac, "neocmakelsp-universal-apple-darwin.tar.gz"),
|
||||
rule(Linux, X64, "neocmakelsp-x86_64-unknown-linux-gnu.tar.gz"),
|
||||
rule(Linux, Arm64, "neocmakelsp-aarch64-unknown-linux-gnu.tar.gz"),
|
||||
rule(Windows, X64, "neocmakelsp-x86_64-pc-windows-msvc.zip"),
|
||||
rule(Windows, Arm64, "neocmakelsp-aarch64-pc-windows-msvc.zip"),
|
||||
],
|
||||
locate: &["neocmakelsp"],
|
||||
},
|
||||
version: ver("neocmakelsp"),
|
||||
homepage: "https://github.com/Decodetalkers/neocmakelsp",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "lemminx",
|
||||
display: "LemMinX (XML)",
|
||||
kind: LanguageServer,
|
||||
commands: &["lemminx"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "redhat-developer/vscode-xml" },
|
||||
assets: &[
|
||||
rule(Mac, Arm64, "lemminx-osx-aarch_64.zip"),
|
||||
rule(Mac, X64, "lemminx-osx-x86_64.zip"),
|
||||
rule(Linux, X64, "lemminx-linux-x86_64.zip"),
|
||||
rule(Linux, Arm64, "lemminx-linux-aarch_64.zip"),
|
||||
rule(Windows, X64, "lemminx-win32.zip"),
|
||||
],
|
||||
locate: &["lemminx-*"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/eclipse/lemminx",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "perlnavigator",
|
||||
display: "Perl Navigator",
|
||||
kind: LanguageServer,
|
||||
commands: &["perlnavigator"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "bscan/PerlNavigator" },
|
||||
assets: &[
|
||||
any_arch(Mac, "perlnavigator-macos-x86_64.zip"),
|
||||
rule(Linux, X64, "perlnavigator-linux-x86_64.zip"),
|
||||
rule(Windows, X64, "perlnavigator-win-x86_64.zip"),
|
||||
],
|
||||
locate: &["perlnavigator"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/bscan/PerlNavigator",
|
||||
needs: &[("perl", "Perl is required (https://www.perl.org/get.html)")],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "kotlin-language-server",
|
||||
display: "Kotlin Language Server (fwcd)",
|
||||
kind: LanguageServer,
|
||||
commands: &["kotlin-language-server"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "fwcd/kotlin-language-server" },
|
||||
assets: &[any_arch(Mac, "server.zip"), any_arch(Linux, "server.zip"), any_arch(Windows, "server.zip")],
|
||||
locate: &["kotlin-language-server"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/fwcd/kotlin-language-server",
|
||||
needs: JAVA,
|
||||
},
|
||||
ToolSpec {
|
||||
name: "kotlin-debug-adapter",
|
||||
display: "Kotlin Debug Adapter",
|
||||
kind: Debugger,
|
||||
commands: &["kotlin-debug-adapter"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "fwcd/kotlin-debug-adapter" },
|
||||
assets: &[any_arch(Mac, "adapter.zip"), any_arch(Linux, "adapter.zip"), any_arch(Windows, "adapter.zip")],
|
||||
locate: &["kotlin-debug-adapter"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/fwcd/kotlin-debug-adapter",
|
||||
needs: JAVA,
|
||||
},
|
||||
ToolSpec {
|
||||
name: "netcoredbg",
|
||||
display: "netcoredbg (.NET debugger)",
|
||||
kind: Debugger,
|
||||
commands: &["netcoredbg"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::GitHub { repo: "Samsung/netcoredbg" },
|
||||
assets: &[
|
||||
rule(Mac, Arm64, "netcoredbg-osx-arm64.zip"),
|
||||
rule(Linux, X64, "netcoredbg-linux-amd64.tar.gz"),
|
||||
rule(Linux, Arm64, "netcoredbg-linux-arm64.tar.gz"),
|
||||
rule(Windows, X64, "netcoredbg-win64.zip"),
|
||||
],
|
||||
locate: &["netcoredbg"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/Samsung/netcoredbg",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "bash-debug",
|
||||
display: "Bash Debug",
|
||||
kind: Debugger,
|
||||
commands: &["bash-debug-adapter"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::OpenVsx { namespace: "rogalmic", extension: "bash-debug" },
|
||||
assets: &[
|
||||
any_arch(Mac, "rogalmic.bash-debug-*.vsix"),
|
||||
any_arch(Linux, "rogalmic.bash-debug-*.vsix"),
|
||||
any_arch(Windows, "rogalmic.bash-debug-*.vsix"),
|
||||
],
|
||||
locate: &["bashDebug.js"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/rogalmic/vscode-bash-debug",
|
||||
needs: NODE,
|
||||
},
|
||||
ToolSpec {
|
||||
name: "php-debug",
|
||||
display: "PHP Debug (Xdebug)",
|
||||
kind: Debugger,
|
||||
commands: &["php-debug-adapter"],
|
||||
method: Method::Release {
|
||||
source: ReleaseSource::OpenVsx { namespace: "xdebug", extension: "php-debug" },
|
||||
assets: &[
|
||||
any_arch(Mac, "xdebug.php-debug-*.vsix"),
|
||||
any_arch(Linux, "xdebug.php-debug-*.vsix"),
|
||||
any_arch(Windows, "xdebug.php-debug-*.vsix"),
|
||||
],
|
||||
locate: &["phpDebug.js"],
|
||||
},
|
||||
version: V,
|
||||
homepage: "https://github.com/xdebug/vscode-php-debug",
|
||||
needs: NODE,
|
||||
},
|
||||
ToolSpec {
|
||||
name: "ruby-lsp",
|
||||
display: "Ruby LSP (Shopify)",
|
||||
kind: LanguageServer,
|
||||
commands: &["ruby-lsp"],
|
||||
method: Method::Gem { gem: "ruby-lsp" },
|
||||
version: V,
|
||||
homepage: "https://shopify.github.io/ruby-lsp",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "solargraph",
|
||||
display: "Solargraph (Ruby)",
|
||||
kind: LanguageServer,
|
||||
commands: &["solargraph"],
|
||||
method: Method::Gem { gem: "solargraph" },
|
||||
version: ver("solargraph"),
|
||||
homepage: "https://solargraph.org",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "csharp-ls",
|
||||
display: "csharp-ls",
|
||||
kind: LanguageServer,
|
||||
commands: &["csharp-ls"],
|
||||
method: Method::DotnetTool { package: "csharp-ls" },
|
||||
version: V,
|
||||
homepage: "https://github.com/razzmatazz/csharp-language-server",
|
||||
needs: &[],
|
||||
},
|
||||
ToolSpec {
|
||||
name: "fsautocomplete",
|
||||
display: "FsAutoComplete (F#)",
|
||||
kind: LanguageServer,
|
||||
commands: &["fsautocomplete"],
|
||||
method: Method::DotnetTool { package: "fsautocomplete" },
|
||||
version: V,
|
||||
homepage: "https://github.com/ionide/FsAutoComplete",
|
||||
needs: &[],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -68,10 +68,12 @@ fn everything_missing_on_an_empty_system() {
|
||||
assert!(vtsls.languages.iter().any(|l| l == "TypeScript"));
|
||||
assert!(vtsls.unavailable_reason.as_deref().unwrap().contains("npm"));
|
||||
// Servers without an installer are listed with their manual hint.
|
||||
let ruby = find(&list, "solargraph");
|
||||
assert_eq!(ruby.install_method, None);
|
||||
assert!(!ruby.can_install);
|
||||
assert_eq!(ruby.status, ToolStatus::Missing);
|
||||
let hls = find(&list, "haskell-language-server");
|
||||
assert_eq!(hls.install_method, None);
|
||||
assert!(!hls.can_install);
|
||||
assert_eq!(hls.status, ToolStatus::Missing);
|
||||
// Gem tools need Ruby.
|
||||
assert!(find(&list, "solargraph").unavailable_reason.as_deref().unwrap().contains("Ruby"));
|
||||
// Shared npm package: each server is its own row.
|
||||
assert_eq!(find(&list, "vscode-css-language-server").install_method.as_deref(), Some("npm"));
|
||||
assert!(find(&list, "delve").kind == ToolKind::Debugger);
|
||||
@@ -155,7 +157,7 @@ fn bin_dirs_cover_every_managed_layout() {
|
||||
fn unknown_or_manual_tools_cannot_be_installed() {
|
||||
let env = Env::new();
|
||||
let tools = env.tools();
|
||||
let err = tools.install("solargraph", &langs(), &CancellationToken::new(), &|_| {}).unwrap_err();
|
||||
let err = tools.install("haskell-language-server", &langs(), &CancellationToken::new(), &|_| {}).unwrap_err();
|
||||
assert_eq!(err.kind, ErrorKind::Unavailable);
|
||||
assert!(err.message.contains("cannot be installed automatically"));
|
||||
assert_eq!(tools.info("nope", &langs()).unwrap_err().kind, ErrorKind::NotFound);
|
||||
@@ -286,3 +288,97 @@ fn installed_bundle_is_detected_and_resolvable() {
|
||||
assert_eq!(managed_bundle(app_data, "java-debug"), Some(bin.join("com.microsoft.java.debug.plugin.jar")));
|
||||
assert_eq!(managed_bundle(app_data, "jdtls"), None, "not a bundle");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn custom_paths_win_and_report_their_version() {
|
||||
let env = Env::new();
|
||||
env.script(&env.sys, "gopls", "echo 'golang.org/x/tools/gopls v0.16.1'");
|
||||
let elsewhere = env.sys.parent().unwrap().join("opt/go/bin");
|
||||
env.script(&elsewhere, "my-gopls", "echo 'golang.org/x/tools/gopls v0.17.0'");
|
||||
let custom =
|
||||
BTreeMap::from([("gopls".to_string(), elsewhere.join("my-gopls")), ("zls".to_string(), elsewhere.join("zls"))]);
|
||||
let list = env.tools().with_custom_paths(custom).list(&langs());
|
||||
let gopls = find(&list, "gopls");
|
||||
assert_eq!(gopls.status, ToolStatus::Custom);
|
||||
assert_eq!(gopls.path.as_deref(), Some(elsewhere.join("my-gopls").as_path()));
|
||||
assert_eq!(gopls.version.as_deref(), Some("0.17.0"));
|
||||
assert_eq!(gopls.custom_error, None);
|
||||
// A path that does not exist is reported, not silently replaced by detection.
|
||||
let zls = find(&list, "zls");
|
||||
assert_eq!(zls.status, ToolStatus::Missing);
|
||||
assert!(zls.custom_error.as_deref().unwrap().contains("does not exist"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_debugger_named_like_its_server_is_listed_by_its_command() {
|
||||
let list = Env::new().tools().list(&langs());
|
||||
let server = find(&list, "elixir-ls");
|
||||
assert_eq!((server.kind, server.command.as_str()), (ToolKind::LanguageServer, "elixir-ls"));
|
||||
let debugger = find(&list, "elixir-ls-debugger");
|
||||
assert_eq!((debugger.kind, debugger.command.as_str()), (ToolKind::Debugger, "elixir-ls-debugger"));
|
||||
assert_eq!(debugger.languages, vec!["Elixir".to_string()]);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn elixir_ls_needs_elixir_and_lists_its_debugger() {
|
||||
let env = Env::new();
|
||||
env.script(&env.sys, "curl", "exit 0");
|
||||
let list = env.tools().list(&langs());
|
||||
let server = find(&list, "elixir-ls");
|
||||
assert_eq!(server.install_method.as_deref(), Some("GitHub release"));
|
||||
assert!(!server.can_install);
|
||||
assert!(server.unavailable_reason.as_deref().unwrap().contains("Elixir is required"));
|
||||
let debugger = find(&list, "elixir-ls-debugger");
|
||||
assert_eq!((debugger.kind, debugger.languages.as_slice()), (ToolKind::Debugger, ["Elixir".to_string()].as_slice()));
|
||||
|
||||
env.script(&env.sys, "elixir", "exit 0");
|
||||
let list = env.tools().list(&langs());
|
||||
assert!(find(&list, "elixir-ls").can_install);
|
||||
assert!(find(&list, "elixir-ls-debugger").can_install);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn gem_install_wraps_stubs_with_gem_home() {
|
||||
let env = Env::new();
|
||||
// `gem install --no-document --install-dir <home> --bindir <bin> solargraph`
|
||||
env.script(
|
||||
&env.sys,
|
||||
"gem",
|
||||
r#"home="$4"; bin="$6"; /bin/mkdir -p "$home/gems/solargraph-0.50.0" "$bin"
|
||||
printf '#!/bin/sh\necho "$GEM_HOME"\n' > "$bin/solargraph"; /bin/chmod +x "$bin/solargraph""#,
|
||||
);
|
||||
let tools = env.tools();
|
||||
let info = tools.install("solargraph", &langs(), &CancellationToken::new(), &|_| {}).unwrap();
|
||||
assert_eq!(info.status, ToolStatus::Installed);
|
||||
assert_eq!(info.version.as_deref(), Some("0.50.0"));
|
||||
let wrapper = env.root.join("solargraph/bin/solargraph");
|
||||
assert_eq!(info.path.as_deref(), Some(wrapper.as_path()));
|
||||
let out = std::process::Command::new(&wrapper).output().unwrap();
|
||||
assert_eq!(String::from_utf8_lossy(&out.stdout).trim(), env.root.join("solargraph/gems").to_string_lossy());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn dotnet_tool_install_into_tool_path() {
|
||||
let env = Env::new();
|
||||
env.script(
|
||||
&env.sys,
|
||||
"dotnet",
|
||||
r#"case "$2" in
|
||||
install) /bin/mkdir -p "$5"; printf '#!/bin/sh\necho "$DOTNET_ROOT"\n' > "$5/csharp-ls"; /bin/chmod +x "$5/csharp-ls" ;;
|
||||
list) printf 'Package Id Version Commands\n----\ncsharp-ls 0.15.0 csharp-ls\n' ;;
|
||||
esac
|
||||
[ "$1" = --list-runtimes ] && echo 'Microsoft.NETCore.App 9.0.1 [/opt/dotnet/shared/Microsoft.NETCore.App]'
|
||||
exit 0"#,
|
||||
);
|
||||
let info = env.tools().install("csharp-ls", &langs(), &CancellationToken::new(), &|_| {}).unwrap();
|
||||
assert_eq!(info.status, ToolStatus::Installed);
|
||||
assert_eq!(info.version.as_deref(), Some("0.15.0"));
|
||||
let wrapper = env.root.join("csharp-ls/bin/csharp-ls");
|
||||
assert_eq!(info.path.as_deref(), Some(wrapper.as_path()));
|
||||
let out = std::process::Command::new(&wrapper).output().unwrap();
|
||||
assert_eq!(String::from_utf8_lossy(&out.stdout).trim(), "/opt/dotnet");
|
||||
}
|
||||
@@ -268,6 +268,7 @@ mod patch;
|
||||
mod refs;
|
||||
mod remotes;
|
||||
mod repo;
|
||||
mod roots;
|
||||
pub mod shelf;
|
||||
mod status;
|
||||
mod write;
|
||||
@@ -275,6 +276,7 @@ mod write;
|
||||
pub use cli::{detected_git_executable, git_version, set_git_executable};
|
||||
pub use diff::build_partial_patch;
|
||||
pub use remotes::Remote;
|
||||
pub use roots::Repos;
|
||||
|
||||
/// Clones `url` into `dest` (which must not exist or be empty), streaming progress.
|
||||
pub fn clone(url: &str, dest: &Path, cancel: &CancellationToken, on_output: &dyn Fn(String)) -> IdeResult<()> {
|
||||
@@ -320,6 +322,10 @@ impl Repo {
|
||||
pub fn branch_info(&self) -> IdeResult<BranchInfo> {
|
||||
refs::branch_info(self)
|
||||
}
|
||||
/// Merge / rebase / cherry-pick… in progress (cheap: no ref walking).
|
||||
pub fn operation(&self) -> IdeResult<Option<String>> {
|
||||
Ok(refs::operation(&self.gix()?))
|
||||
}
|
||||
/// Content of `path` at `rev` (default HEAD); `None` if absent there.
|
||||
/// `rev` may be any revision git understands, or `":"` / `":0"` for the index.
|
||||
pub fn file_at(&self, path: &Path, rev: Option<&str>) -> IdeResult<Option<String>> {
|
||||
|
||||
@@ -30,7 +30,7 @@ pub(crate) fn branch_info(r: &Repo) -> IdeResult<BranchInfo> {
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
fn operation(repo: &gix::Repository) -> Option<String> {
|
||||
pub(crate) fn operation(repo: &gix::Repository) -> Option<String> {
|
||||
use gix::state::InProgress::*;
|
||||
let op = match repo.state()? {
|
||||
ApplyMailbox | ApplyMailboxRebase => "am",
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
//! The repositories of a project (IDEA's VCS roots): the one containing the project
|
||||
//! root plus those nested below it (separate clones side by side, submodules).
|
||||
|
||||
use crate::{FileStatus, Repo};
|
||||
use ide_core::IdeResult;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// How deep below the project root nested repositories are looked for.
|
||||
const MAX_DEPTH: usize = 4;
|
||||
|
||||
/// Folders never searched for nested repositories (dependencies, build output).
|
||||
const SKIPPED: &[&str] = &["node_modules", "target", "build", "dist", "out", "vendor", "venv", "__pycache__"];
|
||||
|
||||
/// The repositories of a project, sorted by root; lookups pick the innermost one.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Repos {
|
||||
repos: Vec<Arc<Repo>>,
|
||||
primary: Option<usize>,
|
||||
}
|
||||
|
||||
impl Repos {
|
||||
/// The repository containing `project_root` and every repository whose worktree
|
||||
/// root lies below it (up to [`MAX_DEPTH`] levels; hidden and dependency folders and
|
||||
/// folders `skip` rejects are not searched).
|
||||
pub fn discover(project_root: &Path, skip: &dyn Fn(&Path) -> bool) -> IdeResult<Self> {
|
||||
let mut repos: Vec<Repo> = Vec::new();
|
||||
if let Some(r) = Repo::discover(project_root)? {
|
||||
repos.push(r);
|
||||
}
|
||||
let mut stack: Vec<(PathBuf, usize)> = vec![(project_root.to_path_buf(), 0)];
|
||||
while let Some((dir, depth)) = stack.pop() {
|
||||
let Ok(entries) = std::fs::read_dir(&dir) else { continue };
|
||||
for entry in entries.flatten() {
|
||||
if !entry.file_type().is_ok_and(|t| t.is_dir()) {
|
||||
continue;
|
||||
}
|
||||
let name = entry.file_name();
|
||||
let name = name.to_string_lossy();
|
||||
let path = entry.path();
|
||||
if name.starts_with('.') || SKIPPED.contains(&name.as_ref()) || skip(&path) {
|
||||
continue;
|
||||
}
|
||||
if path.join(".git").exists()
|
||||
&& let Ok(Some(r)) = Repo::discover(&path)
|
||||
&& r.root() == path
|
||||
&& !repos.iter().any(|x| x.root() == r.root())
|
||||
{
|
||||
repos.push(r);
|
||||
}
|
||||
if depth + 1 < MAX_DEPTH {
|
||||
stack.push((path, depth + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Self::new(repos, project_root))
|
||||
}
|
||||
|
||||
/// Only the repository containing `project_root` (the quick lookup on project open).
|
||||
pub fn enclosing(project_root: &Path) -> IdeResult<Self> {
|
||||
Ok(Self::new(Repo::discover(project_root)?.into_iter().collect(), project_root))
|
||||
}
|
||||
|
||||
/// Worktree roots, sorted.
|
||||
pub fn roots(&self) -> Vec<PathBuf> {
|
||||
self.repos.iter().map(|r| r.root().to_path_buf()).collect()
|
||||
}
|
||||
|
||||
fn new(mut repos: Vec<Repo>, project_root: &Path) -> Self {
|
||||
repos.sort_by(|a, b| a.root().cmp(b.root()));
|
||||
let repos: Vec<Arc<Repo>> = repos.into_iter().map(Arc::new).collect();
|
||||
let roots: Vec<&Path> = repos.iter().map(|r| r.root()).collect();
|
||||
let primary = innermost(&roots, project_root, false).or((!repos.is_empty()).then_some(0));
|
||||
Self { repos, primary }
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.repos.is_empty()
|
||||
}
|
||||
|
||||
pub fn all(&self) -> &[Arc<Repo>] {
|
||||
&self.repos
|
||||
}
|
||||
|
||||
/// The repository of the project root, else the first one.
|
||||
pub fn primary(&self) -> Option<&Arc<Repo>> {
|
||||
self.primary.map(|i| &self.repos[i])
|
||||
}
|
||||
|
||||
/// The innermost repository containing `path` (a file or folder). A nested repository's
|
||||
/// root is an entry of the enclosing repository (a submodule or untracked folder there), so
|
||||
/// it belongs to that one; to the repository itself only when nothing encloses it.
|
||||
pub fn for_path(&self, path: &Path) -> Option<&Arc<Repo>> {
|
||||
let roots: Vec<&Path> = self.repos.iter().map(|r| r.root()).collect();
|
||||
let found = innermost(&roots, path, true).or_else(|| {
|
||||
// Another spelling of the same location (symlinks, /var vs /private/var).
|
||||
let canon = dunce::canonicalize(path).ok()?;
|
||||
let roots: Vec<PathBuf> =
|
||||
roots.iter().map(|r| dunce::canonicalize(r).unwrap_or_else(|_| r.to_path_buf())).collect();
|
||||
innermost(&roots.iter().map(PathBuf::as_path).collect::<Vec<_>>(), &canon, true)
|
||||
});
|
||||
found.map(|i| &self.repos[i])
|
||||
}
|
||||
|
||||
/// The repository whose worktree root is `root` (the repository a repository-scoped
|
||||
/// command was given).
|
||||
pub fn at_root(&self, root: &Path) -> Option<&Arc<Repo>> {
|
||||
self.repos.iter().find(|r| r.root() == root).or_else(|| {
|
||||
let canon = dunce::canonicalize(root).ok()?;
|
||||
self.repos.iter().find(|r| dunce::canonicalize(r.root()).is_ok_and(|r| r == canon))
|
||||
})
|
||||
}
|
||||
|
||||
/// `paths` grouped by the repository each belongs to (paths outside every repository are dropped).
|
||||
pub fn group(&self, paths: &[PathBuf]) -> Vec<(Arc<Repo>, Vec<PathBuf>)> {
|
||||
let mut out: Vec<(Arc<Repo>, Vec<PathBuf>)> = Vec::new();
|
||||
for p in paths {
|
||||
let Some(repo) = self.for_path(p) else { continue };
|
||||
match out.iter_mut().find(|(r, _)| Arc::ptr_eq(r, repo)) {
|
||||
Some((_, list)) => list.push(p.clone()),
|
||||
None => out.push((repo.clone(), vec![p.clone()])),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Changes of every repository. A nested repository reports its own files, so the
|
||||
/// enclosing one's "untracked folder" entry for it is dropped. A repository that cannot
|
||||
/// be read (e.g. deleted since the last scan) is left out; fails only when all fail.
|
||||
pub fn status(&self) -> IdeResult<Vec<FileStatus>> {
|
||||
let mut out = Vec::new();
|
||||
let mut first_error = None;
|
||||
let mut read = 0;
|
||||
for repo in &self.repos {
|
||||
let nested: Vec<&Path> = self
|
||||
.repos
|
||||
.iter()
|
||||
.map(|r| r.root())
|
||||
.filter(|r| *r != repo.root() && r.starts_with(repo.root()))
|
||||
.collect();
|
||||
let status = match repo.status() {
|
||||
Ok(status) => {
|
||||
read += 1;
|
||||
status
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("git status of {}: {e}", repo.root().display());
|
||||
first_error.get_or_insert(e);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
out.extend(status.into_iter().filter(|f| {
|
||||
let untracked_root =
|
||||
f.unstaged == Some(crate::ChangeKind::Untracked) && nested.iter().any(|n| f.path.0 == *n);
|
||||
!untracked_root
|
||||
}));
|
||||
}
|
||||
match first_error {
|
||||
Some(e) if read == 0 => Err(e),
|
||||
_ => Ok(out),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Index of the innermost of `roots` containing `path`. With `strict`, a root equal to
|
||||
/// `path` counts only when no other root contains it.
|
||||
fn innermost(roots: &[&Path], path: &Path, strict: bool) -> Option<usize> {
|
||||
let best = |strict: bool| {
|
||||
roots
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, r)| path.starts_with(r) && !(strict && **r == path))
|
||||
.max_by_key(|(_, r)| r.as_os_str().len())
|
||||
.map(|(i, _)| i)
|
||||
};
|
||||
best(strict).or_else(|| best(false))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::process::Command;
|
||||
|
||||
fn git_init(dir: &Path) {
|
||||
std::fs::create_dir_all(dir).unwrap();
|
||||
let ok = Command::new("git").args(["init", "-q"]).current_dir(dir).status().is_ok_and(|s| s.success());
|
||||
assert!(ok, "git init in {}", dir.display());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finds_nested_repositories_and_routes_paths() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = dunce::canonicalize(tmp.path()).unwrap();
|
||||
git_init(&root);
|
||||
git_init(&root.join("services/api"));
|
||||
git_init(&root.join("web"));
|
||||
git_init(&root.join("node_modules/dep"));
|
||||
git_init(&root.join(".cache/repo"));
|
||||
std::fs::write(root.join("services/api/main.rs"), "fn main() {}").unwrap();
|
||||
std::fs::write(root.join("README.md"), "x").unwrap();
|
||||
|
||||
let repos = Repos::discover(&root, &|_| false).unwrap();
|
||||
let roots: Vec<&Path> = repos.all().iter().map(|r| r.root()).collect();
|
||||
assert_eq!(roots, [root.as_path(), &root.join("services/api"), &root.join("web")]);
|
||||
assert_eq!(repos.primary().unwrap().root(), root);
|
||||
assert_eq!(repos.for_path(&root.join("services/api/main.rs")).unwrap().root(), root.join("services/api"));
|
||||
assert_eq!(repos.for_path(&root.join("services/other.txt")).unwrap().root(), root);
|
||||
// A nested root is the enclosing repository's entry (submodule / untracked folder).
|
||||
assert_eq!(repos.for_path(&root.join("services/api")).unwrap().root(), root);
|
||||
assert_eq!(repos.for_path(&root).unwrap().root(), root);
|
||||
assert_eq!(repos.at_root(&root.join("services/api")).unwrap().root(), root.join("services/api"));
|
||||
assert!(repos.at_root(&root.join("services")).is_none());
|
||||
|
||||
let status = repos.status().unwrap();
|
||||
let paths: Vec<String> =
|
||||
status.iter().map(|f| f.path.0.strip_prefix(&root).unwrap().to_string_lossy().replace('\\', "/")).collect();
|
||||
assert!(paths.contains(&"README.md".to_owned()), "{paths:?}");
|
||||
assert!(paths.contains(&"services/api/main.rs".to_owned()), "{paths:?}");
|
||||
assert!(
|
||||
!paths.iter().any(|p| p.trim_end_matches('/') == "web"),
|
||||
"nested root is not an untracked folder: {paths:?}"
|
||||
);
|
||||
|
||||
let groups = repos.group(&[root.join("README.md"), root.join("services/api/main.rs"), root.join("web/x")]);
|
||||
assert_eq!(groups.len(), 3);
|
||||
assert_eq!(groups[1].1, [root.join("services/api/main.rs")]);
|
||||
|
||||
let skipped = Repos::discover(&root, &|p| p.ends_with("services")).unwrap();
|
||||
assert_eq!(skipped.all().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn side_by_side_repositories_without_an_enclosing_one() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let root = dunce::canonicalize(tmp.path()).unwrap();
|
||||
git_init(&root.join("a"));
|
||||
git_init(&root.join("b"));
|
||||
let repos = Repos::discover(&root, &|_| false).unwrap();
|
||||
assert_eq!(repos.all().len(), 2);
|
||||
assert_eq!(repos.primary().unwrap().root(), root.join("a"), "the first when none contains the project root");
|
||||
assert!(repos.for_path(&root.join("c.txt")).is_none());
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@ root-markers = ["mix.exs"]
|
||||
install-hint = "Install ElixirLS (https://github.com/elixir-lsp/elixir-ls/releases) and expose language_server.sh as `elixir-ls`"
|
||||
|
||||
[debugger]
|
||||
adapter = "elixir-ls"
|
||||
adapter = "elixir-ls-debugger"
|
||||
command = "elixir-ls-debugger"
|
||||
install-hint = "Install ElixirLS and expose debug_adapter.sh as `elixir-ls-debugger`"
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "openidea",
|
||||
"private": true,
|
||||
"description": "An open-source IDE inspired by IntelliJ IDEA",
|
||||
"version": "0.1.5",
|
||||
"version": "0.1.8",
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -71,7 +71,7 @@ pub async fn open_project(window: Window, path: PathBuf) -> IdeResult<ProjectInf
|
||||
fn project_info(project: &crate::state::Project) -> ProjectInfo {
|
||||
ProjectInfo {
|
||||
name: project.root.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default(),
|
||||
is_git: project.repo.lock().is_some(),
|
||||
is_git: !project.repos.read().is_empty(),
|
||||
settings: project.settings.effective(),
|
||||
root: project.root.clone().into(),
|
||||
}
|
||||
@@ -148,8 +148,8 @@ pub fn settings_set(
|
||||
.set_file_defaults(ide_workspace::FileDefaults::from_settings(&effective, Some(&project.root)));
|
||||
}
|
||||
}
|
||||
// A new interpreter / toolchain restarts the language servers it affects.
|
||||
if key == "languages" || key.starts_with("languages.") {
|
||||
// A new interpreter / toolchain / server executable restarts the language servers it affects.
|
||||
if ["languages", "tools"].iter().any(|k| key == *k || key.starts_with(&format!("{k}."))) {
|
||||
let affected = if project_scope { current.iter().cloned().collect() } else { state.projects() };
|
||||
for project in affected {
|
||||
let lsp = project.lsp.clone();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
use crate::state::AppState;
|
||||
use ide_build::compile::{self, BuildEvent, BuildKind, BuildResult};
|
||||
use ide_build::{BuildModel, BuildTool, SyncOptions, SyncProgress};
|
||||
use ide_core::settings::Settings;
|
||||
use ide_core::{IdeError, IdeEvent, IdeResult, RequestId};
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
@@ -14,22 +15,32 @@ fn join_err(e: tauri::Error) -> IdeError {
|
||||
IdeError::internal(e.to_string())
|
||||
}
|
||||
|
||||
/// `JAVA_HOME` of the installed JDK matching `release` (none when the project names no version).
|
||||
fn java_env(release: Option<u32>) -> BTreeMap<String, String> {
|
||||
/// `JAVA_HOME`: the project JDK, else the installed JDK matching `release` (none
|
||||
/// when the project names no version).
|
||||
fn java_env(project_jdk: Option<&ide_sdk::java::Jdk>, release: Option<u32>) -> BTreeMap<String, String> {
|
||||
let jdks = ide_sdk::java::installed_jdks();
|
||||
let jdk = release.and_then(|r| ide_sdk::java::pick_jdk(&jdks, Some(r)));
|
||||
let jdk = project_jdk.or_else(|| release.and_then(|r| ide_sdk::java::pick_jdk(&jdks, Some(r))));
|
||||
jdk.map(|j| BTreeMap::from([("JAVA_HOME".to_owned(), j.home.to_string_lossy().into_owned())])).unwrap_or_default()
|
||||
}
|
||||
|
||||
pub(crate) fn load(root: &Path, cache: &Path) -> BuildModel {
|
||||
let mut model = ide_build::load(root, cache);
|
||||
/// The build model with the launch settings applied: the JDK (`JAVA_HOME`), and
|
||||
/// the Maven home and options from Settings › Maven.
|
||||
pub(crate) fn load(root: &Path, cache: &Path, settings: &Settings) -> BuildModel {
|
||||
let mut model = ide_build::load(root, cache, ide_sdk::apply::maven_local_repository(root, settings));
|
||||
let jdk = ide_sdk::apply::project_jdk(root, settings);
|
||||
if let Some(m) = &mut model.maven {
|
||||
let mvn = ide_sdk::apply::maven_command(root, settings);
|
||||
let options = ide_sdk::apply::maven_options(root, settings);
|
||||
for p in &mut m.projects {
|
||||
p.env = java_env(p.java_version);
|
||||
p.env = java_env(jdk.as_ref(), p.java_version);
|
||||
if let Some(mvn) = &mvn {
|
||||
p.command = mvn.to_string_lossy().into_owned();
|
||||
}
|
||||
p.options = options.clone();
|
||||
}
|
||||
}
|
||||
if let Some(g) = &mut model.gradle {
|
||||
g.env = java_env(g.java_version);
|
||||
g.env = java_env(jdk.as_ref(), g.java_version);
|
||||
}
|
||||
model
|
||||
}
|
||||
@@ -39,8 +50,8 @@ pub(crate) fn load(root: &Path, cache: &Path) -> BuildModel {
|
||||
#[specta::specta]
|
||||
pub async fn build_model(window: Window, state: State<'_, AppState>) -> IdeResult<BuildModel> {
|
||||
let project = state.project(window.label())?;
|
||||
let (root, cache) = (project.root.clone(), project.build_cache_dir());
|
||||
tauri::async_runtime::spawn_blocking(move || load(&root, &cache)).await.map_err(join_err)
|
||||
let (root, cache, settings) = (project.root.clone(), project.build_cache_dir(), project.settings.effective());
|
||||
tauri::async_runtime::spawn_blocking(move || load(&root, &cache, &settings)).await.map_err(join_err)
|
||||
}
|
||||
|
||||
/// Runs Maven (`help:effective-pom dependency:tree`) or Gradle (`tasks --all`) in the
|
||||
@@ -58,10 +69,10 @@ pub async fn build_sync(
|
||||
on_progress: Channel<SyncProgress>,
|
||||
) -> IdeResult<BuildModel> {
|
||||
let project = state.project(window.label())?;
|
||||
let (root, cache) = (project.root.clone(), project.build_cache_dir());
|
||||
let (root, cache, settings) = (project.root.clone(), project.build_cache_dir(), project.settings.effective());
|
||||
let token = state.begin_request(request);
|
||||
let result = tauri::async_runtime::spawn_blocking(move || {
|
||||
let current = load(&root, &cache);
|
||||
let current = load(&root, &cache, &settings);
|
||||
let env = match tool {
|
||||
BuildTool::Maven => current
|
||||
.maven
|
||||
@@ -71,7 +82,13 @@ pub async fn build_sync(
|
||||
.unwrap_or_default(),
|
||||
BuildTool::Gradle => current.gradle.as_ref().map(|g| g.env.clone()).unwrap_or_default(),
|
||||
};
|
||||
let options = SyncOptions { offline, profiles, env };
|
||||
let options = SyncOptions {
|
||||
offline,
|
||||
profiles,
|
||||
env,
|
||||
maven_command: ide_sdk::apply::maven_command(&root, &settings).map(|p| p.to_string_lossy().into_owned()),
|
||||
maven_options: ide_sdk::apply::maven_options(&root, &settings),
|
||||
};
|
||||
let progress = |p: SyncProgress| {
|
||||
let _ = on_progress.send(p);
|
||||
};
|
||||
@@ -79,7 +96,7 @@ pub async fn build_sync(
|
||||
BuildTool::Maven => ide_build::sync_maven(&root, &cache, &options, &token, &progress)?,
|
||||
BuildTool::Gradle => ide_build::sync_gradle(&root, &cache, &options, &token, &progress)?,
|
||||
}
|
||||
Ok(load(&root, &cache))
|
||||
Ok(load(&root, &cache, &settings))
|
||||
})
|
||||
.await
|
||||
.map_err(join_err);
|
||||
@@ -104,6 +121,7 @@ pub async fn build_run(
|
||||
) -> IdeResult<BuildResult> {
|
||||
let project = state.project(window.label())?;
|
||||
let (root, cache, sink) = (project.root.clone(), project.build_cache_dir(), project.sink.clone());
|
||||
let settings = project.settings.effective();
|
||||
let token = state.begin_request(request);
|
||||
let result = tauri::async_runtime::spawn_blocking(move || {
|
||||
for path in clear {
|
||||
@@ -113,7 +131,7 @@ pub async fn build_run(
|
||||
items: Vec::new(),
|
||||
});
|
||||
}
|
||||
let plan = compile::plan(&root, &load(&root, &cache), kind, file.as_deref())?;
|
||||
let plan = compile::plan(&root, &load(&root, &cache, &settings), kind, file.as_deref())?;
|
||||
let result = compile::run(&root, &plan, &token, &|e| {
|
||||
let _ = on_event.send(e);
|
||||
})?;
|
||||
|
||||
@@ -14,7 +14,16 @@ pub async fn debug_start(
|
||||
) -> IdeResult<DebugSessionId> {
|
||||
let label = window.label();
|
||||
let owner = SessionOwner::new(AppState::owner_window(label), state.window_sink(label));
|
||||
state.debugger.start(config, owner).await
|
||||
let settings = match state.project(label) {
|
||||
Ok(project) => project.settings.effective(),
|
||||
Err(_) => state.global_settings.effective(),
|
||||
};
|
||||
let root = config.cwd.clone().map(PathBuf::from).unwrap_or_default();
|
||||
let custom = |command: &str| {
|
||||
let path = ide_sdk::apply::setting_path(&root, settings.tool_path(command)?)?;
|
||||
Some(path.to_string_lossy().into_owned())
|
||||
};
|
||||
state.debugger.start_with(config, owner, custom).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::state::AppState;
|
||||
use ide_core::{ChangeSet, DocId, IdeError, IdeResult, OutlineItem, Range};
|
||||
use ide_language::FoldRange;
|
||||
use ide_language::{FoldRange, SyntaxHighlights};
|
||||
use ide_text::LineEnding;
|
||||
use ide_workspace::{DocumentInfo, HistoryEntry};
|
||||
use std::path::PathBuf;
|
||||
@@ -136,6 +136,22 @@ pub async fn doc_folding(window: Window, state: State<'_, AppState>, doc: DocId)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Tree-sitter highlighting for languages the UI has no CodeMirror mode for;
|
||||
/// empty when the grammar has no highlights query or the document is large.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn doc_highlights(window: Window, state: State<'_, AppState>, doc: DocId) -> IdeResult<SyntaxHighlights> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || {
|
||||
let snap = project.documents.text_snapshot(doc)?;
|
||||
if snap.large {
|
||||
return Ok(SyntaxHighlights::default());
|
||||
}
|
||||
Ok(project.syntax.highlights(doc, &snap.language, snap.version, &snap.text))
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Extend Selection (⌥↑): syntax ranges around `offset`, innermost first.
|
||||
/// Large documents fall back to word / line / document ranges.
|
||||
#[tauri::command]
|
||||
|
||||
@@ -22,10 +22,12 @@ pub async fn java_resolve_launch(
|
||||
) -> IdeResult<JavaLaunchInfo> {
|
||||
let project = state.project(window.label())?;
|
||||
let module = project.root.join(module);
|
||||
let settings = project.settings.effective();
|
||||
let built = if build && compile::has_non_java_sources(&module) {
|
||||
let (root, cache, module) = (project.root.clone(), project.build_cache_dir(), module.clone());
|
||||
let (root, cache, module, settings) =
|
||||
(project.root.clone(), project.build_cache_dir(), module.clone(), settings.clone());
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
compile::build_for_launch(&root, &load(&root, &cache), &module, test, &CancellationToken::new())
|
||||
compile::build_for_launch(&root, &load(&root, &cache, &settings), &module, test, &CancellationToken::new())
|
||||
})
|
||||
.await
|
||||
.map_err(|e| IdeError::internal(e.to_string()))??
|
||||
@@ -40,19 +42,22 @@ pub async fn java_resolve_launch(
|
||||
}
|
||||
}
|
||||
info.class_paths = class_paths;
|
||||
// The project JDK, else the JDK jdtls compiles the module against, else one matching its Java version.
|
||||
let project_jdk = ide_sdk::apply::project_jdk(&project.root, &settings);
|
||||
let from_jdtls = info.java_home.as_deref().map(ide_sdk::java::java_executable).filter(|p| p.is_file());
|
||||
let java = from_jdtls.or_else(|| {
|
||||
let java = project_jdk.map(|j| ide_sdk::java::java_executable(&j.home)).or(from_jdtls).or_else(|| {
|
||||
let release = ide_sdk::java::project_java_version(&module);
|
||||
let jdks = ide_sdk::java::installed_jdks();
|
||||
ide_sdk::java::pick_jdk(&jdks, release).map(|j| ide_sdk::java::java_executable(&j.home))
|
||||
});
|
||||
info.java_exec = Some(java.map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|| "java".to_owned()));
|
||||
if info.error_count > 0 {
|
||||
let vm_args = project.settings.effective().languages.java.jdtls_vm_args;
|
||||
let vm_args = &settings.languages.java.jdtls_vm_args;
|
||||
let lombok = ide_sdk::lombok::lombok_agent(
|
||||
&project.root,
|
||||
ide_sdk::lombok::agent_in_args(vm_args.split_whitespace()),
|
||||
ide_tools::managed_bundle(&state.data_dir, "lombok"),
|
||||
ide_sdk::apply::maven_local_repository(&project.root, &settings),
|
||||
);
|
||||
info.hints.extend(lombok.problem());
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ pub fn builder() -> tauri_specta::Builder<tauri::Wry> {
|
||||
doc::doc_set_line_ending,
|
||||
doc::doc_outline,
|
||||
doc::doc_folding,
|
||||
doc::doc_highlights,
|
||||
doc::doc_selection_ranges,
|
||||
syntax::syntax_support,
|
||||
syntax::syntax_node_at,
|
||||
@@ -129,6 +130,7 @@ pub fn builder() -> tauri_specta::Builder<tauri::Wry> {
|
||||
lsp::apply_workspace_edit,
|
||||
lsp::lsp_execute_command,
|
||||
vcs::vcs_status,
|
||||
vcs::vcs_roots,
|
||||
vcs::vcs_branch_info,
|
||||
vcs::vcs_line_hunks,
|
||||
vcs::vcs_file_at,
|
||||
|
||||
@@ -4,11 +4,21 @@ use crate::state::AppState;
|
||||
use ide_core::{IdeError, IdeResult, RequestId};
|
||||
use ide_tools::{InstallEvent, ToolInfo, Tools};
|
||||
use tauri::ipc::Channel;
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
use tauri::{AppHandle, Manager, State, Window};
|
||||
|
||||
fn tools(app: &AppHandle) -> IdeResult<Tools> {
|
||||
/// The installer, reporting the executables chosen in the window's settings.
|
||||
fn tools(app: &AppHandle, state: &AppState, window: &Window) -> IdeResult<Tools> {
|
||||
let data = app.path().app_data_dir().map_err(|e| IdeError::internal(e.to_string()))?;
|
||||
Ok(Tools::new(&data))
|
||||
let (settings, root) = match state.project(window.label()) {
|
||||
Ok(project) => (project.settings.effective(), project.root.clone()),
|
||||
Err(_) => (state.global_settings.effective(), Default::default()),
|
||||
};
|
||||
let custom = settings
|
||||
.tools
|
||||
.iter()
|
||||
.filter_map(|(command, t)| Some((command.clone(), ide_sdk::apply::setting_path(&root, &t.path)?)))
|
||||
.collect();
|
||||
Ok(Tools::new(&data).with_custom_paths(custom))
|
||||
}
|
||||
|
||||
fn join_err(e: impl std::fmt::Display) -> IdeError {
|
||||
@@ -18,8 +28,8 @@ fn join_err(e: impl std::fmt::Display) -> IdeError {
|
||||
/// Status of every known language server / debug adapter and the languages using it.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn tools_list(app: AppHandle, state: State<'_, AppState>) -> IdeResult<Vec<ToolInfo>> {
|
||||
let tools = tools(&app)?;
|
||||
pub async fn tools_list(app: AppHandle, window: Window, state: State<'_, AppState>) -> IdeResult<Vec<ToolInfo>> {
|
||||
let tools = tools(&app, &state, &window)?;
|
||||
let langs = state.languages.all();
|
||||
tauri::async_runtime::spawn_blocking(move || tools.list(&langs)).await.map_err(join_err)
|
||||
}
|
||||
@@ -30,12 +40,13 @@ pub async fn tools_list(app: AppHandle, state: State<'_, AppState>) -> IdeResult
|
||||
#[specta::specta]
|
||||
pub async fn tools_install(
|
||||
app: AppHandle,
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
name: String,
|
||||
request: RequestId,
|
||||
on_event: Channel<InstallEvent>,
|
||||
) -> IdeResult<ToolInfo> {
|
||||
let tools = tools(&app)?;
|
||||
let tools = tools(&app, &state, &window)?;
|
||||
let langs = state.languages.all();
|
||||
let cancel = state.begin_request(request);
|
||||
let result = tauri::async_runtime::spawn_blocking(move || {
|
||||
@@ -56,8 +67,13 @@ pub async fn tools_install(
|
||||
/// Removes a tool the IDE installed.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn tools_uninstall(app: AppHandle, state: State<'_, AppState>, name: String) -> IdeResult<ToolInfo> {
|
||||
let tools = tools(&app)?;
|
||||
pub async fn tools_uninstall(
|
||||
app: AppHandle,
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
name: String,
|
||||
) -> IdeResult<ToolInfo> {
|
||||
let tools = tools(&app, &state, &window)?;
|
||||
let langs = state.languages.all();
|
||||
let info =
|
||||
tauri::async_runtime::spawn_blocking(move || tools.uninstall(&name, &langs)).await.map_err(join_err)??;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::state::AppState;
|
||||
use crate::state::{AppState, Project};
|
||||
use ide_core::{IdeResult, RequestId};
|
||||
use ide_vcs::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -13,18 +13,59 @@ pub(crate) fn apply_git_executable(settings: &ide_core::settings::Settings) {
|
||||
ide_vcs::set_git_executable((!exe.is_empty()).then(|| Path::new(exe)));
|
||||
}
|
||||
|
||||
/// Changes of every repository of the project.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_status(window: Window, state: State<'_, AppState>) -> IdeResult<Vec<FileStatus>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.status())).await
|
||||
blocking(move || {
|
||||
let settings = project.settings.effective();
|
||||
apply_git_executable(&settings);
|
||||
let repos = project.repos();
|
||||
if repos.is_empty() {
|
||||
return Err(ide_core::IdeError::unavailable("project is not a git repository"));
|
||||
}
|
||||
for r in repos.all() {
|
||||
r.set_ignored_names(settings.ignored_names());
|
||||
}
|
||||
repos.status()
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// A repository of the project (IDEA's VCS root).
|
||||
#[derive(Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct VcsRoot {
|
||||
/// Worktree root.
|
||||
pub root: ide_core::IpcPath,
|
||||
/// Merge / rebase / cherry-pick / revert in progress.
|
||||
pub operation: Option<String>,
|
||||
}
|
||||
|
||||
/// The project's repositories, the primary one first.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub fn vcs_roots(window: Window, state: State<'_, AppState>) -> IdeResult<Vec<VcsRoot>> {
|
||||
let repos = state.project(window.label())?.repos();
|
||||
let primary = repos.primary().map(|r| r.root().to_path_buf());
|
||||
let mut all: Vec<&std::sync::Arc<Repo>> = repos.all().iter().collect();
|
||||
all.sort_by_key(|r| Some(r.root()) != primary.as_deref());
|
||||
Ok(all
|
||||
.into_iter()
|
||||
.map(|r| VcsRoot { root: r.root().to_path_buf().into(), operation: r.operation().ok().flatten() })
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_branch_info(window: Window, state: State<'_, AppState>) -> IdeResult<BranchInfo> {
|
||||
pub async fn vcs_branch_info(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
) -> IdeResult<BranchInfo> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.branch_info())).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.branch_info())).await
|
||||
}
|
||||
|
||||
/// Gutter change markers for a file, computed against its current (unsaved) text.
|
||||
@@ -33,7 +74,7 @@ pub async fn vcs_branch_info(window: Window, state: State<'_, AppState>) -> IdeR
|
||||
pub fn vcs_line_hunks(window: Window, state: State<'_, AppState>, path: PathBuf) -> IdeResult<Vec<LineHunk>> {
|
||||
let project = state.project(window.label())?;
|
||||
let text = project.text_of(&path)?;
|
||||
project.with_repo(|r| r.line_hunks(&path, &text, false))
|
||||
project.with_repo_of(&path, |r| r.line_hunks(&path, &text, false))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -45,7 +86,7 @@ pub async fn vcs_file_at(
|
||||
rev: Option<String>,
|
||||
) -> IdeResult<Option<String>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.file_at(&path, rev.as_deref()))).await
|
||||
blocking(move || project.with_repo_of(&path, |r| r.file_at(&path, rev.as_deref()))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -53,14 +94,19 @@ pub async fn vcs_file_at(
|
||||
pub async fn vcs_blame(window: Window, state: State<'_, AppState>, path: PathBuf) -> IdeResult<Vec<BlameLine>> {
|
||||
let project = state.project(window.label())?;
|
||||
let text = project.documents.text_of(&path);
|
||||
blocking(move || project.with_repo(|r| r.blame(&path, text.as_deref()))).await
|
||||
blocking(move || project.with_repo_of(&path, |r| r.blame(&path, text.as_deref()))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_log(window: Window, state: State<'_, AppState>, query: LogQuery) -> IdeResult<Vec<Commit>> {
|
||||
pub async fn vcs_log(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
query: LogQuery,
|
||||
) -> IdeResult<Vec<Commit>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.log(&query))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.log(&query))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -68,38 +114,39 @@ pub async fn vcs_log(window: Window, state: State<'_, AppState>, query: LogQuery
|
||||
pub async fn vcs_commit_files(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
commit: String,
|
||||
) -> IdeResult<Vec<ChangedFile>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.commit_files(&commit))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.commit_files(&commit))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_branches(window: Window, state: State<'_, AppState>) -> IdeResult<Vec<Branch>> {
|
||||
pub async fn vcs_branches(window: Window, state: State<'_, AppState>, repo: Option<PathBuf>) -> IdeResult<Vec<Branch>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.branches())).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.branches())).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_stashes(window: Window, state: State<'_, AppState>) -> IdeResult<Vec<Stash>> {
|
||||
pub async fn vcs_stashes(window: Window, state: State<'_, AppState>, repo: Option<PathBuf>) -> IdeResult<Vec<Stash>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.stashes())).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.stashes())).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_stage(window: Window, state: State<'_, AppState>, paths: Vec<PathBuf>) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.stage(&paths))).await
|
||||
blocking(move || per_repo(&project, &paths, None, |r, paths| r.stage(paths))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_unstage(window: Window, state: State<'_, AppState>, paths: Vec<PathBuf>) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.unstage(&paths))).await
|
||||
blocking(move || per_repo(&project, &paths, None, |r, paths| r.unstage(paths))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -113,7 +160,7 @@ pub async fn vcs_stage_patch(window: Window, state: State<'_, AppState>, patch:
|
||||
#[specta::specta]
|
||||
pub async fn vcs_discard(window: Window, state: State<'_, AppState>, paths: Vec<PathBuf>) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo_recorded(Some("Rollback"), |r| r.discard(&paths))).await
|
||||
blocking(move || per_repo(&project, &paths, Some("Rollback"), |r, paths| r.discard(paths))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -121,19 +168,27 @@ pub async fn vcs_discard(window: Window, state: State<'_, AppState>, paths: Vec<
|
||||
pub async fn vcs_commit(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
message: String,
|
||||
options: CommitOptions,
|
||||
) -> IdeResult<String> {
|
||||
// Commit hooks may run for a long time.
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.commit_with(&message, &options))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.commit_with(&message, &options))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_checkout(window: Window, state: State<'_, AppState>, branch: String, create: bool) -> IdeResult<()> {
|
||||
pub async fn vcs_checkout(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
branch: String,
|
||||
create: bool,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo_recorded(Some("Git checkout"), |r| r.checkout(&branch, create))).await
|
||||
blocking(move || project.with_repo_recorded(repo.as_deref(), Some("Git checkout"), |r| r.checkout(&branch, create)))
|
||||
.await
|
||||
}
|
||||
|
||||
/// New Branch: creates `name` at `start` (HEAD when absent), optionally checking it out.
|
||||
@@ -142,22 +197,31 @@ pub async fn vcs_checkout(window: Window, state: State<'_, AppState>, branch: St
|
||||
pub async fn vcs_create_branch(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
name: String,
|
||||
start: Option<String>,
|
||||
checkout: bool,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
let recorded = checkout.then_some("Git checkout");
|
||||
blocking(move || project.with_repo_recorded(recorded, |r| r.create_branch(&name, start.as_deref(), checkout))).await
|
||||
blocking(move || {
|
||||
project.with_repo_recorded(repo.as_deref(), recorded, |r| r.create_branch(&name, start.as_deref(), checkout))
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Undo Commit: moves HEAD back to the commit's parent, keeping its changes staged.
|
||||
/// Returns the undone commit's message.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_undo_commit(window: Window, state: State<'_, AppState>, commit: String) -> IdeResult<String> {
|
||||
pub async fn vcs_undo_commit(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
commit: String,
|
||||
) -> IdeResult<String> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.undo_commit(&commit))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.undo_commit(&commit))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -165,32 +229,49 @@ pub async fn vcs_undo_commit(window: Window, state: State<'_, AppState>, commit:
|
||||
pub async fn vcs_delete_branch(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
branch: String,
|
||||
force: bool,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.delete_branch(&branch, force))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.delete_branch(&branch, force))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_rename_branch(window: Window, state: State<'_, AppState>, from: String, to: String) -> IdeResult<()> {
|
||||
pub async fn vcs_rename_branch(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
from: String,
|
||||
to: String,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.rename_branch(&from, &to))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.rename_branch(&from, &to))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_merge(window: Window, state: State<'_, AppState>, branch: String) -> IdeResult<()> {
|
||||
pub async fn vcs_merge(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
branch: String,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo_recorded(Some("Git merge"), |r| r.merge(&branch))).await
|
||||
blocking(move || project.with_repo_recorded(repo.as_deref(), Some("Git merge"), |r| r.merge(&branch))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_rebase(window: Window, state: State<'_, AppState>, onto: String) -> IdeResult<()> {
|
||||
pub async fn vcs_rebase(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
onto: String,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo_recorded(Some("Git rebase"), |r| r.rebase(&onto))).await
|
||||
blocking(move || project.with_repo_recorded(repo.as_deref(), Some("Git rebase"), |r| r.rebase(&onto))).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -198,28 +279,43 @@ pub async fn vcs_rebase(window: Window, state: State<'_, AppState>, onto: String
|
||||
pub async fn vcs_stash_push(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
message: Option<String>,
|
||||
include_untracked: bool,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || {
|
||||
project.with_repo_recorded(Some("Git stash"), |r| r.stash_push(message.as_deref(), include_untracked))
|
||||
project.with_repo_recorded(repo.as_deref(), Some("Git stash"), |r| {
|
||||
r.stash_push(message.as_deref(), include_untracked)
|
||||
})
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_stash_apply(window: Window, state: State<'_, AppState>, index: u32, pop: bool) -> IdeResult<()> {
|
||||
pub async fn vcs_stash_apply(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
index: u32,
|
||||
pop: bool,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo_recorded(Some("Git unstash"), |r| r.stash_apply(index, pop))).await
|
||||
blocking(move || project.with_repo_recorded(repo.as_deref(), Some("Git unstash"), |r| r.stash_apply(index, pop)))
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_stash_drop(window: Window, state: State<'_, AppState>, index: u32) -> IdeResult<()> {
|
||||
pub async fn vcs_stash_drop(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
index: u32,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.stash_drop(index))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.stash_drop(index))).await
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Type)]
|
||||
@@ -258,6 +354,7 @@ pub enum RemoteOp {
|
||||
pub async fn vcs_remote(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
request: RequestId,
|
||||
op: RemoteOp,
|
||||
on_output: Channel<String>,
|
||||
@@ -269,7 +366,7 @@ pub async fn vcs_remote(
|
||||
let _ = on_output.send(line);
|
||||
};
|
||||
let recorded = matches!(op, RemoteOp::Pull { .. }).then_some("Git pull");
|
||||
project.with_repo_recorded(recorded, |r| match op {
|
||||
project.with_repo_recorded(repo.as_deref(), recorded, |r| match op {
|
||||
RemoteOp::Fetch => r.fetch(&cancel, &out),
|
||||
RemoteOp::Pull { rebase } => r.pull(rebase, &cancel, &out),
|
||||
RemoteOp::Push { force_with_lease, set_upstream, tags } => {
|
||||
@@ -304,7 +401,7 @@ pub async fn vcs_conflict_versions(
|
||||
) -> IdeResult<ConflictVersions> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || {
|
||||
project.with_repo(|r| {
|
||||
project.with_repo_of(&path, |r| {
|
||||
r.conflict_versions(&path).map(|(base, ours, theirs)| ConflictVersions { base, ours, theirs })
|
||||
})
|
||||
})
|
||||
@@ -320,7 +417,7 @@ pub async fn vcs_diff_text(
|
||||
staged: bool,
|
||||
) -> IdeResult<String> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.diff_text(&path, staged))).await
|
||||
blocking(move || project.with_repo_of(&path, |r| r.diff_text(&path, staged))).await
|
||||
}
|
||||
|
||||
/// Line hunks between two arbitrary texts (diff viewer, commit dialog).
|
||||
@@ -337,7 +434,7 @@ pub fn vcs_diff_hunks(old_text: String, new_text: String) -> Vec<LineHunk> {
|
||||
pub fn vcs_stage_hunks(window: Window, state: State<'_, AppState>, path: PathBuf, hunks: Vec<u32>) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
let current = ide_vfs::load_text(&path)?.text;
|
||||
project.with_repo(|r| {
|
||||
project.with_repo_of(&path, |r| {
|
||||
let index_text = r.file_at(&path, Some(":0"))?.unwrap_or_default();
|
||||
let rel = path.strip_prefix(r.root()).unwrap_or(&path).to_string_lossy().replace('\\', "/");
|
||||
let selected: Vec<usize> = hunks.iter().map(|&h| h as usize).collect();
|
||||
@@ -408,9 +505,14 @@ pub fn vcs_detected_git() -> Option<String> {
|
||||
/// `git config --get <key>` in the project repository; `None` when unset.
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_config_get(window: Window, state: State<'_, AppState>, key: String) -> IdeResult<Option<String>> {
|
||||
pub async fn vcs_config_get(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
key: String,
|
||||
) -> IdeResult<Option<String>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.config_get(&key))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.config_get(&key))).await
|
||||
}
|
||||
|
||||
// ---- in-progress operations, history rewriting (Git Log actions) ----
|
||||
@@ -448,6 +550,7 @@ pub enum GitOperation {
|
||||
pub async fn vcs_operation(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
request: RequestId,
|
||||
op: GitOperation,
|
||||
on_output: Channel<String>,
|
||||
@@ -465,7 +568,7 @@ pub async fn vcs_operation(
|
||||
GitOperation::InteractiveRebase { .. } => Some("Git rebase"),
|
||||
_ => None,
|
||||
};
|
||||
project.with_repo_recorded(recorded, |r| match op {
|
||||
project.with_repo_recorded(repo.as_deref(), recorded, |r| match op {
|
||||
GitOperation::Continue => r.continue_operation(&cancel, &out),
|
||||
GitOperation::Abort => r.abort_operation(&cancel, &out),
|
||||
GitOperation::Skip => r.skip_operation(&cancel, &out),
|
||||
@@ -488,20 +591,22 @@ pub async fn vcs_operation(
|
||||
pub async fn vcs_create_tag(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
name: String,
|
||||
commit: String,
|
||||
message: Option<String>,
|
||||
force: bool,
|
||||
) -> IdeResult<()> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.create_tag(&name, &commit, message.as_deref(), force))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.create_tag(&name, &commit, message.as_deref(), force)))
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn vcs_tags(window: Window, state: State<'_, AppState>) -> IdeResult<Vec<String>> {
|
||||
pub async fn vcs_tags(window: Window, state: State<'_, AppState>, repo: Option<PathBuf>) -> IdeResult<Vec<String>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.tags())).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.tags())).await
|
||||
}
|
||||
|
||||
/// Compare with Local: tracked files that differ between `rev` and the working tree.
|
||||
@@ -510,10 +615,42 @@ pub async fn vcs_tags(window: Window, state: State<'_, AppState>) -> IdeResult<V
|
||||
pub async fn vcs_diff_with_worktree(
|
||||
window: Window,
|
||||
state: State<'_, AppState>,
|
||||
repo: Option<PathBuf>,
|
||||
rev: String,
|
||||
) -> IdeResult<Vec<ChangedFile>> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || project.with_repo(|r| r.diff_with_worktree(&rev))).await
|
||||
blocking(move || project.with_repo_at(repo.as_deref(), |r| r.diff_with_worktree(&rev))).await
|
||||
}
|
||||
|
||||
/// Runs `f` once per repository with the `paths` that belong to it.
|
||||
fn per_repo(
|
||||
project: &Project,
|
||||
paths: &[PathBuf],
|
||||
recorded: Option<&str>,
|
||||
f: impl Fn(&Repo, &[PathBuf]) -> IdeResult<()>,
|
||||
) -> IdeResult<()> {
|
||||
let groups = project.repos().group(paths);
|
||||
if groups.is_empty() {
|
||||
return project.with_repo_recorded(None, recorded, |r| f(r, paths));
|
||||
}
|
||||
for (repo, paths) in groups {
|
||||
project.with_repo_recorded(Some(repo.root()), recorded, |r| f(r, &paths))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Shelf and patches work in the primary repository only: changes of a nested one
|
||||
/// fail instead of being left out silently.
|
||||
fn in_primary_repo(project: &Project, paths: &[PathBuf]) -> IdeResult<()> {
|
||||
let repos = project.repos();
|
||||
let primary = repos.primary().map(|r| r.root());
|
||||
match paths.iter().find(|p| repos.for_path(p).map(|r| r.root()) != primary) {
|
||||
Some(p) => Err(ide_core::IdeError::invalid(format!(
|
||||
"{} is in another git repository; shelving and patches support the project's main repository only",
|
||||
p.display()
|
||||
))),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn blocking<T: Send + 'static>(f: impl FnOnce() -> IdeResult<T> + Send + 'static) -> IdeResult<T> {
|
||||
@@ -539,6 +676,7 @@ pub async fn vcs_create_patch(window: Window, state: State<'_, AppState>, source
|
||||
project.with_repo(|r| match source {
|
||||
PatchSource::Changes { paths, reverse } => {
|
||||
let paths: Vec<PathBuf> = paths.into_iter().map(Into::into).collect();
|
||||
in_primary_repo(&project, &paths)?;
|
||||
r.create_patch(&paths, reverse)
|
||||
}
|
||||
PatchSource::Commits { commits, reverse } => r.create_commits_patch(&commits, reverse),
|
||||
@@ -586,8 +724,9 @@ pub async fn vcs_shelve(
|
||||
) -> IdeResult<ShelvedChangeList> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || {
|
||||
in_primary_repo(&project, &paths)?;
|
||||
keep_private(&project.root);
|
||||
project.with_repo_recorded(Some("Shelve"), |r| r.shelve(&shelf_dir(&project.root), &name, &paths))
|
||||
project.with_repo_recorded(None, Some("Shelve"), |r| r.shelve(&shelf_dir(&project.root), &name, &paths))
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -611,7 +750,7 @@ pub async fn vcs_unshelve(
|
||||
) -> IdeResult<ApplyOutcome> {
|
||||
let project = state.project(window.label())?;
|
||||
blocking(move || {
|
||||
project.with_repo_recorded(Some("Unshelve"), |r| r.unshelve(&shelf_dir(&project.root), &id, remove))
|
||||
project.with_repo_recorded(None, Some("Unshelve"), |r| r.unshelve(&shelf_dir(&project.root), &id, remove))
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use ide_run::ProcessManager;
|
||||
use ide_syntax::StructureService;
|
||||
use ide_terminal::TerminalManager;
|
||||
use ide_text::{AppliedChange, ByteEdit};
|
||||
use ide_vcs::Repo;
|
||||
use ide_vcs::{Repo, Repos};
|
||||
use ide_vfs::Watcher;
|
||||
use ide_workspace::documents::DocumentObserver;
|
||||
use ide_workspace::{
|
||||
@@ -56,7 +56,8 @@ pub struct Project {
|
||||
pub moves: FileMoves,
|
||||
pub index: Arc<ProjectIndex>,
|
||||
pub lsp: Arc<LspManager>,
|
||||
pub repo: Mutex<Option<Repo>>,
|
||||
/// Git repositories: the one containing the project root and those nested below it.
|
||||
pub repos: Arc<RwLock<Repos>>,
|
||||
/// Incrementally maintained syntax trees of the open documents.
|
||||
pub syntax: Arc<SyntaxCache>,
|
||||
/// Tree-sitter structure queries (LSP fallback) over `syntax`.
|
||||
@@ -242,7 +243,8 @@ impl AppState {
|
||||
let root = root.clone();
|
||||
let data_dir = self.data_dir.clone();
|
||||
lsp.set_config_hook(Box::new(move |cfg, server_root| {
|
||||
ide_sdk::apply::configure_server(cfg, &root, server_root, &settings.effective());
|
||||
let effective = settings.effective();
|
||||
ide_sdk::apply::configure_server(cfg, &root, server_root, &effective);
|
||||
if cfg.name == "jdtls" {
|
||||
let bundles: Vec<PathBuf> =
|
||||
ide_tools::managed_bundle(&data_dir, "java-debug").into_iter().collect();
|
||||
@@ -252,6 +254,7 @@ impl AppState {
|
||||
server_root,
|
||||
ide_sdk::lombok::agent_in_args(cfg.args.iter().map(String::as_str)),
|
||||
ide_tools::managed_bundle(&data_dir, "lombok"),
|
||||
ide_sdk::apply::maven_local_repository(&root, &effective),
|
||||
);
|
||||
if let Some(problem) = lombok.problem() {
|
||||
tracing::warn!("{problem}");
|
||||
@@ -261,6 +264,7 @@ impl AppState {
|
||||
server_root,
|
||||
&data_dir,
|
||||
&jdks,
|
||||
ide_sdk::apply::project_jdk(&root, &effective).as_ref(),
|
||||
min_java,
|
||||
&bundles,
|
||||
lombok.jar(),
|
||||
@@ -277,7 +281,10 @@ impl AppState {
|
||||
documents.add_observer(Arc::new(LspObserver(lsp.clone())));
|
||||
documents.add_observer(Arc::new(HistoryObserver(history.clone())));
|
||||
|
||||
let repos = Arc::new(RwLock::new(Repos::enclosing(&root)?));
|
||||
let watcher = {
|
||||
let repos = repos.clone();
|
||||
let settings = settings.clone();
|
||||
let index = index.clone();
|
||||
let documents = documents.clone();
|
||||
let sink = sink.clone();
|
||||
@@ -303,6 +310,19 @@ impl AppState {
|
||||
sink.emit(IdeEvent::ProjectRootsChanged { root: root.clone().into() });
|
||||
}
|
||||
}
|
||||
// A repository was cloned / initialised / removed below the project: its
|
||||
// `.git/HEAD` (the watcher reports nothing else of `.git`) appeared or went.
|
||||
let known = repos.read().roots();
|
||||
let git_dirs = changed.iter().chain(&batch.removed).any(|p| {
|
||||
let Some(dir) = p.ends_with(".git/HEAD").then(|| p.parent().and_then(Path::parent)).flatten()
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
known.iter().any(|r| r == dir) != p.is_file()
|
||||
});
|
||||
if git_dirs {
|
||||
scan_repositories(&root, &repos, &settings, &sink);
|
||||
}
|
||||
sink.emit(IdeEvent::VcsChanged { root: root.clone().into() });
|
||||
}),
|
||||
)?
|
||||
@@ -329,8 +349,13 @@ impl AppState {
|
||||
};
|
||||
|
||||
mark("watcher");
|
||||
let repo = Repo::discover(&root)?;
|
||||
let branch = repo.as_ref().and_then(|r| r.branch_info().ok()).and_then(|b| b.head);
|
||||
let branch = repos.read().primary().and_then(|r| r.branch_info().ok()).and_then(|b| b.head);
|
||||
{
|
||||
let (root, repos, settings, sink) = (root.clone(), repos.clone(), settings.clone(), sink.clone());
|
||||
std::thread::Builder::new()
|
||||
.name("openidea-vcs-roots".into())
|
||||
.spawn(move || scan_repositories(&root, &repos, &settings, &sink))?;
|
||||
}
|
||||
mark("git");
|
||||
self.recent.touch(&root, branch)?;
|
||||
mark("recent");
|
||||
@@ -347,7 +372,7 @@ impl AppState {
|
||||
moves: FileMoves::new(),
|
||||
index,
|
||||
lsp,
|
||||
repo: Mutex::new(repo),
|
||||
repos,
|
||||
structure: Arc::new(StructureService::new(syntax.clone())),
|
||||
syntax,
|
||||
detected_roots,
|
||||
@@ -389,18 +414,65 @@ impl AppState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Looks for repositories nested below the project (and the one containing it);
|
||||
/// emits `VcsChanged` when the set of roots changed.
|
||||
fn scan_repositories(root: &Path, repos: &RwLock<Repos>, settings: &SettingsStore, sink: &SharedSink) {
|
||||
let ignored = settings.effective().ignored_names();
|
||||
let skip = |p: &Path| p.file_name().is_some_and(|n| ignored.is_ignored_name(&n.to_string_lossy()));
|
||||
match Repos::discover(root, &skip) {
|
||||
Ok(found) => {
|
||||
if found.roots() != repos.read().roots() {
|
||||
*repos.write() = found;
|
||||
sink.emit(IdeEvent::VcsChanged { root: root.to_path_buf().into() });
|
||||
}
|
||||
}
|
||||
Err(e) => tracing::warn!("looking for git repositories: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
impl Project {
|
||||
/// Runs `f` with the git repository, or fails when the project is not under git.
|
||||
pub fn with_repo<T>(&self, f: impl FnOnce(&Repo) -> IdeResult<T>) -> IdeResult<T> {
|
||||
/// The project's git repositories.
|
||||
pub fn repos(&self) -> Repos {
|
||||
self.repos.read().clone()
|
||||
}
|
||||
|
||||
/// Runs `f` with the repository whose root is `at`, the project's primary repository
|
||||
/// when `None`; fails when there is none (a repository-scoped command never falls back
|
||||
/// to another repository).
|
||||
pub fn with_repo_at<T>(&self, at: Option<&Path>, f: impl FnOnce(&Repo) -> IdeResult<T>) -> IdeResult<T> {
|
||||
let repos = self.repos();
|
||||
match at {
|
||||
Some(root) => match repos.at_root(root) {
|
||||
Some(repo) => self.run_in(repo, f),
|
||||
None => {
|
||||
Err(IdeError::unavailable(format!("{} is not a git repository of the project", root.display())))
|
||||
}
|
||||
},
|
||||
None => match repos.primary() {
|
||||
Some(repo) => self.run_in(repo, f),
|
||||
None => Err(IdeError::unavailable("project is not a git repository")),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs `f` with the repository `path` (a file or folder) belongs to.
|
||||
pub fn with_repo_of<T>(&self, path: &Path, f: impl FnOnce(&Repo) -> IdeResult<T>) -> IdeResult<T> {
|
||||
match self.repos().for_path(path) {
|
||||
Some(repo) => self.run_in(repo, f),
|
||||
None => Err(IdeError::unavailable(format!("{} is not in a git repository", path.display()))),
|
||||
}
|
||||
}
|
||||
|
||||
fn run_in<T>(&self, repo: &Repo, f: impl FnOnce(&Repo) -> IdeResult<T>) -> IdeResult<T> {
|
||||
let settings = self.settings.effective();
|
||||
crate::commands::vcs::apply_git_executable(&settings);
|
||||
match self.repo.lock().as_ref() {
|
||||
Some(repo) => {
|
||||
repo.set_ignored_names(settings.ignored_names());
|
||||
f(repo)
|
||||
}
|
||||
None => Err(IdeError::unavailable("project is not a git repository")),
|
||||
}
|
||||
repo.set_ignored_names(settings.ignored_names());
|
||||
f(repo)
|
||||
}
|
||||
|
||||
/// Runs `f` with the project's primary git repository, or fails when the project is not under git.
|
||||
pub fn with_repo<T>(&self, f: impl FnOnce(&Repo) -> IdeResult<T>) -> IdeResult<T> {
|
||||
self.with_repo_at(None, f)
|
||||
}
|
||||
|
||||
/// Runs a VCS operation that rewrites the working tree (checkout, merge,
|
||||
@@ -409,19 +481,20 @@ impl Project {
|
||||
/// `None` runs `f` like [`with_repo`](Self::with_repo) (operations that keep the working tree).
|
||||
pub fn with_repo_recorded<T>(
|
||||
&self,
|
||||
at: Option<&Path>,
|
||||
operation: Option<&str>,
|
||||
f: impl FnOnce(&Repo) -> IdeResult<T>,
|
||||
) -> IdeResult<T> {
|
||||
let Some(name) = operation else { return self.with_repo(f) };
|
||||
let Some(name) = operation else { return self.with_repo_at(at, f) };
|
||||
self.history_label(&format!("Before {name}"));
|
||||
if let Ok(changed) = self.with_repo(|r| r.status()) {
|
||||
if let Ok(changed) = self.with_repo_at(at, |r| r.status()) {
|
||||
for file in changed.iter().take(HISTORY_BATCH_LIMIT) {
|
||||
if let Err(e) = self.history.record_file(&file.path, &format!("Before {name}"), false) {
|
||||
tracing::debug!("local history: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
let result = self.with_repo(f);
|
||||
let result = self.with_repo_at(at, f);
|
||||
self.history_label(&format!("After {name}"));
|
||||
result
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "OpenIDEA",
|
||||
"version": "0.1.5",
|
||||
"version": "0.1.8",
|
||||
"identifier": "ai.l0ng.openidea",
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
|
||||
+93
-24
@@ -92,6 +92,11 @@ export const commands = {
|
||||
*/
|
||||
docOutline: (doc: DocId) => typedError<OutlineItem[], IdeError>(__TAURI_INVOKE("doc_outline", { doc })),
|
||||
docFolding: (doc: DocId) => typedError<FoldRange[], IdeError>(__TAURI_INVOKE("doc_folding", { doc })),
|
||||
/**
|
||||
* Tree-sitter highlighting for languages the UI has no CodeMirror mode for;
|
||||
* empty when the grammar has no highlights query or the document is large.
|
||||
*/
|
||||
docHighlights: (doc: DocId) => typedError<SyntaxHighlights, IdeError>(__TAURI_INVOKE("doc_highlights", { doc })),
|
||||
/**
|
||||
* Extend Selection (⌥↑): syntax ranges around `offset`, innermost first.
|
||||
* Large documents fall back to word / line / document ranges.
|
||||
@@ -249,38 +254,41 @@ export const commands = {
|
||||
* follow-up command. Edits the server requests arrive via `workspace/applyEdit`.
|
||||
*/
|
||||
lspExecuteCommand: (doc: DocId, command: Command) => typedError<null, IdeError>(__TAURI_INVOKE("lsp_execute_command", { doc, command })),
|
||||
/** Changes of every repository of the project. */
|
||||
vcsStatus: () => typedError<FileStatus[], IdeError>(__TAURI_INVOKE("vcs_status")),
|
||||
vcsBranchInfo: () => typedError<BranchInfo, IdeError>(__TAURI_INVOKE("vcs_branch_info")),
|
||||
/** The project's repositories, the primary one first. */
|
||||
vcsRoots: () => typedError<VcsRoot[], IdeError>(__TAURI_INVOKE("vcs_roots")),
|
||||
vcsBranchInfo: (repo: string | null) => typedError<BranchInfo, IdeError>(__TAURI_INVOKE("vcs_branch_info", { repo })),
|
||||
/** Gutter change markers for a file, computed against its current (unsaved) text. */
|
||||
vcsLineHunks: (path: string) => typedError<LineHunk[], IdeError>(__TAURI_INVOKE("vcs_line_hunks", { path })),
|
||||
vcsFileAt: (path: string, rev: string | null) => typedError<string | null, IdeError>(__TAURI_INVOKE("vcs_file_at", { path, rev })),
|
||||
vcsBlame: (path: string) => typedError<BlameLine[], IdeError>(__TAURI_INVOKE("vcs_blame", { path })),
|
||||
vcsLog: (query: LogQuery) => typedError<Commit[], IdeError>(__TAURI_INVOKE("vcs_log", { query })),
|
||||
vcsCommitFiles: (commit: string) => typedError<ChangedFile[], IdeError>(__TAURI_INVOKE("vcs_commit_files", { commit })),
|
||||
vcsBranches: () => typedError<Branch[], IdeError>(__TAURI_INVOKE("vcs_branches")),
|
||||
vcsStashes: () => typedError<Stash[], IdeError>(__TAURI_INVOKE("vcs_stashes")),
|
||||
vcsLog: (repo: string | null, query: LogQuery) => typedError<Commit[], IdeError>(__TAURI_INVOKE("vcs_log", { repo, query })),
|
||||
vcsCommitFiles: (repo: string | null, commit: string) => typedError<ChangedFile[], IdeError>(__TAURI_INVOKE("vcs_commit_files", { repo, commit })),
|
||||
vcsBranches: (repo: string | null) => typedError<Branch[], IdeError>(__TAURI_INVOKE("vcs_branches", { repo })),
|
||||
vcsStashes: (repo: string | null) => typedError<Stash[], IdeError>(__TAURI_INVOKE("vcs_stashes", { repo })),
|
||||
vcsStage: (paths: string[]) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_stage", { paths })),
|
||||
vcsUnstage: (paths: string[]) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_unstage", { paths })),
|
||||
vcsStagePatch: (patch: string) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_stage_patch", { patch })),
|
||||
vcsDiscard: (paths: string[]) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_discard", { paths })),
|
||||
vcsCommit: (message: string, options: CommitOptions) => typedError<string, IdeError>(__TAURI_INVOKE("vcs_commit", { message, options })),
|
||||
vcsCheckout: (branch: string, create: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_checkout", { branch, create })),
|
||||
vcsDeleteBranch: (branch: string, force: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_delete_branch", { branch, force })),
|
||||
vcsCommit: (repo: string | null, message: string, options: CommitOptions) => typedError<string, IdeError>(__TAURI_INVOKE("vcs_commit", { repo, message, options })),
|
||||
vcsCheckout: (repo: string | null, branch: string, create: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_checkout", { repo, branch, create })),
|
||||
vcsDeleteBranch: (repo: string | null, branch: string, force: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_delete_branch", { repo, branch, force })),
|
||||
/** New Branch: creates `name` at `start` (HEAD when absent), optionally checking it out. */
|
||||
vcsCreateBranch: (name: string, start: string | null, checkout: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_create_branch", { name, start, checkout })),
|
||||
vcsCreateBranch: (repo: string | null, name: string, start: string | null, checkout: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_create_branch", { repo, name, start, checkout })),
|
||||
/**
|
||||
* Undo Commit: moves HEAD back to the commit's parent, keeping its changes staged.
|
||||
* Returns the undone commit's message.
|
||||
*/
|
||||
vcsUndoCommit: (commit: string) => typedError<string, IdeError>(__TAURI_INVOKE("vcs_undo_commit", { commit })),
|
||||
vcsRenameBranch: (from: string, to: string) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_rename_branch", { from, to })),
|
||||
vcsMerge: (branch: string) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_merge", { branch })),
|
||||
vcsRebase: (onto: string) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_rebase", { onto })),
|
||||
vcsStashPush: (message: string | null, includeUntracked: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_stash_push", { message, includeUntracked })),
|
||||
vcsStashApply: (index: number, pop: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_stash_apply", { index, pop })),
|
||||
vcsStashDrop: (index: number) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_stash_drop", { index })),
|
||||
vcsUndoCommit: (repo: string | null, commit: string) => typedError<string, IdeError>(__TAURI_INVOKE("vcs_undo_commit", { repo, commit })),
|
||||
vcsRenameBranch: (repo: string | null, from: string, to: string) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_rename_branch", { repo, from, to })),
|
||||
vcsMerge: (repo: string | null, branch: string) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_merge", { repo, branch })),
|
||||
vcsRebase: (repo: string | null, onto: string) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_rebase", { repo, onto })),
|
||||
vcsStashPush: (repo: string | null, message: string | null, includeUntracked: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_stash_push", { repo, message, includeUntracked })),
|
||||
vcsStashApply: (repo: string | null, index: number, pop: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_stash_apply", { repo, index, pop })),
|
||||
vcsStashDrop: (repo: string | null, index: number) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_stash_drop", { repo, index })),
|
||||
/** Network operation; progress lines stream through `on_output`. Cancellable. */
|
||||
vcsRemote: (request: RequestId, op: RemoteOp, onOutput: Channel<string>) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_remote", { request, op, onOutput })),
|
||||
vcsRemote: (repo: string | null, request: RequestId, op: RemoteOp, onOutput: Channel<string>) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_remote", { repo, request, op, onOutput })),
|
||||
vcsConflictVersions: (path: string) => typedError<ConflictVersions, IdeError>(__TAURI_INVOKE("vcs_conflict_versions", { path })),
|
||||
vcsDiffText: (path: string, staged: boolean) => typedError<string, IdeError>(__TAURI_INVOKE("vcs_diff_text", { path, staged })),
|
||||
/** Line hunks between two arbitrary texts (diff viewer, commit dialog). */
|
||||
@@ -300,16 +308,16 @@ export const commands = {
|
||||
/** The auto-detected git executable (shown as the field's placeholder). */
|
||||
vcsDetectedGit: () => __TAURI_INVOKE<string | null>("vcs_detected_git"),
|
||||
/** `git config --get <key>` in the project repository; `None` when unset. */
|
||||
vcsConfigGet: (key: string) => typedError<string | null, IdeError>(__TAURI_INVOKE("vcs_config_get", { key })),
|
||||
vcsConfigGet: (repo: string | null, key: string) => typedError<string | null, IdeError>(__TAURI_INVOKE("vcs_config_get", { repo, key })),
|
||||
/**
|
||||
* Local history operation that may take a while (hooks, large checkouts); git's
|
||||
* output streams through `on_output`. Cancellable.
|
||||
*/
|
||||
vcsOperation: (request: RequestId, op: GitOperation, onOutput: Channel<string>) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_operation", { request, op, onOutput })),
|
||||
vcsCreateTag: (name: string, commit: string, message: string | null, force: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_create_tag", { name, commit, message, force })),
|
||||
vcsTags: () => typedError<string[], IdeError>(__TAURI_INVOKE("vcs_tags")),
|
||||
vcsOperation: (repo: string | null, request: RequestId, op: GitOperation, onOutput: Channel<string>) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_operation", { repo, request, op, onOutput })),
|
||||
vcsCreateTag: (repo: string | null, name: string, commit: string, message: string | null, force: boolean) => typedError<null, IdeError>(__TAURI_INVOKE("vcs_create_tag", { repo, name, commit, message, force })),
|
||||
vcsTags: (repo: string | null) => typedError<string[], IdeError>(__TAURI_INVOKE("vcs_tags", { repo })),
|
||||
/** Compare with Local: tracked files that differ between `rev` and the working tree. */
|
||||
vcsDiffWithWorktree: (rev: string) => typedError<ChangedFile[], IdeError>(__TAURI_INVOKE("vcs_diff_with_worktree", { rev })),
|
||||
vcsDiffWithWorktree: (repo: string | null, rev: string) => typedError<ChangedFile[], IdeError>(__TAURI_INVOKE("vcs_diff_with_worktree", { repo, rev })),
|
||||
vcsCreatePatch: (source: PatchSource) => typedError<string, IdeError>(__TAURI_INVOKE("vcs_create_patch", { source })),
|
||||
vcsPatchPreview: (patch: string) => typedError<PatchFile[], IdeError>(__TAURI_INVOKE("vcs_patch_preview", { patch })),
|
||||
vcsApplyPatch: (patch: string) => typedError<ApplyOutcome, IdeError>(__TAURI_INVOKE("vcs_apply_patch", { patch })),
|
||||
@@ -2341,11 +2349,18 @@ export type JavaLaunchInfo = {
|
||||
};
|
||||
|
||||
export type JavaSettings = {
|
||||
/**
|
||||
* Project JDK home; empty = per module, the installed JDK matching the
|
||||
* Java version it targets.
|
||||
*/
|
||||
jdk?: string,
|
||||
/**
|
||||
* Extra JVM options for the Java language server (jdtls), space-separated
|
||||
* (VS Code's `java.jdt.ls.vmargs`).
|
||||
*/
|
||||
jdtlsVmArgs?: string,
|
||||
/** Build Tools › Maven. */
|
||||
maven?: MavenSettings,
|
||||
};
|
||||
|
||||
/** Editor › Code Style › <Language> › Tabs and Indents (unset fields inherit). */
|
||||
@@ -2635,10 +2650,22 @@ export type MavenProject = {
|
||||
javaVersion: number | null,
|
||||
/** Maven launcher: the nearest `mvnw` up to the project root (absolute), else `mvn`. */
|
||||
command: string,
|
||||
/** Options before the goals (`-s`, `-Dmaven.repo.local=`); filled in by the shell from settings. */
|
||||
options: string[],
|
||||
/** Environment for runs (`JAVA_HOME` of the matching JDK); filled in by the shell. */
|
||||
env: { [key in string]: string },
|
||||
};
|
||||
|
||||
/** Build Tools › Maven. */
|
||||
export type MavenSettings = {
|
||||
/** Maven home (or its `mvn` executable); empty = the project's `mvnw`, else `mvn` on `PATH`. */
|
||||
home?: string,
|
||||
/** User `settings.xml` (`-s`); empty = `~/.m2/settings.xml`. */
|
||||
userSettings?: string,
|
||||
/** Local repository (`-Dmaven.repo.local`); empty = from `settings.xml`. */
|
||||
localRepository?: string,
|
||||
};
|
||||
|
||||
export type MemoryCategory =
|
||||
/** The backend and its WebView processes. */
|
||||
"app" | "languageServer" |
|
||||
@@ -3281,7 +3308,11 @@ export type Sdk = {
|
||||
/** What [`detect`] looks for. */
|
||||
export type SdkKind = "python" | "node" |
|
||||
/** npm / pnpm / yarn executables. */
|
||||
"packageManager" | "rust" | "go" | "typeScript";
|
||||
"packageManager" | "rust" | "go" | "typeScript" |
|
||||
/** JDK homes. */
|
||||
"jdk" |
|
||||
/** Maven homes. */
|
||||
"maven";
|
||||
|
||||
export type SearchEvent = { type: "file"; file: FileMatches } | { type: "done"; summary: SearchSummary };
|
||||
|
||||
@@ -3390,6 +3421,11 @@ export type Settings_Deserialize = {
|
||||
terminal?: TerminalSettings,
|
||||
actionsOnSave?: ActionsOnSaveSettings,
|
||||
externalTools?: ExternalTool[],
|
||||
/**
|
||||
* Language servers / debug adapters at a user-chosen location, by the
|
||||
* command the language definition launches (`elixir-ls`, `codelldb`).
|
||||
*/
|
||||
tools?: { [key in string]: ToolSettings },
|
||||
};
|
||||
|
||||
export type Settings_Serialize = {
|
||||
@@ -3423,6 +3459,11 @@ export type Settings_Serialize = {
|
||||
terminal: TerminalSettings,
|
||||
actionsOnSave: ActionsOnSaveSettings,
|
||||
externalTools: ExternalTool[],
|
||||
/**
|
||||
* Language servers / debug adapters at a user-chosen location, by the
|
||||
* command the language definition launches (`elixir-ls`, `codelldb`).
|
||||
*/
|
||||
tools: { [key in string]: ToolSettings },
|
||||
};
|
||||
|
||||
export type Severity = "error" | "warning" | "info" | "hint";
|
||||
@@ -3657,6 +3698,17 @@ export type SyntaxErrors = {
|
||||
truncated: boolean,
|
||||
};
|
||||
|
||||
/** Highlight classes sent to the UI, which maps each onto a Lezer tag. */
|
||||
export type SyntaxHighlightKind = "keyword" | "string" | "stringSpecial" | "escape" | "regexp" | "atom" | "number" | "constant" | "comment" | "docComment" | "function" | "functionCall" | "builtin" | "type" | "namespace" | "variable" | "selfVariable" | "property" | "attribute" | "macro" | "label" | "tag" | "operator" | "punctuation";
|
||||
|
||||
/** Highlighted ranges of a whole document, packed like LSP semantic tokens. */
|
||||
export type SyntaxHighlights = {
|
||||
/** Legend: `data` kind `i` is `kinds[i]`. */
|
||||
kinds: SyntaxHighlightKind[],
|
||||
/** `[from, to, kind]` triples: sorted, non-overlapping UTF-16 offsets. */
|
||||
data: number[],
|
||||
};
|
||||
|
||||
/** One tree-sitter node. */
|
||||
export type SyntaxNode = {
|
||||
/** Grammar node kind, e.g. `method_invocation`, `identifier`, `;`. */
|
||||
@@ -3818,17 +3870,26 @@ export type ToolInfo = {
|
||||
/** Manual install instructions from the language definition. */
|
||||
installHint: string | null,
|
||||
homepage: string | null,
|
||||
/** Why the executable chosen in settings cannot be used (status is then `Missing`). */
|
||||
customError: string | null,
|
||||
};
|
||||
|
||||
export type ToolKind = "languageServer" | "debugger" |
|
||||
/** Loaded into another tool's process, e.g. a jdtls agent. */
|
||||
"plugin";
|
||||
|
||||
export type ToolSettings = {
|
||||
/** Executable to launch instead of the managed / `PATH` one; empty = auto-detect. */
|
||||
path?: string,
|
||||
};
|
||||
|
||||
export type ToolStatus =
|
||||
/** Installed by the IDE (managed tools dir or a toolchain component it manages). */
|
||||
"installed" |
|
||||
/** Found on the system `PATH`. */
|
||||
"onPath" | "missing";
|
||||
"onPath" |
|
||||
/** The executable chosen in settings. */
|
||||
"custom" | "missing";
|
||||
|
||||
export type TypeScriptSettings = {
|
||||
/**
|
||||
@@ -3874,6 +3935,14 @@ export type VcsConfirmationSettings = {
|
||||
onDelete?: string,
|
||||
};
|
||||
|
||||
/** A repository of the project (IDEA's VCS root). */
|
||||
export type VcsRoot = {
|
||||
/** Worktree root. */
|
||||
root: IpcPath,
|
||||
/** Merge / rebase / cherry-pick / revert in progress. */
|
||||
operation: string | null,
|
||||
};
|
||||
|
||||
/** Version Control (main page) and its sub-pages. */
|
||||
export type VcsSettings = {
|
||||
/** Colour folders that contain changed files (project tree, tabs). */
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
type LineEnding,
|
||||
type OutlineItem,
|
||||
type Range,
|
||||
type SyntaxHighlights,
|
||||
type TextChange,
|
||||
} from "@/platform/ipc";
|
||||
|
||||
@@ -43,6 +44,8 @@ export interface DocBackend {
|
||||
setEncoding(doc: DocId, encoding: string, reload: boolean): Promise<string>;
|
||||
outline(doc: DocId): Promise<OutlineItem[]>;
|
||||
folding(doc: DocId): Promise<FoldRange[]>;
|
||||
/** Tree-sitter highlighting, for languages without a CodeMirror mode. */
|
||||
highlights(doc: DocId): Promise<SyntaxHighlights>;
|
||||
selectionRanges(doc: DocId, offset: number): Promise<Range[]>;
|
||||
languages(): Promise<LanguageInfo[]>;
|
||||
onPatched(handler: (e: DocPatchedEvent) => void): () => void;
|
||||
@@ -62,6 +65,7 @@ export const ipcBackend: DocBackend = {
|
||||
setEncoding: (doc, encoding, reload) => call(commands.docSetEncoding(doc, encoding, reload)),
|
||||
outline: (doc) => call(commands.docOutline(doc)),
|
||||
folding: (doc) => call(commands.docFolding(doc)),
|
||||
highlights: (doc) => call(commands.docHighlights(doc)),
|
||||
selectionRanges: (doc, offset) => call(commands.docSelectionRanges(doc, offset)),
|
||||
languages: () => commands.languages(),
|
||||
onPatched: (h) => onIdeEvent("docPatched", (e) => h(e)),
|
||||
@@ -343,6 +347,9 @@ export function createMemoryBackend(files: Record<string, string> = {}): MemoryB
|
||||
}
|
||||
return items;
|
||||
},
|
||||
async highlights() {
|
||||
return { kinds: [], data: [] };
|
||||
},
|
||||
async folding(doc) {
|
||||
const d = get(doc);
|
||||
const out: FoldRange[] = [];
|
||||
|
||||
@@ -25,6 +25,7 @@ import { openideaTheme } from "./theme";
|
||||
import { caretRowHighlight } from "./caretRow";
|
||||
import { changeLane, overviewLane } from "./lanes";
|
||||
import { foldingExtension } from "./folding";
|
||||
import { syntaxHighlightField } from "./syntaxHighlight";
|
||||
import { indentGuides } from "./indentGuides";
|
||||
import { stickyMaxLines, stickyScroll } from "./stickyScroll";
|
||||
import { findExtension } from "./find";
|
||||
@@ -267,6 +268,7 @@ export function baseExtensions(o: SetupOptions): Extension {
|
||||
clipboardHistoryExtension,
|
||||
indentOnInput(),
|
||||
syntaxHighlighting(openideaHighlightStyle),
|
||||
syntaxHighlightField,
|
||||
closeBrackets(),
|
||||
caretRowHighlight,
|
||||
fontZoom,
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { highlightingFor, syntaxHighlighting } from "@codemirror/language";
|
||||
import { tags as t } from "@lezer/highlight";
|
||||
import { openideaHighlightStyle } from "./highlight";
|
||||
import { setSyntaxHighlights, syntaxHighlightField } from "./syntaxHighlight";
|
||||
|
||||
function marks(state: EditorState) {
|
||||
const out: { text: string; cls: string }[] = [];
|
||||
state.field(syntaxHighlightField).between(0, state.doc.length, (from, to, d) => {
|
||||
out.push({ text: state.doc.sliceString(from, to), cls: d.spec.class as string });
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
describe("syntaxHighlightField", () => {
|
||||
const create = () =>
|
||||
EditorState.create({ doc: "def hi, do: :ok", extensions: [syntaxHighlighting(openideaHighlightStyle), syntaxHighlightField] });
|
||||
|
||||
it("styles backend ranges with the active highlight style and maps them through edits", () => {
|
||||
let state = create();
|
||||
state = state.update({
|
||||
effects: setSyntaxHighlights.of({ kinds: ["keyword", "atom", "functionCall"], data: [0, 3, 0, 4, 6, 2, 12, 15, 1, 99, 120, 0] }),
|
||||
}).state;
|
||||
const keyword = highlightingFor(state, [t.keyword]);
|
||||
const atom = highlightingFor(state, [t.atom]);
|
||||
expect(keyword).toBeTruthy();
|
||||
expect(marks(state)).toEqual([
|
||||
{ text: "def", cls: keyword },
|
||||
{ text: "hi", cls: highlightingFor(state, [t.function(t.variableName)]) },
|
||||
{ text: ":ok", cls: atom },
|
||||
]);
|
||||
|
||||
state = state.update({ changes: { from: 0, insert: " " } }).state;
|
||||
expect(marks(state).map((m) => m.text)).toEqual(["def", "hi", ":ok"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Tree-sitter highlighting (`doc_highlights`) for languages without a
|
||||
* CodeMirror mode (Elixir, ...): backend kinds → Lezer tags, so the colours
|
||||
* come from the same highlight style and Color Scheme settings as Lezer
|
||||
* highlighting. Refreshed with folding; in between, marks are mapped through
|
||||
* the changes.
|
||||
*/
|
||||
import { StateEffect, StateField, type EditorState } from "@codemirror/state";
|
||||
import { Decoration, EditorView, type DecorationSet } from "@codemirror/view";
|
||||
import { highlightingFor } from "@codemirror/language";
|
||||
import { tags as t, type Tag } from "@lezer/highlight";
|
||||
import type { SyntaxHighlightKind, SyntaxHighlights } from "@/platform/ipc";
|
||||
|
||||
const TAGS: Record<SyntaxHighlightKind, Tag> = {
|
||||
keyword: t.keyword,
|
||||
string: t.string,
|
||||
stringSpecial: t.special(t.string),
|
||||
escape: t.escape,
|
||||
regexp: t.regexp,
|
||||
atom: t.atom,
|
||||
number: t.number,
|
||||
constant: t.constant(t.variableName),
|
||||
comment: t.comment,
|
||||
docComment: t.docComment,
|
||||
function: t.function(t.definition(t.variableName)),
|
||||
functionCall: t.function(t.variableName),
|
||||
builtin: t.standard(t.variableName),
|
||||
type: t.typeName,
|
||||
namespace: t.namespace,
|
||||
variable: t.variableName,
|
||||
selfVariable: t.self,
|
||||
property: t.propertyName,
|
||||
attribute: t.annotation,
|
||||
macro: t.macroName,
|
||||
label: t.labelName,
|
||||
tag: t.tagName,
|
||||
operator: t.operator,
|
||||
punctuation: t.punctuation,
|
||||
};
|
||||
|
||||
export const setSyntaxHighlights = StateEffect.define<SyntaxHighlights>();
|
||||
|
||||
function decorations(state: EditorState, h: SyntaxHighlights): DecorationSet {
|
||||
const marks = h.kinds.map((k) => {
|
||||
const cls = highlightingFor(state, [TAGS[k]]);
|
||||
return cls ? Decoration.mark({ class: cls }) : null;
|
||||
});
|
||||
const len = state.doc.length;
|
||||
const ranges = [];
|
||||
for (let i = 0; i + 2 < h.data.length; i += 3) {
|
||||
const from = h.data[i]!;
|
||||
const to = Math.min(h.data[i + 1]!, len);
|
||||
const mark = marks[h.data[i + 2]!];
|
||||
if (mark && from < to) ranges.push(mark.range(from, to));
|
||||
}
|
||||
return Decoration.set(ranges, true);
|
||||
}
|
||||
|
||||
export const syntaxHighlightField = StateField.define<DecorationSet>({
|
||||
create: () => Decoration.none,
|
||||
update(deco, tr) {
|
||||
for (const e of tr.effects) if (e.is(setSyntaxHighlights)) return decorations(tr.state, e.value);
|
||||
return tr.docChanged ? deco.map(tr.changes) : deco;
|
||||
},
|
||||
provide: (f) => EditorView.decorations.from(f),
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
/** The line-number gutter's context menu, IDEA's EditorGutterPopupMenu. */
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { editorPrefs } from "@/platform/editorSettings";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { menuGroupItems } from "@/workbench/contributions";
|
||||
import type { MenuItem } from "@/ui";
|
||||
import type { EditorSlot } from "./model/slot";
|
||||
|
||||
/** Whether a right-click on `target` belongs to the gutter menu (contributed gutters with their own menu handle theirs). */
|
||||
export function inGutterMenuArea(target: EventTarget | null): boolean {
|
||||
const t = target as HTMLElement | null;
|
||||
return !!t?.closest?.(".cm-gutters") && !t.closest(".cm-vcs-blame");
|
||||
}
|
||||
|
||||
async function setEditorSetting(key: string, value: unknown) {
|
||||
useProject.setState({ settings: await call(commands.settingsSet("global", `editor.${key}`, JSON.stringify(value))) });
|
||||
}
|
||||
|
||||
function toggle(label: string, key: string, on: boolean): MenuItem {
|
||||
return { label, checked: on, run: () => void setEditorSetting(key, !on) };
|
||||
}
|
||||
|
||||
function appearanceItems(): MenuItem[] {
|
||||
const p = editorPrefs();
|
||||
const whitespace = !!useProject.getState().settings?.editor?.showWhitespace;
|
||||
return [
|
||||
toggle("Show Line Numbers", "appearance.lineNumbers", p.appearance.lineNumbers),
|
||||
toggle("Show Gutter Icons", "showGutterIcons", p.showGutterIcons),
|
||||
toggle("Show Folding Outline", "folding.showOutline", p.folding.showOutline),
|
||||
toggle("Show Indent Guides", "appearance.indentGuides", p.appearance.indentGuides),
|
||||
toggle("Show Whitespaces", "showWhitespace", whitespace),
|
||||
toggle("Show Method Separators", "appearance.methodSeparators", p.appearance.methodSeparators),
|
||||
toggle("Show Breadcrumbs", "breadcrumbs.show", p.breadcrumbs.show),
|
||||
];
|
||||
}
|
||||
|
||||
const openSettings = (page: string) => () => void executeAction("file.settings", page);
|
||||
|
||||
export function gutterMenuItems(slot: EditorSlot, line: number): MenuItem[] {
|
||||
const model = slot.model;
|
||||
return [
|
||||
// Contributed groups (Annotate with Git Blame, bookmarks), each followed by a separator.
|
||||
...menuGroupItems("editorGutter", { paths: [model.path], text: slot.currentState().doc.toString(), line }),
|
||||
{ label: "Soft-Wrap", checked: model.softWrapOn(), run: () => model.toggleSoftWrap() },
|
||||
{ label: "Configure Soft Wraps…", run: openSettings("editor.general") },
|
||||
{ kind: "separator" },
|
||||
{ label: "Appearance", submenu: appearanceItems() },
|
||||
{ label: "Configure Gutter Icons…", run: openSettings("editor.general.gutterIcons") },
|
||||
];
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { EditorView } from "@codemirror/view";
|
||||
import type { LanguageDescription, LanguageSupport } from "@codemirror/language";
|
||||
import { create } from "zustand";
|
||||
import type { EditorConfigProps } from "@/bindings";
|
||||
import type { DocId, DocumentInfo, EditorSettings, FileSettings, LineEnding, OutlineItem, Settings } from "@/platform/ipc";
|
||||
import type { DocId, DocumentInfo, EditorSettings, FileSettings, LineEnding, OutlineItem, Settings, SyntaxHighlights } from "@/platform/ipc";
|
||||
import {
|
||||
_emitEditorEvent,
|
||||
_saveParticipants,
|
||||
@@ -22,6 +22,7 @@ import type { DocBackend, LanguageInfo } from "../backend";
|
||||
import { findLanguageDescription, languageInfo, loadLanguageInfos, loadSupport, loadedSupport, commentTokens } from "../cm/languages";
|
||||
import { foldEffect } from "@codemirror/language";
|
||||
import { backendFolds, setBackendFolds } from "../cm/folding";
|
||||
import { setSyntaxHighlights } from "../cm/syntaxHighlight";
|
||||
import {
|
||||
caretFor,
|
||||
compartments,
|
||||
@@ -265,6 +266,7 @@ export class DocModel {
|
||||
|
||||
addSlot(slot: EditorSlot) {
|
||||
this.slots.add(slot);
|
||||
if (this.highlights?.counter === this.changeCounter) slot.reconfigure([setSyntaxHighlights.of(this.highlights.value)]);
|
||||
}
|
||||
|
||||
removeSlot(slot: EditorSlot) {
|
||||
@@ -332,6 +334,8 @@ export class DocModel {
|
||||
indentOverride: { tabSize: number; insertSpaces: boolean } | null = null;
|
||||
/** Indentation detected in the file's text at open time. */
|
||||
detectedIndent: { insertSpaces: boolean; size?: number } | null = null;
|
||||
/** Last tree-sitter highlighting, for slots opened before the next refresh. */
|
||||
private highlights: { counter: number; value: SyntaxHighlights } | null = null;
|
||||
/** Fold-by-default has been applied (first folding ranges of the document). */
|
||||
private initialFolds = false;
|
||||
/** Signature of settings that require contributions to be rebuilt. */
|
||||
@@ -423,7 +427,12 @@ export class DocModel {
|
||||
await this.sync.whenIdle();
|
||||
const counter = this.changeCounter;
|
||||
const backend = this.manager.backend;
|
||||
const [folds, outline] = await Promise.allSettled([backend.folding(this.doc), backend.outline(this.doc)]);
|
||||
const [folds, outline, highlights] = await Promise.allSettled([
|
||||
backend.folding(this.doc),
|
||||
backend.outline(this.doc),
|
||||
// Without a CodeMirror mode, colours come from the grammar's tree-sitter query.
|
||||
this.desc ? null : backend.highlights(this.doc),
|
||||
]);
|
||||
if (this.closed) return;
|
||||
if (counter !== this.changeCounter) {
|
||||
this.scheduleRefresh();
|
||||
@@ -436,6 +445,10 @@ export class DocModel {
|
||||
this.foldByDefault();
|
||||
}
|
||||
}
|
||||
if (highlights.status === "fulfilled" && highlights.value) {
|
||||
this.highlights = { counter, value: highlights.value };
|
||||
for (const s of this.slots) s.reconfigure([setSyntaxHighlights.of(highlights.value)]);
|
||||
}
|
||||
if (outline.status === "fulfilled") {
|
||||
useOutline.setState({ [this.path]: outline.value });
|
||||
const lines = methodLines(outline.value);
|
||||
|
||||
@@ -17,9 +17,11 @@ import {
|
||||
type ChangeSet,
|
||||
type TransactionSpec,
|
||||
} from "@codemirror/state";
|
||||
import { EditorView, keymap, type ViewUpdate } from "@codemirror/view";
|
||||
import { EditorView, ViewPlugin, keymap, type ViewUpdate } from "@codemirror/view";
|
||||
import { _addEditor, _removeEditor, documentSynced, isExternalChange, type EditorDocContext, type TextEditorHandle } from "@/editor/api";
|
||||
import { showContextMenu } from "@/ui";
|
||||
import { baseExtensions, compartments, contributionExtensions } from "../cm/setup";
|
||||
import { gutterMenuItems, inGutterMenuArea } from "../gutterMenu";
|
||||
import type { DocModel } from "./document";
|
||||
|
||||
export interface SlotHost {
|
||||
@@ -107,6 +109,18 @@ export class EditorSlot {
|
||||
return true;
|
||||
},
|
||||
}),
|
||||
ViewPlugin.define((view) => {
|
||||
// Gutters sit outside the content DOM. Gutter extensions with their own menu (breakpoints,
|
||||
// annotations) handle the event first and prevent its default.
|
||||
const onContextMenu = (e: MouseEvent) => {
|
||||
if (e.defaultPrevented || !inGutterMenuArea(e.target)) return;
|
||||
e.preventDefault();
|
||||
const block = view.lineBlockAtHeight(e.clientY - view.documentTop);
|
||||
showContextMenu(e, gutterMenuItems(this, view.state.doc.lineAt(block.from).number - 1));
|
||||
};
|
||||
view.dom.addEventListener("contextmenu", onContextMenu);
|
||||
return { destroy: () => view.dom.removeEventListener("contextmenu", onContextMenu) };
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ const mavenModel: BuildModel = {
|
||||
profiles: ["ci"],
|
||||
javaVersion: 21,
|
||||
command: "/p/mvnw",
|
||||
options: [],
|
||||
env: {},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -95,6 +95,10 @@ export function activate(): () => void {
|
||||
if ([...e.created, ...e.modified, ...e.removed].some((p) => BUILD_FILE.test(p))) scheduleLoad();
|
||||
}),
|
||||
onIdeEvent("projectRootsChanged", scheduleLoad),
|
||||
// Project JDK / Maven home and options are applied to the model's launchers.
|
||||
onIdeEvent("settingsChanged", (e) => {
|
||||
if (e.key === "languages" || e.key.startsWith("languages.java")) scheduleLoad();
|
||||
}),
|
||||
registerActions([
|
||||
{
|
||||
id: "maven.reload",
|
||||
|
||||
@@ -37,6 +37,7 @@ function project(over: Partial<MavenProject>): MavenProject {
|
||||
profiles: [],
|
||||
javaVersion: 21,
|
||||
command: "/p/mvnw",
|
||||
options: [],
|
||||
env: { JAVA_HOME: "/jdk21" },
|
||||
...over,
|
||||
};
|
||||
@@ -184,6 +185,11 @@ describe("Maven runs", () => {
|
||||
const root = mavenGoalConfig(maven.projects[0]!, ["clean"], maven, { offline: false, skipTests: false, profiles: {} });
|
||||
expect(root.cwd).toBeNull();
|
||||
expect(root.isTest).toBe(false);
|
||||
// Settings › Maven options go before the goals.
|
||||
const configured = { ...core, options: ["-s", "/m2/settings.xml"] };
|
||||
expect(mavenGoalConfig(configured, ["test"], maven, { offline: false, skipTests: true, profiles: {} }).args).toEqual(
|
||||
["-s", "/m2/settings.xml", "test", "-DskipTests"],
|
||||
);
|
||||
});
|
||||
|
||||
it("parses typed command lines", () => {
|
||||
|
||||
@@ -401,7 +401,7 @@ export function mavenGoalConfig(
|
||||
model: Pick<MavenModel, "profiles">,
|
||||
options: MavenRunOptions,
|
||||
): RunConfig {
|
||||
const args = mavenArgs(goals, model, options);
|
||||
const args = [...project.options, ...mavenArgs(goals, model, options)];
|
||||
return {
|
||||
id: `maven:goal:${project.pom}:${goals.join(" ")}`,
|
||||
name: mavenConfigName(project, goals),
|
||||
|
||||
@@ -6,13 +6,11 @@
|
||||
import { RangeSet, StateEffect, StateField, type EditorState, type Extension } from "@codemirror/state";
|
||||
import { Decoration, EditorView, GutterMarker, ViewPlugin, lineNumberMarkers, type ViewUpdate } from "@codemirror/view";
|
||||
import { editorsFor, mirroredChange, remoteChange, useEditorRegistry, type EditorDocContext } from "@/editor/api";
|
||||
import { showContextMenu } from "@/ui";
|
||||
import { isConditional, mapLines, type BreakpointEntry, type BreakpointStatus } from "../breakpoints/model";
|
||||
import {
|
||||
addBreakpoint,
|
||||
breakpointsOf,
|
||||
setFileBreakpoints,
|
||||
toggleTemporaryBreakpoint,
|
||||
updateBreakpoint,
|
||||
useBreakpoints,
|
||||
} from "../breakpoints/store";
|
||||
@@ -21,14 +19,11 @@ import {
|
||||
removeSpecial,
|
||||
setSpecialLines,
|
||||
specialAt,
|
||||
toggleFieldAt,
|
||||
toggleMethodAt,
|
||||
updateSpecial,
|
||||
useSpecialBreakpoints,
|
||||
type SpecialBreakpoint,
|
||||
} from "../breakpoints/special";
|
||||
import { toggleBreakpointSmart } from "../breakpoints/toggle";
|
||||
import { methodAt, fieldAt } from "../breakpoints/symbols";
|
||||
import { sessionsRunning, useDebug } from "../state";
|
||||
import { openBreakpointPopover } from "../ui/popoverStore";
|
||||
import styles from "./editor.module.css";
|
||||
@@ -172,7 +167,8 @@ export function breakpointGutter(ctx: EditorDocContext): Extension {
|
||||
}),
|
||||
];
|
||||
view.dom.addEventListener("mousedown", this.onMouseDown);
|
||||
view.dom.addEventListener("contextmenu", this.onContextMenu);
|
||||
// Inside view.dom, so this runs before the editor's gutter menu listener there.
|
||||
view.scrollDOM.addEventListener("contextmenu", this.onContextMenu);
|
||||
}
|
||||
|
||||
scheduleRebuild() {
|
||||
@@ -234,59 +230,18 @@ export function breakpointGutter(ctx: EditorDocContext): Extension {
|
||||
if (!inBreakpointArea(e)) return;
|
||||
const line = lineAtEvent(this.view, e);
|
||||
if (line == null) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const at = { x: e.clientX, y: e.clientY };
|
||||
// Other lines get the editor's gutter menu, like IDEA.
|
||||
const bp = specialAt(path).find((b) => b.line === line) ?? breakpointsOf(path).find((b) => b.line === line);
|
||||
if (bp) {
|
||||
openBreakpointPopover(path, bp.id, at);
|
||||
return;
|
||||
}
|
||||
if (!canPlaceBreakpoint(ctx.language)) return;
|
||||
const text = this.view.state.doc.toString();
|
||||
const method = methodAt(ctx.language, text, line);
|
||||
const field = fieldAt(ctx.language, text, line);
|
||||
showContextMenu(at, [
|
||||
{ label: "Toggle Line Breakpoint", icon: "breakpoint", run: () => addBreakpoint(path, line) },
|
||||
{
|
||||
label: "Toggle Temporary Line Breakpoint",
|
||||
icon: "breakpoint",
|
||||
run: () => toggleTemporaryBreakpoint(path, line),
|
||||
},
|
||||
...(method
|
||||
? [
|
||||
{
|
||||
label: `Toggle Method Breakpoint (${method.label})`,
|
||||
icon: "breakpoint-method",
|
||||
run: () => void toggleMethodAt(path, line, method.name),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(field
|
||||
? [
|
||||
{
|
||||
label: `Toggle Field Watchpoint (${field.label})`,
|
||||
icon: "breakpoint-field",
|
||||
run: () => void toggleFieldAt(path, line, field),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: "Add Conditional Breakpoint…",
|
||||
run: () => openBreakpointPopover(path, addBreakpoint(path, line).id, at),
|
||||
},
|
||||
{
|
||||
label: "Add Logpoint…",
|
||||
run: () => openBreakpointPopover(path, addBreakpoint(path, line).id, at, true),
|
||||
},
|
||||
]);
|
||||
if (!bp) return;
|
||||
e.preventDefault();
|
||||
openBreakpointPopover(path, bp.id, { x: e.clientX, y: e.clientY });
|
||||
};
|
||||
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
this.unsubs.forEach((u) => u());
|
||||
this.view.dom.removeEventListener("mousedown", this.onMouseDown);
|
||||
this.view.dom.removeEventListener("contextmenu", this.onContextMenu);
|
||||
this.view.scrollDOM.removeEventListener("contextmenu", this.onContextMenu);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -37,7 +37,11 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
.repo {
|
||||
min-width: 0;
|
||||
margin-left: 8px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
|
||||
@@ -591,5 +591,10 @@ export function PullRequestsView() {
|
||||
export function PullRequestsHeader() {
|
||||
const availability = useGithub((s) => s.availability);
|
||||
if (availability?.kind !== "ready") return null;
|
||||
return <span className={styles.repo}>{availability.repo.nameWithOwner}</span>;
|
||||
const name = availability.repo.nameWithOwner;
|
||||
return (
|
||||
<span className={styles.repo} title={name}>
|
||||
{name}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ function CreateDialog(props: {
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
// Base candidates: branches of the remotes (without `origin/`), the default first.
|
||||
call(commands.vcsBranches())
|
||||
call(commands.vcsBranches(null))
|
||||
.then((branches) => {
|
||||
const names = new Set<string>();
|
||||
if (props.defaultBase) names.add(props.defaultBase);
|
||||
|
||||
@@ -89,7 +89,7 @@ export async function createPullRequest() {
|
||||
let needsPush = true;
|
||||
let title = "";
|
||||
try {
|
||||
const info = await call(commands.vcsBranchInfo());
|
||||
const info = await call(commands.vcsBranchInfo(null));
|
||||
head = info.head;
|
||||
needsPush = !info.upstream || info.ahead > 0;
|
||||
if (head) title = head.replace(/^[^/]+\//, "").replace(/[-_]+/g, " ").replace(/^\w/, (c) => c.toUpperCase());
|
||||
|
||||
@@ -386,6 +386,10 @@ export function activate(): () => void {
|
||||
const paths = [...e.created, ...e.modified, ...e.removed];
|
||||
if (paths.some((p) => CONFIG_FILES.test(p))) scheduleReload();
|
||||
}),
|
||||
// Detected configs carry the selected toolchains (interpreter, JDK, Maven home and options).
|
||||
onIdeEvent("settingsChanged", (e) => {
|
||||
if (e.key === "languages" || e.key.startsWith("languages.")) scheduleReload();
|
||||
}),
|
||||
);
|
||||
|
||||
return () => {
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
*/
|
||||
import { lazyComponent } from "@/ui";
|
||||
import { activeEditor, registerEditorContribution } from "@/editor/api";
|
||||
import { registerActions } from "@/platform/actions";
|
||||
import { executeAction, registerActions } from "@/platform/actions";
|
||||
import { shortcutLabel } from "@/platform/keymap";
|
||||
import { onIdeEvent } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { registerOverlay, registerToolWindow } from "@/workbench/contributions";
|
||||
import { registerMenuGroup, registerOverlay, registerToolWindow } from "@/workbench/contributions";
|
||||
import { bookmarkGutter } from "./bookmarks/gutter";
|
||||
import {
|
||||
hasBookmark,
|
||||
loadBookmarks,
|
||||
renameBookmarks,
|
||||
toggleBookmark,
|
||||
@@ -46,7 +48,8 @@ function closeAllPopups(except?: PopupKind) {
|
||||
if (except !== "everywhere") hideSearchEverywhere();
|
||||
if (except !== "recent") hideRecentPopup();
|
||||
if (except !== "find") hideFindPopup();
|
||||
if (except !== "fileStructure" && useFileStructurePopup.getState().open) useFileStructurePopup.setState({ open: false });
|
||||
if (except !== "fileStructure" && useFileStructurePopup.getState().open)
|
||||
useFileStructurePopup.setState({ open: false });
|
||||
}
|
||||
|
||||
function jumpBookmark(dir: 1 | -1) {
|
||||
@@ -59,7 +62,9 @@ function jumpBookmark(dir: 1 | -1) {
|
||||
const cur = `${path ?? ""}\u0000${String(line).padStart(9, "0")}`;
|
||||
const sorted = order.sort((a, b) => (a.k < b.k ? -1 : a.k > b.k ? 1 : 0));
|
||||
const next =
|
||||
dir === 1 ? (sorted.find((x) => x.k > cur) ?? sorted[0]) : ([...sorted].reverse().find((x) => x.k < cur) ?? sorted[sorted.length - 1]);
|
||||
dir === 1
|
||||
? (sorted.find((x) => x.k > cur) ?? sorted[0])
|
||||
: ([...sorted].reverse().find((x) => x.k < cur) ?? sorted[sorted.length - 1]);
|
||||
if (next) void openLocation(next.b.path, { line: next.b.line, col: 0 });
|
||||
}
|
||||
|
||||
@@ -113,6 +118,22 @@ export function activate(): void | (() => void) {
|
||||
order: 50,
|
||||
extensions: (ctx) => bookmarkGutter(ctx.path),
|
||||
}),
|
||||
registerMenuGroup({
|
||||
id: "search.bookmarks",
|
||||
menus: ["editorGutter"],
|
||||
order: 20,
|
||||
items: (_menu, { paths: [path], line }) => {
|
||||
if (!path || line == null) return [];
|
||||
const on = hasBookmark(useBookmarks.getState().items, path, line);
|
||||
return [
|
||||
{
|
||||
label: on ? "Remove Bookmark" : "Add Bookmark",
|
||||
shortcut: shortcutLabel("navigate.toggleBookmark"),
|
||||
run: () => void executeAction("navigate.toggleBookmark", { path, line }),
|
||||
},
|
||||
];
|
||||
},
|
||||
}),
|
||||
|
||||
registerActions([
|
||||
{
|
||||
@@ -298,7 +319,8 @@ export function activate(): void | (() => void) {
|
||||
onProject(s.project?.root ?? null);
|
||||
resetTracking();
|
||||
// A directory scope pointed into the previous project.
|
||||
if (useFindPopup.getState().scopeTab === "directory") useFindPopup.setState({ scopeTab: "project", directory: "" });
|
||||
if (useFindPopup.getState().scopeTab === "directory")
|
||||
useFindPopup.setState({ scopeTab: "project", directory: "" });
|
||||
}),
|
||||
onIdeEvent("fsChanged", (e) => {
|
||||
if (!e.removed.length) return;
|
||||
|
||||
@@ -21,7 +21,7 @@ describe("languages settings", () => {
|
||||
node: { packageManager: "pip" },
|
||||
rust: { checkCommand: "clippy", checkOnSave: false },
|
||||
typescript: { version: "" },
|
||||
java: { jdtlsVmArgs: " -Xmx2g " },
|
||||
java: { jdtlsVmArgs: " -Xmx2g ", jdk: 21, maven: { home: " /opt/maven " } },
|
||||
});
|
||||
expect(v.python).toEqual({ interpreter: "/usr/bin/python3", activateVirtualenv: true });
|
||||
expect(v.node.packageManager).toBe("");
|
||||
@@ -29,6 +29,8 @@ describe("languages settings", () => {
|
||||
expect(v.rust.checkOnSave).toBe(false);
|
||||
expect(v.typescript.version).toBe("bundled");
|
||||
expect(v.java.jdtlsVmArgs).toBe("-Xmx2g");
|
||||
expect(v.java.jdk).toBe("");
|
||||
expect(v.java.maven).toEqual({ home: "/opt/maven", userSettings: "", localRepository: "" });
|
||||
expect(validateSettings({}).languages).toEqual(DEFAULT_LANGUAGES);
|
||||
});
|
||||
|
||||
@@ -61,5 +63,7 @@ describe("language pages", () => {
|
||||
expect(filterPackages(pkgs, "dj").map((p) => p.name)).toEqual(["Django"]);
|
||||
expect(filterPackages(pkgs, "")).toHaveLength(2);
|
||||
expect(tildify("/Users/me/p/.venv/bin/python")).toBe("~/p/.venv/bin/python");
|
||||
expect(tildify("C:/Users/me/.m2/wrapper/dists/apache-maven-3.9.16")).toBe("~/.m2/wrapper/dists/apache-maven-3.9.16");
|
||||
expect(tildify("C:/Program Files/Java/jdk-21")).toBe("C:/Program Files/Java/jdk-21");
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Settings › Languages & Frameworks › Go / Java / Node.js / Rust / TypeScript: the
|
||||
* toolchain each language's server and run configurations use (applied by
|
||||
* `ide-sdk` when language servers start and when run configurations load).
|
||||
* Settings › Languages & Frameworks › Go / Java / Node.js / Rust / TypeScript and
|
||||
* Build Tools › Maven: the toolchain each language's server and run configurations
|
||||
* use (applied by `ide-sdk` when language servers start and when run configurations load).
|
||||
*/
|
||||
import { useId, useMemo } from "react";
|
||||
import { IconButton, Input, type SelectOption } from "@/ui";
|
||||
@@ -16,12 +16,15 @@ function PathInput({
|
||||
placeholder,
|
||||
hint,
|
||||
title,
|
||||
file,
|
||||
}: {
|
||||
k: string;
|
||||
label: string;
|
||||
placeholder: string;
|
||||
hint?: string;
|
||||
title: string;
|
||||
/** Browse for a file instead of a directory. */
|
||||
file?: boolean;
|
||||
}) {
|
||||
const [value, set] = useProjectSetting<string>(k);
|
||||
const id = useId();
|
||||
@@ -41,7 +44,7 @@ function PathInput({
|
||||
size="small"
|
||||
title="Browse…"
|
||||
onClick={async () => {
|
||||
const p = await choosePath({ directory: true, title, defaultPath: value || undefined });
|
||||
const p = await choosePath({ directory: !file, title, defaultPath: value || undefined });
|
||||
if (p) set(p);
|
||||
}}
|
||||
/>
|
||||
@@ -217,6 +220,19 @@ export function JavaPage() {
|
||||
const id = useId();
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<Section title="Project JDK">
|
||||
<SdkRow
|
||||
k="languages.java.jdk"
|
||||
label="SDK"
|
||||
kind="jdk"
|
||||
emptyLabel="Auto"
|
||||
emptyDetail="per module, the JDK of its Java version"
|
||||
directory
|
||||
browseTitle="Select JDK Home Directory"
|
||||
aria-label="Project JDK"
|
||||
hint="Compiles and runs the project: the default jdtls runtime, Run/Debug, and JAVA_HOME for Maven and Gradle."
|
||||
/>
|
||||
</Section>
|
||||
<Section title="Language Server">
|
||||
<Row
|
||||
label="JVM options"
|
||||
@@ -237,6 +253,44 @@ export function JavaPage() {
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Build Tools › Maven
|
||||
|
||||
export function MavenPage() {
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<Section>
|
||||
<SdkRow
|
||||
k="languages.java.maven.home"
|
||||
label="Maven home path"
|
||||
kind="maven"
|
||||
emptyLabel="Auto"
|
||||
emptyDetail="Maven wrapper, else mvn on PATH"
|
||||
directory
|
||||
browseTitle="Select Maven Home Directory"
|
||||
aria-label="Maven home path"
|
||||
hint="Runs sync, builds and Maven run configurations. A chosen home is used instead of the project's mvnw."
|
||||
/>
|
||||
<PathInput
|
||||
k="languages.java.maven.userSettings"
|
||||
label="User settings file"
|
||||
placeholder="~/.m2/settings.xml"
|
||||
title="Select Maven settings.xml"
|
||||
file
|
||||
hint="Passed as -s (mirrors, servers, proxies)."
|
||||
/>
|
||||
<PathInput
|
||||
k="languages.java.maven.localRepository"
|
||||
label="Local repository"
|
||||
placeholder="From settings.xml, else ~/.m2/repository"
|
||||
title="Select Local Repository"
|
||||
hint="Passed as -Dmaven.repo.local."
|
||||
/>
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// TypeScript
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export function useProjectSetting<T>(key: string): [T, (v: T) => void] {
|
||||
return useSetting<T>(key, hasProject ? "project" : "global");
|
||||
}
|
||||
|
||||
const HOME = /^\/(?:Users|home)\/[^/]+/;
|
||||
const HOME = /^(?:\/(?:Users|home)|[A-Za-z]:[\\/]Users)[\\/][^\\/]+/;
|
||||
|
||||
/** `~/…` for paths in the home directory. */
|
||||
export function tildify(path: string): string {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* Build, Execution, Deployment pages: Console, Debugger (+ Data Views,
|
||||
* Build, Execution, Deployment pages: Maven, Console, Debugger (+ Data Views,
|
||||
* Stepping), Python Debugger and Run/Debug. Consumed by the run and debugger
|
||||
* features (and `ide-run` for encoding / termination timeout).
|
||||
*/
|
||||
import { WORKFLOW_LIMITS } from "@/platform/workflowSettings";
|
||||
import type { SelectOption } from "@/ui";
|
||||
import { GlobListEditor, NumberInput, Row } from "../components/Form";
|
||||
import { MavenPage } from "../languages/LanguagePages";
|
||||
import { useSetting } from "../components/context";
|
||||
import type { PageSpec } from "./spec";
|
||||
import { Indented, ToggleNumber } from "./workflowControls";
|
||||
@@ -89,6 +90,15 @@ function TooltipDelayRow() {
|
||||
}
|
||||
|
||||
export const EXECUTION_PAGES: PageSpec[] = [
|
||||
{
|
||||
id: "build.maven",
|
||||
title: "Maven",
|
||||
group: BUILD_GROUP,
|
||||
// IntelliJ IDEA: Build Tools › Maven, before Console / Debugger.
|
||||
order: 359,
|
||||
keywords: ["maven home", "mvn", "mvnw", "wrapper", "settings.xml", "user settings", "local repository", "m2"],
|
||||
component: MavenPage,
|
||||
},
|
||||
{
|
||||
id: "build.console",
|
||||
title: "Console",
|
||||
|
||||
@@ -52,7 +52,17 @@ export const LANGUAGE_PAGES: PageSpec[] = [
|
||||
title: "Java",
|
||||
group: LANGUAGES_GROUP,
|
||||
order: 395,
|
||||
keywords: ["jdtls", "jvm options", "vmargs", "lombok", "javaagent", "eclipse jdt"],
|
||||
keywords: [
|
||||
"jdk",
|
||||
"project sdk",
|
||||
"java home",
|
||||
"jdtls",
|
||||
"jvm options",
|
||||
"vmargs",
|
||||
"lombok",
|
||||
"javaagent",
|
||||
"eclipse jdt",
|
||||
],
|
||||
component: JavaPage,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -3,36 +3,58 @@
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
height: 100%;
|
||||
min-height: 420px;
|
||||
}
|
||||
.intro {
|
||||
margin: 0 0 4px;
|
||||
margin: 0;
|
||||
max-width: 680px;
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
.body {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* list */
|
||||
.side {
|
||||
display: flex;
|
||||
flex: none;
|
||||
flex-direction: column;
|
||||
width: 300px;
|
||||
min-height: 0;
|
||||
border-right: 1px solid var(--border);
|
||||
}
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
gap: 4px;
|
||||
margin: 8px 8px 6px;
|
||||
}
|
||||
.search {
|
||||
width: 240px;
|
||||
}
|
||||
.spacer {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.segmented {
|
||||
display: inline-flex;
|
||||
display: flex;
|
||||
height: var(--h-control-small);
|
||||
margin: 0 8px 6px;
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border-strong);
|
||||
overflow: hidden;
|
||||
}
|
||||
.segment {
|
||||
padding: 0 10px;
|
||||
flex: 1;
|
||||
padding: 0 6px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--fg-secondary);
|
||||
font: inherit;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.segment:hover {
|
||||
background: var(--bg-hover);
|
||||
@@ -45,67 +67,70 @@
|
||||
background: var(--bg-selected);
|
||||
color: var(--fg-strong);
|
||||
}
|
||||
.error,
|
||||
.rowError {
|
||||
color: var(--danger);
|
||||
}
|
||||
.error {
|
||||
padding: 6px 0;
|
||||
}
|
||||
.tableWrap {
|
||||
min-width: 0;
|
||||
.list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
margin: 0;
|
||||
padding: 0 0 4px;
|
||||
list-style: none;
|
||||
overflow: auto;
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border);
|
||||
}
|
||||
.table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: auto;
|
||||
.groupHeader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
height: var(--h-row);
|
||||
padding: 0 12px;
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.table th {
|
||||
height: var(--h-header);
|
||||
padding: 0 8px;
|
||||
text-align: left;
|
||||
font-weight: normal;
|
||||
color: var(--fg-secondary);
|
||||
background: var(--bg-island);
|
||||
border-bottom: 1px solid var(--border);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table td {
|
||||
padding: 4px 8px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
/* IDEA tables: no row rules, selection-like hover. */
|
||||
.row td {
|
||||
border-top: 0;
|
||||
}
|
||||
.table th + th {
|
||||
border-left: 1px solid var(--border);
|
||||
}
|
||||
.row:first-child td {
|
||||
border-top: 0;
|
||||
.groupCount {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.row:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
.detailRow td {
|
||||
padding-top: 0;
|
||||
padding-bottom: 6px;
|
||||
.rowSelected,
|
||||
.rowSelected:hover {
|
||||
background: var(--bg-selected);
|
||||
}
|
||||
.toolName {
|
||||
.rowMain {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-height: var(--h-row);
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
height: var(--h-row);
|
||||
padding: 0 12px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--fg);
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
}
|
||||
.display {
|
||||
.rowMain:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.rowName {
|
||||
flex: none;
|
||||
max-width: 60%;
|
||||
overflow: hidden;
|
||||
color: var(--fg-strong);
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rowLanguages {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
text-align: right;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.kindTag {
|
||||
flex: none;
|
||||
padding: 0 5px;
|
||||
border-radius: var(--radius-small);
|
||||
background: var(--bg-control);
|
||||
@@ -113,35 +138,108 @@
|
||||
font-size: var(--fs-tiny);
|
||||
line-height: 16px;
|
||||
}
|
||||
.sub {
|
||||
max-width: 320px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
.listEmpty {
|
||||
padding: 8px 12px;
|
||||
color: var(--fg-muted);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.languages {
|
||||
max-width: 200px;
|
||||
|
||||
/* details */
|
||||
.details {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
min-width: 0;
|
||||
padding: 12px 16px 16px;
|
||||
overflow: auto;
|
||||
}
|
||||
.detailsEmpty {
|
||||
flex: 1;
|
||||
}
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
}
|
||||
.headerText {
|
||||
min-width: 0;
|
||||
}
|
||||
.title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: var(--fg-strong);
|
||||
font-size: var(--fs-input-large);
|
||||
font-weight: 600;
|
||||
}
|
||||
.subtitle {
|
||||
margin-top: 2px;
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
.version {
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--fg-secondary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* Status, Version and actions take their content's width; Tool and Languages share the rest. */
|
||||
.fitHead,
|
||||
.actionsHead {
|
||||
width: 1%;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.fields {
|
||||
display: grid;
|
||||
grid-template-columns: max-content minmax(0, 1fr);
|
||||
column-gap: 16px;
|
||||
row-gap: 8px;
|
||||
align-items: baseline;
|
||||
margin-top: 4px;
|
||||
}
|
||||
.field {
|
||||
display: contents;
|
||||
}
|
||||
.fieldLabel {
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
.fieldValue {
|
||||
min-width: 0;
|
||||
color: var(--fg);
|
||||
}
|
||||
code.fieldValue {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.breakAll {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.version {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.pathRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.pathInput {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.fieldHint {
|
||||
margin-top: 2px;
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.fieldError,
|
||||
.error {
|
||||
color: var(--danger);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.fieldError {
|
||||
margin-top: 2px;
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.notice {
|
||||
padding: 6px 8px;
|
||||
border-radius: var(--radius-small);
|
||||
background: var(--bg-control);
|
||||
color: var(--fg-secondary);
|
||||
overflow-wrap: anywhere;
|
||||
-webkit-user-select: text;
|
||||
user-select: text;
|
||||
}
|
||||
.job {
|
||||
display: flex;
|
||||
@@ -166,14 +264,10 @@
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.hint {
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.log {
|
||||
margin: 4px 0 0;
|
||||
margin: 0;
|
||||
padding: 6px 8px;
|
||||
max-height: 200px;
|
||||
max-height: 240px;
|
||||
overflow: auto;
|
||||
background: var(--bg-app);
|
||||
color: var(--fg-secondary);
|
||||
@@ -184,15 +278,3 @@
|
||||
-webkit-user-select: text;
|
||||
user-select: text;
|
||||
}
|
||||
.empty {
|
||||
padding: 12px;
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.visuallyHidden {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0 0 0 0);
|
||||
white-space: nowrap;
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
/** Settings › Languages & Frameworks › Language Servers: status + install/uninstall of LSP servers and debug adapters. */
|
||||
import { Fragment, useEffect, useMemo, useState } from "react";
|
||||
/**
|
||||
* Settings › Languages & Frameworks › Language Servers, laid out like the
|
||||
* Plugins page: language servers and debug adapters in a list on the left,
|
||||
* the selected tool's location, custom path and install actions on the right.
|
||||
*/
|
||||
import { useEffect, useId, useMemo, useState, type KeyboardEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
import type { ToolInfo } from "@/bindings";
|
||||
import { Badge, Button, IconButton, ProgressBar, SearchField, Spinner, T } from "@/ui";
|
||||
import { Badge, Button, EmptyState, IconButton, Input, ProgressBar, SearchField, Spinner, T } from "@/ui";
|
||||
import { toolsBackend } from "./backend";
|
||||
import {
|
||||
cancelInstall,
|
||||
installTool,
|
||||
refreshTools,
|
||||
setCustomPath,
|
||||
STATUS_LABEL,
|
||||
uninstallTool,
|
||||
useTools,
|
||||
@@ -19,9 +25,16 @@ type Filter = "all" | "missing" | "installed";
|
||||
const STATUS_TONE: Record<ToolInfo["status"], "success" | "accent" | "warning"> = {
|
||||
installed: "success",
|
||||
onPath: "accent",
|
||||
custom: "accent",
|
||||
missing: "warning",
|
||||
};
|
||||
|
||||
const KIND_LABEL: Record<ToolInfo["kind"], string> = {
|
||||
languageServer: "Language server",
|
||||
debugger: "Debugger",
|
||||
plugin: "Plugin",
|
||||
};
|
||||
|
||||
export function filterTools(tools: readonly ToolInfo[], query: string, filter: Filter): ToolInfo[] {
|
||||
const q = query.trim().toLowerCase();
|
||||
return tools.filter((t) => {
|
||||
@@ -48,217 +61,308 @@ function JobRow({ name, job }: { name: string; job: InstallJob }) {
|
||||
);
|
||||
}
|
||||
|
||||
function Actions({
|
||||
tool,
|
||||
busy,
|
||||
onToggleLog,
|
||||
hasLog,
|
||||
logOpen,
|
||||
}: {
|
||||
tool: ToolInfo;
|
||||
busy: boolean;
|
||||
hasLog: boolean;
|
||||
logOpen: boolean;
|
||||
onToggleLog: () => void;
|
||||
}) {
|
||||
const label = tool.displayName;
|
||||
function ToolRow({ tool, selected, onSelect }: { tool: ToolInfo; selected: boolean; onSelect: () => void }) {
|
||||
return (
|
||||
<div className={styles.actions}>
|
||||
{tool.canInstall && (
|
||||
<Button
|
||||
size="small"
|
||||
variant={tool.status === "missing" ? "primary" : "secondary"}
|
||||
disabled={busy}
|
||||
onClick={() => void installTool(tool.name)}
|
||||
aria-label={`${tool.status === "missing" ? "Install" : tool.status === "installed" ? "Reinstall" : "Install managed copy of"} ${label}`}
|
||||
>
|
||||
{tool.status === "missing" ? "Install" : tool.status === "installed" ? "Reinstall" : "Install"}
|
||||
</Button>
|
||||
<li className={clsx(styles.row, selected && styles.rowSelected)}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.rowMain}
|
||||
aria-current={selected || undefined}
|
||||
data-tool={tool.name}
|
||||
title={`${tool.displayName} — ${tool.languages.join(", ")}`}
|
||||
onClick={onSelect}
|
||||
>
|
||||
<Badge dot tone={STATUS_TONE[tool.status]}>
|
||||
{STATUS_LABEL[tool.status]}
|
||||
</Badge>
|
||||
<span className={styles.rowName}>{tool.displayName}</span>
|
||||
{tool.kind !== "languageServer" && (
|
||||
<span className={styles.kindTag}>
|
||||
<T>{KIND_LABEL[tool.kind]}</T>
|
||||
</span>
|
||||
)}
|
||||
<span className={styles.rowLanguages}>{tool.languages.join(", ")}</span>
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
/** "Path" field: an executable to launch instead of the detected one, saved when committed. */
|
||||
function CustomPath({ tool }: { tool: ToolInfo }) {
|
||||
const id = useId();
|
||||
const saved = tool.status === "custom" || tool.customError ? (tool.path ?? "") : "";
|
||||
const [draft, setDraft] = useState<string | null>(null);
|
||||
const value = draft ?? (tool.status === "custom" ? saved : "");
|
||||
const commit = async (next: string) => {
|
||||
setDraft(null);
|
||||
if (next.trim() !== saved) await setCustomPath(tool.command, next);
|
||||
};
|
||||
return (
|
||||
<div className={styles.field}>
|
||||
<label className={styles.fieldLabel} htmlFor={id}>
|
||||
<T>Path</T>
|
||||
</label>
|
||||
<div className={styles.fieldValue}>
|
||||
<span className={styles.pathRow}>
|
||||
<Input
|
||||
id={id}
|
||||
mono
|
||||
className={styles.pathInput}
|
||||
value={value}
|
||||
invalid={!!tool.customError}
|
||||
placeholder={tool.status !== "custom" && tool.path ? tool.path : "Auto-detect"}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onBlur={() => draft !== null && void commit(draft)}
|
||||
onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === "Enter") void commit(e.currentTarget.value);
|
||||
if (e.key === "Escape" && draft !== null) {
|
||||
e.stopPropagation();
|
||||
setDraft(null);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<IconButton
|
||||
icon="folder-open"
|
||||
size="small"
|
||||
title="Browse…"
|
||||
onClick={async () => {
|
||||
const picked = await toolsBackend().chooseExecutable(`Select ${tool.command}`, value || undefined);
|
||||
if (picked) await commit(picked);
|
||||
}}
|
||||
/>
|
||||
{tool.status === "custom" && (
|
||||
<IconButton icon="close" size="small" title="Use auto-detected" onClick={() => void commit("")} />
|
||||
)}
|
||||
</span>
|
||||
{tool.customError ? (
|
||||
<div className={styles.fieldError} role="alert">
|
||||
{tool.customError}
|
||||
</div>
|
||||
) : (
|
||||
<div className={styles.fieldHint}>
|
||||
<T>Leave empty to use the IDE-installed copy, else the one on PATH.</T>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Details({ tool }: { tool: ToolInfo }) {
|
||||
const job = useTools((s) => s.jobs[tool.name]);
|
||||
const last = useTools((s) => s.logs[tool.name]);
|
||||
const [logOpen, setLogOpen] = useState(false);
|
||||
const log = job?.lines ?? last?.lines ?? [];
|
||||
const lastError = !job && last?.error !== "Cancelled" ? last?.error : null;
|
||||
const busy = !!job;
|
||||
const manualHint = !tool.canInstall && tool.status === "missing";
|
||||
return (
|
||||
<div className={styles.details} aria-label={`${tool.displayName} details`}>
|
||||
<div className={styles.header}>
|
||||
<div className={styles.headerText}>
|
||||
<div className={styles.title}>
|
||||
<span>{tool.displayName}</span>
|
||||
<Badge tone={STATUS_TONE[tool.status]}>{STATUS_LABEL[tool.status]}</Badge>
|
||||
</div>
|
||||
<div className={styles.subtitle}>
|
||||
<T>{KIND_LABEL[tool.kind]}</T>
|
||||
{tool.languages.length > 0 && <> · {tool.languages.join(", ")}</>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.actions}>
|
||||
{tool.canInstall && (
|
||||
<Button
|
||||
size="small"
|
||||
variant={tool.status === "missing" ? "primary" : "secondary"}
|
||||
disabled={busy}
|
||||
onClick={() => void installTool(tool.name)}
|
||||
aria-label={`${tool.status === "installed" ? "Reinstall" : "Install"} ${tool.displayName}`}
|
||||
>
|
||||
{tool.status === "installed" ? "Reinstall" : "Install"}
|
||||
</Button>
|
||||
)}
|
||||
{tool.canUninstall && (
|
||||
<Button size="small" variant="ghost" disabled={busy} onClick={() => void uninstallTool(tool.name)}>
|
||||
<T>Uninstall</T>
|
||||
</Button>
|
||||
)}
|
||||
{log.length > 0 && (
|
||||
<Button size="small" variant="ghost" aria-expanded={logOpen} onClick={() => setLogOpen(!logOpen)}>
|
||||
{logOpen ? "Hide install log" : "Show install log"}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{job && <JobRow name={tool.displayName} job={job} />}
|
||||
{lastError && (
|
||||
<div className={styles.error} role="alert">
|
||||
{lastError}
|
||||
</div>
|
||||
)}
|
||||
{tool.canUninstall && (
|
||||
<Button
|
||||
size="small"
|
||||
variant="ghost"
|
||||
disabled={busy}
|
||||
onClick={() => void uninstallTool(tool.name)}
|
||||
aria-label={`Uninstall ${label}`}
|
||||
>
|
||||
<T>Uninstall</T>
|
||||
</Button>
|
||||
{manualHint && (
|
||||
<div className={styles.notice} role="note">
|
||||
{tool.unavailableReason ?? tool.installHint ?? "Install it manually and put it on PATH."}
|
||||
</div>
|
||||
)}
|
||||
{hasLog && (
|
||||
<IconButton
|
||||
icon="terminal"
|
||||
size="small"
|
||||
title={logOpen ? "Hide install log" : "Show install log"}
|
||||
pressed={logOpen}
|
||||
onClick={onToggleLog}
|
||||
/>
|
||||
{tool.canInstall && tool.status === "missing" && tool.unavailableReason === null && tool.installMethod && (
|
||||
<div className={styles.fieldHint}>
|
||||
<T>Installs into the IDE's own tools folder via</T> {tool.installMethod}.
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={styles.fields}>
|
||||
<div className={styles.field}>
|
||||
<span className={styles.fieldLabel}>
|
||||
<T>Command</T>
|
||||
</span>
|
||||
<code className={styles.fieldValue}>{tool.command}</code>
|
||||
</div>
|
||||
{tool.kind !== "plugin" && <CustomPath key={`${tool.name}:${tool.path ?? ""}`} tool={tool} />}
|
||||
{tool.status !== "custom" && (
|
||||
<div className={styles.field}>
|
||||
<span className={styles.fieldLabel}>
|
||||
<T>Location</T>
|
||||
</span>
|
||||
<code className={clsx(styles.fieldValue, styles.breakAll)}>{tool.path ?? "—"}</code>
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.field}>
|
||||
<span className={styles.fieldLabel}>
|
||||
<T>Version</T>
|
||||
</span>
|
||||
<span className={clsx(styles.fieldValue, styles.version)}>{tool.version ?? "—"}</span>
|
||||
</div>
|
||||
{tool.homepage && (
|
||||
<div className={styles.field}>
|
||||
<span className={styles.fieldLabel}>
|
||||
<T>Homepage</T>
|
||||
</span>
|
||||
<a
|
||||
className={clsx(styles.fieldValue, styles.breakAll)}
|
||||
href={tool.homepage}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
{tool.homepage}
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{logOpen && log.length > 0 && (
|
||||
<pre className={styles.log} aria-label={`${tool.displayName} install log`}>
|
||||
{log.join("\n")}
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function LanguageServersPage() {
|
||||
const { tools, loaded, loading, error, jobs, logs } = useTools();
|
||||
const { tools, loaded, loading, error } = useTools();
|
||||
const [query, setQuery] = useState("");
|
||||
const [filter, setFilter] = useState<Filter>("all");
|
||||
const [openLog, setOpenLog] = useState<string | null>(null);
|
||||
const [selectedName, setSelectedName] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
void refreshTools();
|
||||
}, []);
|
||||
|
||||
const shown = useMemo(() => filterTools(tools, query, filter), [tools, query, filter]);
|
||||
const ready = shown.filter((t) => t.status !== "missing");
|
||||
const missing = shown.filter((t) => t.status === "missing");
|
||||
const ordered = [...ready, ...missing];
|
||||
const selected = ordered.find((t) => t.name === selectedName) ?? ordered[0] ?? null;
|
||||
const missingCount = tools.filter((t) => t.status === "missing").length;
|
||||
|
||||
const onListKey = (e: KeyboardEvent<HTMLUListElement>) => {
|
||||
if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
|
||||
e.preventDefault();
|
||||
const i = selected ? ordered.indexOf(selected) : -1;
|
||||
const next = ordered[Math.min(ordered.length - 1, Math.max(0, i + (e.key === "ArrowDown" ? 1 : -1)))];
|
||||
if (!next) return;
|
||||
setSelectedName(next.name);
|
||||
e.currentTarget.querySelector<HTMLElement>(`[data-tool="${CSS.escape(next.name)}"]`)?.focus();
|
||||
};
|
||||
|
||||
const group = (title: string, list: ToolInfo[]) =>
|
||||
list.length > 0 && (
|
||||
<>
|
||||
<li className={styles.groupHeader} role="presentation">
|
||||
<T>{title}</T> <span className={styles.groupCount}>{list.length}</span>
|
||||
</li>
|
||||
{list.map((t) => (
|
||||
<ToolRow key={t.name} tool={t} selected={t === selected} onSelect={() => setSelectedName(t.name)} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<p className={styles.intro}>
|
||||
Language servers and debug adapters used by the IDE. Missing tools can be installed into the IDE's own
|
||||
tools folder; nothing is downloaded until you click Install.
|
||||
</p>
|
||||
<div className={styles.toolbar}>
|
||||
<SearchField
|
||||
className={styles.search}
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
placeholder="Filter by tool or language"
|
||||
aria-label="Filter language servers"
|
||||
/>
|
||||
<div className={styles.segmented} role="radiogroup" aria-label="Show">
|
||||
{(["all", "missing", "installed"] as const).map((f) => (
|
||||
<button
|
||||
key={f}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={filter === f}
|
||||
className={clsx(styles.segment, filter === f && styles.segmentOn)}
|
||||
onClick={() => setFilter(f)}
|
||||
>
|
||||
{f === "all" ? "All" : f === "missing" ? `Missing (${missingCount})` : "Available"}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<span className={styles.spacer} />
|
||||
{loading && <Spinner size={14} label="Checking tools" />}
|
||||
<IconButton
|
||||
icon="refresh"
|
||||
title="Re-check installed tools"
|
||||
onClick={() => void refreshTools()}
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className={styles.error} role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={styles.tableWrap}>
|
||||
<table className={styles.table} aria-label="Language servers and debug adapters">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<T>Tool</T>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<T>Languages</T>
|
||||
</th>
|
||||
<th scope="col" className={styles.fitHead}>
|
||||
<T>Status</T>
|
||||
</th>
|
||||
<th scope="col" className={styles.fitHead}>
|
||||
<T>Version</T>
|
||||
</th>
|
||||
<th scope="col" className={styles.actionsHead}>
|
||||
<span className={styles.visuallyHidden}>
|
||||
<T>Actions</T>
|
||||
</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{shown.map((t) => {
|
||||
const job = jobs[t.name];
|
||||
const log = job?.lines ?? logs[t.name]?.lines ?? [];
|
||||
const lastError = !job ? logs[t.name]?.error : null;
|
||||
const logOpen = openLog === t.name;
|
||||
return (
|
||||
<Fragment key={t.name}>
|
||||
<tr className={styles.row} data-tool={t.name}>
|
||||
<td>
|
||||
<div className={styles.toolName}>
|
||||
<span className={styles.display}>{t.displayName}</span>
|
||||
{t.kind === "debugger" && (
|
||||
<span className={styles.kindTag}>
|
||||
<T>Debugger</T>
|
||||
</span>
|
||||
)}
|
||||
{t.kind === "plugin" && (
|
||||
<span className={styles.kindTag}>
|
||||
<T>Plugin</T>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{(t.path ?? (t.command !== t.displayName ? t.command : null)) && (
|
||||
<div className={styles.sub} title={t.path ?? undefined}>
|
||||
{t.path ?? t.command}
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td className={styles.languages}>{t.languages.join(", ") || "—"}</td>
|
||||
<td>
|
||||
<Badge tone={STATUS_TONE[t.status]}>{STATUS_LABEL[t.status]}</Badge>
|
||||
</td>
|
||||
<td className={styles.version}>{t.version ?? "—"}</td>
|
||||
<td>
|
||||
<Actions
|
||||
tool={t}
|
||||
busy={!!job}
|
||||
hasLog={log.length > 0}
|
||||
logOpen={logOpen}
|
||||
onToggleLog={() => setOpenLog(logOpen ? null : t.name)}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
{(job || lastError || logOpen || (!t.canInstall && t.status === "missing")) && (
|
||||
<tr className={styles.detailRow}>
|
||||
<td colSpan={5}>
|
||||
{job && <JobRow name={t.displayName} job={job} />}
|
||||
{lastError && lastError !== "Cancelled" && (
|
||||
<div className={styles.rowError} role="alert">
|
||||
{lastError}
|
||||
</div>
|
||||
)}
|
||||
{!t.canInstall && t.status === "missing" && (
|
||||
<div className={styles.hint}>
|
||||
{t.unavailableReason ?? t.installHint ?? "Install it manually and put it on PATH."}
|
||||
</div>
|
||||
)}
|
||||
{logOpen && log.length > 0 && (
|
||||
<pre className={styles.log} aria-label={`${t.displayName} install log`}>
|
||||
{log.join("\n")}
|
||||
</pre>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
{loaded && shown.length === 0 && (
|
||||
<div className={styles.empty}>
|
||||
<T>No tools match.</T>
|
||||
<div className={styles.body}>
|
||||
<div className={styles.side}>
|
||||
<div className={styles.toolbar}>
|
||||
<SearchField
|
||||
className={styles.search}
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
placeholder="Filter by tool or language"
|
||||
aria-label="Filter language servers"
|
||||
/>
|
||||
{loading ? (
|
||||
<Spinner size={14} label="Checking tools" />
|
||||
) : (
|
||||
<IconButton
|
||||
icon="refresh"
|
||||
size="small"
|
||||
title="Re-check installed tools"
|
||||
onClick={() => void refreshTools()}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{!loaded && !error && (
|
||||
<div className={styles.empty}>
|
||||
<T>Checking installed tools…</T>
|
||||
<div className={styles.segmented} role="radiogroup" aria-label="Show">
|
||||
{(["all", "missing", "installed"] as const).map((f) => (
|
||||
<button
|
||||
key={f}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={filter === f}
|
||||
className={clsx(styles.segment, filter === f && styles.segmentOn)}
|
||||
onClick={() => setFilter(f)}
|
||||
>
|
||||
{f === "all" ? "All" : f === "missing" ? `Missing (${missingCount})` : "Available"}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<ul className={styles.list} aria-label="Language servers and debug adapters" onKeyDown={onListKey}>
|
||||
{group("Available", ready)}
|
||||
{group("Missing", missing)}
|
||||
{loaded && shown.length === 0 && (
|
||||
<li className={styles.listEmpty}>
|
||||
<T>No tools match.</T>
|
||||
</li>
|
||||
)}
|
||||
{!loaded && !error && (
|
||||
<li className={styles.listEmpty}>
|
||||
<T>Checking installed tools…</T>
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
{selected ? (
|
||||
<Details key={selected.name} tool={selected} />
|
||||
) : (
|
||||
<EmptyState className={styles.detailsEmpty} title={loaded ? "No tool selected" : "Loading…"} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -126,29 +126,59 @@ describe("missing language server prompt", () => {
|
||||
});
|
||||
|
||||
describe("LanguageServersPage", () => {
|
||||
it("lists tools and installs from the table", async () => {
|
||||
const listItem = (name: string) =>
|
||||
screen.getByRole("list", { name: /language servers/i }).querySelector<HTMLElement>(`[data-tool="${name}"]`)!;
|
||||
|
||||
it("lists tools and installs from the details pane", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<LanguageServersPage />);
|
||||
const table = await screen.findByRole("table", { name: /language servers/i });
|
||||
const row = await within(table).findByText("gopls");
|
||||
const tr = row.closest("tr")!;
|
||||
expect(within(tr).getByText("Missing")).toBeInTheDocument();
|
||||
await user.click(within(tr).getByRole("button", { name: "Install gopls" }));
|
||||
await waitFor(() => expect(within(table).getByText("gopls").closest("tr")!).toHaveTextContent("Installed"));
|
||||
expect(within(table).getByText("gopls").closest("tr")!).toHaveTextContent("1.0.0");
|
||||
await screen.findByText("gopls");
|
||||
await user.click(listItem("gopls"));
|
||||
const details = screen.getByLabelText("gopls details");
|
||||
expect(within(details).getByText("Missing")).toBeInTheDocument();
|
||||
await user.click(within(details).getByRole("button", { name: "Install gopls" }));
|
||||
await waitFor(() => expect(screen.getByLabelText("gopls details")).toHaveTextContent("Installed"));
|
||||
expect(screen.getByLabelText("gopls details")).toHaveTextContent("1.0.0");
|
||||
// Installed tools move to the Available group, still selected.
|
||||
expect(listItem("gopls")).toHaveAttribute("aria-current", "true");
|
||||
// The install log can be shown afterwards.
|
||||
await user.click(
|
||||
within(within(table).getByText("gopls").closest("tr")!).getByRole("button", { name: "Show install log" }),
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "Show install log" }));
|
||||
expect(screen.getByLabelText("gopls install log")).toHaveTextContent("Installing gopls");
|
||||
});
|
||||
|
||||
it("explains why a tool cannot be installed", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<LanguageServersPage />);
|
||||
expect(await screen.findByText("gem install solargraph")).toBeInTheDocument();
|
||||
await screen.findByText("solargraph");
|
||||
await user.click(listItem("solargraph"));
|
||||
expect(screen.getByText("gem install solargraph")).toBeInTheDocument();
|
||||
await user.click(listItem("zls"));
|
||||
expect(screen.getByText("curl is required to download tools")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("sets and clears a custom path", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<LanguageServersPage />);
|
||||
await screen.findByText("gopls");
|
||||
await user.click(listItem("gopls"));
|
||||
const path = within(screen.getByLabelText("gopls details")).getByRole("textbox", { name: "Path" });
|
||||
await user.type(path, "/opt/go/bin/gopls{Enter}");
|
||||
await waitFor(() => expect(screen.getByLabelText("gopls details")).toHaveTextContent("Custom"));
|
||||
expect(backend.customPaths).toEqual({ gopls: "/opt/go/bin/gopls" });
|
||||
await user.click(screen.getByRole("button", { name: "Use auto-detected" }));
|
||||
await waitFor(() => expect(backend.customPaths).toEqual({}));
|
||||
expect(screen.getByLabelText("gopls details")).toHaveTextContent("Missing");
|
||||
});
|
||||
|
||||
it("moves the selection with the arrow keys", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<LanguageServersPage />);
|
||||
await screen.findByText("gopls");
|
||||
await user.click(listItem("rust-analyzer"));
|
||||
await user.keyboard("{ArrowDown}");
|
||||
expect(screen.getByLabelText("typescript-language-server details")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("filters to missing tools", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<LanguageServersPage />);
|
||||
@@ -158,7 +188,7 @@ describe("LanguageServersPage", () => {
|
||||
expect(screen.getByText("gopls")).toBeInTheDocument();
|
||||
await user.type(screen.getByRole("textbox", { name: /filter language servers/i }), "zig");
|
||||
expect(screen.queryByText("gopls")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("ZLS (Zig)")).toBeInTheDocument();
|
||||
expect(listItem("zls")).toHaveTextContent("ZLS (Zig)");
|
||||
});
|
||||
|
||||
it("shows backend errors", async () => {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { Channel } from "@tauri-apps/api/core";
|
||||
import type { InstallEvent, RequestId, ToolInfo } from "@/bindings";
|
||||
import { call, commands, IpcError, isTauri } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
|
||||
export interface ToolsBackend {
|
||||
list(): Promise<ToolInfo[]>;
|
||||
@@ -13,6 +14,10 @@ export interface ToolsBackend {
|
||||
cancel(request: RequestId): void;
|
||||
/** Restarts running language servers named `name` (after an install). */
|
||||
restartServers(name: string): Promise<void>;
|
||||
/** Launches `command` from `path` instead of the detected one (global setting); "" clears it. */
|
||||
setCustomPath(command: string, path: string): Promise<void>;
|
||||
/** File chooser for an executable; null when cancelled. */
|
||||
chooseExecutable(title: string, defaultPath?: string): Promise<string | null>;
|
||||
}
|
||||
|
||||
export const tauriToolsBackend: ToolsBackend = {
|
||||
@@ -35,6 +40,18 @@ export const tauriToolsBackend: ToolsBackend = {
|
||||
servers.filter((s) => s.name === name).map((s) => call(commands.lspRestart(s.id)).catch(() => {})),
|
||||
);
|
||||
},
|
||||
setCustomPath: async (command, path) => {
|
||||
const tools = { ...(await commands.settingsGet()).tools };
|
||||
if (path) tools[command] = { path };
|
||||
else delete tools[command];
|
||||
const settings = await call(commands.settingsSet("global", "tools", JSON.stringify(tools)));
|
||||
useProject.setState({ settings });
|
||||
},
|
||||
chooseExecutable: async (title, defaultPath) => {
|
||||
const { open } = await import("@tauri-apps/plugin-dialog");
|
||||
const picked = await open({ directory: false, multiple: false, title, defaultPath: defaultPath || undefined });
|
||||
return (Array.isArray(picked) ? picked[0] : picked) ?? null;
|
||||
},
|
||||
};
|
||||
|
||||
function tool(partial: Partial<ToolInfo> & Pick<ToolInfo, "name" | "languages">): ToolInfo {
|
||||
@@ -51,6 +68,7 @@ function tool(partial: Partial<ToolInfo> & Pick<ToolInfo, "name" | "languages">)
|
||||
canUninstall: false,
|
||||
installHint: null,
|
||||
homepage: null,
|
||||
customError: null,
|
||||
...partial,
|
||||
};
|
||||
}
|
||||
@@ -183,6 +201,23 @@ export class MemoryToolsBackend implements ToolsBackend {
|
||||
async restartServers(name: string) {
|
||||
this.restarted.push(name);
|
||||
}
|
||||
|
||||
/** Paths set through `setCustomPath`, by command. */
|
||||
customPaths: Record<string, string> = {};
|
||||
/** What `chooseExecutable` answers. */
|
||||
chosen: string | null = null;
|
||||
|
||||
async setCustomPath(command: string, path: string) {
|
||||
if (path) this.customPaths[command] = path;
|
||||
else delete this.customPaths[command];
|
||||
for (const t of this.tools.filter((x) => x.command === command)) {
|
||||
this.replace(path ? { ...t, status: "custom", path, version: null } : { ...t, status: "missing", path: null });
|
||||
}
|
||||
}
|
||||
|
||||
async chooseExecutable() {
|
||||
return this.chosen;
|
||||
}
|
||||
}
|
||||
|
||||
let backend: ToolsBackend | null = null;
|
||||
|
||||
@@ -179,8 +179,26 @@ export async function uninstallTool(name: string): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Launches `command` from `path` (empty: auto-detect again), then re-checks the tools. */
|
||||
export async function setCustomPath(command: string, path: string): Promise<boolean> {
|
||||
try {
|
||||
await toolsBackend().setCustomPath(command, path.trim());
|
||||
await refreshTools();
|
||||
return true;
|
||||
} catch (e) {
|
||||
notifications().notify({
|
||||
group: "tools",
|
||||
level: "error",
|
||||
title: `Failed to set the path of ${command}`,
|
||||
body: errorText(e),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export const STATUS_LABEL: Record<ToolInfo["status"], string> = {
|
||||
installed: "Installed",
|
||||
onPath: "On PATH",
|
||||
custom: "Custom",
|
||||
missing: "Missing",
|
||||
};
|
||||
@@ -18,6 +18,48 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.repo {
|
||||
flex: none;
|
||||
max-width: 120px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.repo::after {
|
||||
content: " /";
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.repos {
|
||||
flex: none;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
padding: 6px 8px;
|
||||
border-bottom: 1px solid var(--border-popup);
|
||||
}
|
||||
.repoButton {
|
||||
max-width: 160px;
|
||||
height: 22px;
|
||||
padding: 0 8px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
border: none;
|
||||
border-radius: var(--radius-small);
|
||||
background: transparent;
|
||||
color: var(--fg-secondary);
|
||||
font: inherit;
|
||||
font-size: var(--fs-small);
|
||||
cursor: pointer;
|
||||
}
|
||||
.repoButton:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
.repoSelected,
|
||||
.repoSelected:hover {
|
||||
background: var(--bg-selected);
|
||||
color: var(--fg);
|
||||
}
|
||||
.operation {
|
||||
color: var(--warning);
|
||||
font-size: var(--fs-tiny);
|
||||
|
||||
@@ -19,7 +19,7 @@ import { buildBranchRows, type BranchRow, type PopupAction } from "./branches";
|
||||
import { branchMenu } from "./branchMenu";
|
||||
import { recentBranches } from "./branchOps";
|
||||
import { inProgress, operationTitle, type InProgress } from "./operations";
|
||||
import { loadBranches, useVcs } from "./store";
|
||||
import { loadBranches, repoName, selectRepo, useVcs } from "./store";
|
||||
import styles from "./BranchWidget.module.css";
|
||||
|
||||
export const useBranchesPopup = create<{ open: boolean }>(() => ({ open: false }));
|
||||
@@ -34,6 +34,8 @@ export function headLabel(branch: { head: string | null; headCommit: string | nu
|
||||
export function BranchWidget() {
|
||||
const available = useVcs((s) => s.available);
|
||||
const branch = useVcs((s) => s.branch);
|
||||
// With several repositories the widget names the selected one, like IDEA's.
|
||||
const repo = useVcs((s) => (s.roots.length > 1 && s.repo ? repoName(s.repo) : null));
|
||||
const open = useBranchesPopup((s) => s.open);
|
||||
const ref = useRef<HTMLButtonElement>(null);
|
||||
if (!available || !branch) return null;
|
||||
@@ -43,6 +45,7 @@ export function BranchWidget() {
|
||||
branch.ahead > 0 ? `${branch.ahead} outgoing` : "",
|
||||
].filter(Boolean);
|
||||
const tooltip =
|
||||
(repo ? `Repository: ${repo}\n` : "") +
|
||||
(branch.upstream
|
||||
? `Git branch: ${headLabel(branch)}${op}\nTracking ${branch.upstream}`
|
||||
: `Git branch: ${headLabel(branch)}${op}`) + (sync.length ? `\n${sync.join(", ")} commits` : "");
|
||||
@@ -58,6 +61,7 @@ export function BranchWidget() {
|
||||
onClick={() => useBranchesPopup.setState({ open: !open })}
|
||||
>
|
||||
<Icon name={branch.head ? "branch" : "commit"} size={16} className={styles.icon} />
|
||||
{repo && <span className={styles.repo}>{repo}</span>}
|
||||
<span className={styles.name}>
|
||||
{inProgress(branch.operation) ? operationTitle(inProgress(branch.operation)!, branch.head) : headLabel(branch)}
|
||||
</span>
|
||||
@@ -179,6 +183,7 @@ function BranchesPopup({ anchor, onClose }: { anchor: RefObject<HTMLElement | nu
|
||||
aria-label="Git Branches"
|
||||
className={styles.popup}
|
||||
>
|
||||
<RepositoryBar />
|
||||
<div className={styles.search}>
|
||||
<SearchField
|
||||
data-autofocus
|
||||
@@ -237,6 +242,29 @@ function BranchesPopup({ anchor, onClose }: { anchor: RefObject<HTMLElement | nu
|
||||
);
|
||||
}
|
||||
|
||||
/** Repository switcher (several repositories): branches, log and push act on the selected one. */
|
||||
function RepositoryBar() {
|
||||
const roots = useVcs((s) => s.roots);
|
||||
const repo = useVcs((s) => s.repo);
|
||||
if (roots.length < 2) return null;
|
||||
return (
|
||||
<div className={styles.repos} role="group" aria-label="Repository">
|
||||
{roots.map((r) => (
|
||||
<button
|
||||
key={r}
|
||||
type="button"
|
||||
className={clsx(styles.repoButton, r === repo && styles.repoSelected)}
|
||||
aria-pressed={r === repo}
|
||||
title={r}
|
||||
onClick={() => void selectRepo(r).then(() => loadBranches().catch(() => undefined))}
|
||||
>
|
||||
{repoName(r)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function BranchRowView({ row }: { row: BranchRow }) {
|
||||
if (row.type === "action") {
|
||||
const keys = shortcutLabel(row.action.id);
|
||||
|
||||
@@ -43,7 +43,7 @@ import { KIND_COLOR, KIND_LABEL, formatTime, stashLabel, stripSlash } from "./mo
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { OperationBanner } from "./operations";
|
||||
import { ShelfPanel, loadShelves, useShelf } from "./shelf";
|
||||
import { loadStashes, refreshNow, useVcs } from "./store";
|
||||
import { currentRepo, loadStashes, refreshNow, useVcs } from "./store";
|
||||
import styles from "./CommitView.module.css";
|
||||
|
||||
/** MIME type of changed files dragged between change lists (absolute paths, newline-separated). */
|
||||
@@ -243,7 +243,11 @@ function ChangesPanel() {
|
||||
const treeRef = useRef<TreeHandle>(null);
|
||||
const viewRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
const roots = useMemo(() => buildChangeTree(status, root, groupByDir, lists), [status, root, groupByDir, lists]);
|
||||
const repos = useVcs((s) => s.roots);
|
||||
const roots = useMemo(
|
||||
() => buildChangeTree(status, root, groupByDir, lists, repos),
|
||||
[status, root, groupByDir, lists, repos],
|
||||
);
|
||||
const [byKey, parents] = useMemo(() => {
|
||||
const m = new Map<string, ChangeNode>();
|
||||
const up = new Map<string, string>();
|
||||
@@ -556,7 +560,15 @@ function CommitMessage({ included }: { included: number }) {
|
||||
if (v && !useCommit.getState().message.trim()) {
|
||||
try {
|
||||
const [last] = await call(
|
||||
commands.vcsLog({ branch: "HEAD", path: null, author: null, text: null, range: null, skip: 0, limit: 1 }),
|
||||
commands.vcsLog(currentRepo(), {
|
||||
branch: "HEAD",
|
||||
path: null,
|
||||
author: null,
|
||||
text: null,
|
||||
range: null,
|
||||
skip: 0,
|
||||
limit: 1,
|
||||
}),
|
||||
);
|
||||
if (last && !useCommit.getState().message.trim()) {
|
||||
amendMessage.current = last.message;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { call, commands } from "@/platform/ipc";
|
||||
import { Dialog, List, Spinner, Tabs, T } from "@/ui";
|
||||
import { openDialog } from "./dialogs";
|
||||
import { formatTime } from "./model";
|
||||
import { useVcs } from "./store";
|
||||
import { currentRepo, useVcs } from "./store";
|
||||
import styles from "./common.module.css";
|
||||
|
||||
const LIMIT = 2000;
|
||||
@@ -14,7 +14,7 @@ const LIMIT = 2000;
|
||||
/** Commits reachable from `to` but not from `from` (git's `from..to`), computed by git, unbounded by any window. */
|
||||
const commitsBetween = (from: string, to: string) =>
|
||||
call(
|
||||
commands.vcsLog({
|
||||
commands.vcsLog(currentRepo(), {
|
||||
branch: null,
|
||||
path: null,
|
||||
author: null,
|
||||
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
} from "./logStore";
|
||||
import { KIND_COLOR, baseName, formatTime, relTo, type EffectiveKind } from "./model";
|
||||
import { clearConsole, useVcsConsole } from "./ops";
|
||||
import { loadBranches, useVcs } from "./store";
|
||||
import { currentRepo, loadBranches, useVcs } from "./store";
|
||||
import { checkoutBranch, loadFavoriteBranches, newBranch, useFavoriteBranches } from "./branchOps";
|
||||
import { branchMenu } from "./branchMenu";
|
||||
import { branchFolderKeys, branchGroupKeys, buildBranchTree, filterBranchTree, type BranchTreeNode } from "./branches";
|
||||
@@ -111,14 +111,16 @@ function LogView() {
|
||||
const commits = useGitLog((s) => s.commits);
|
||||
const selected = useGitLog((s) => s.selected);
|
||||
const root = useVcs((s) => s.root);
|
||||
const repo = useVcs((s) => s.repo);
|
||||
const lastRefs = useRef<string | null>(null);
|
||||
|
||||
// On mount and when the window switches to another repository.
|
||||
// On mount, when the window switches to another project and when another of its
|
||||
// repositories is selected (its branches are needed to notice its refs moving).
|
||||
useEffect(() => {
|
||||
lastRefs.current = null;
|
||||
if (!useGitLog.getState().commits.length) void reloadLog();
|
||||
void loadBranches().catch(() => undefined);
|
||||
}, [root]);
|
||||
}, [root, repo]);
|
||||
|
||||
// HEAD or a branch tip moved (commit, undo, reset, rebase, fetch…): reload (keeps the selection).
|
||||
useEffect(() => {
|
||||
@@ -711,7 +713,7 @@ function CommitDetails({ commits }: { commits: Commit[] }) {
|
||||
useEffect(() => {
|
||||
if (!selected) return;
|
||||
let alive = true;
|
||||
call(commands.vcsCommitFiles(selected))
|
||||
call(commands.vcsCommitFiles(currentRepo(), selected))
|
||||
.then((f) => alive && setFiles(f))
|
||||
.catch((e) => alive && setError(e instanceof Error ? e.message : String(e)));
|
||||
return () => {
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { FileStatus } from "@/bindings";
|
||||
import { aggregateCheck, buildChangeTree, initialCheck, planCommit, type CheckState, type ChangeNode } from "../changes";
|
||||
import {
|
||||
aggregateCheck,
|
||||
buildChangeTree,
|
||||
commitRepos,
|
||||
initialCheck,
|
||||
planCommit,
|
||||
type CheckState,
|
||||
type ChangeNode,
|
||||
} from "../changes";
|
||||
import { rootOf } from "../model";
|
||||
|
||||
const fs = (rel: string, staged: FileStatus["staged"], unstaged: FileStatus["unstaged"]): FileStatus => ({
|
||||
path: `/r/${rel}`,
|
||||
@@ -54,6 +63,56 @@ describe("buildChangeTree", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("several repositories", () => {
|
||||
const nested = [...status, fs("libs/core/Lib.kt", null, "modified"), fs("libs/core/new.txt", null, "untracked")];
|
||||
const repos = ["/r", "/r/libs/core"];
|
||||
|
||||
it("groups each change group by repository", () => {
|
||||
expect(shape(buildChangeTree(nested, "/r", false, undefined, repos))).toEqual([
|
||||
"Merge Conflicts",
|
||||
" r",
|
||||
" conf.yml",
|
||||
"Changes",
|
||||
" r",
|
||||
" App.kt",
|
||||
" AppTest.kt",
|
||||
" Partial.kt",
|
||||
" README.md",
|
||||
" libs/core",
|
||||
" Lib.kt",
|
||||
"Unversioned Files",
|
||||
" r",
|
||||
" notes.txt",
|
||||
" libs/core",
|
||||
" new.txt",
|
||||
]);
|
||||
const changes = buildChangeTree(nested, "/r", true, undefined, repos)[1]!;
|
||||
expect(changes.children!.map((n) => [n.label, n.path])).toEqual([
|
||||
["r", "/r"],
|
||||
["libs/core", "/r/libs/core"],
|
||||
]);
|
||||
expect(shape(changes.children![1]!.children!)).toEqual(["Lib.kt"]);
|
||||
// One repository: no repository level.
|
||||
const single = buildChangeTree(status, "/r", false, undefined, ["/r"]);
|
||||
expect(shape(single)).toEqual(shape(buildChangeTree(status, "/r", false)));
|
||||
});
|
||||
|
||||
it("commits every repository with included changes, the selected one last", () => {
|
||||
const included = [nested[0]!, nested[7]!];
|
||||
expect(commitRepos(included, repos, "/r")).toEqual(["/r/libs/core", "/r"]);
|
||||
expect(commitRepos(included.slice(0, 1), repos, "/r/libs/core")).toEqual(["/r"]);
|
||||
expect(commitRepos([], repos, "/r/libs/core")).toEqual(["/r/libs/core"]);
|
||||
});
|
||||
|
||||
it("routes a nested repository's own entry (submodule) to the enclosing repository", () => {
|
||||
expect(rootOf("/r/libs/core/Lib.kt", repos)).toBe("/r/libs/core");
|
||||
expect(rootOf("/r/libs/core", repos)).toBe("/r");
|
||||
expect(rootOf("/r/libs/core/", repos)).toBe("/r");
|
||||
expect(rootOf("/r", repos)).toBe("/r");
|
||||
expect(rootOf("/other", repos)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("commit inclusion", () => {
|
||||
it("defaults: tracked changes included, partial files keep their staged part, unversioned excluded", () => {
|
||||
expect(initialCheck(status[0]!)).toBe("all");
|
||||
|
||||
@@ -11,6 +11,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
...real.commands,
|
||||
vcsStatus: () => vcsStatus(),
|
||||
vcsBranchInfo: async () => ({ status: "ok", data: info() }),
|
||||
vcsRoots: async () => ({ status: "ok", data: [{ root: "/p", operation: null }] }),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { FileStatus } from "@/bindings";
|
||||
import { isNestedRepoEntry, rollbackCandidates } from "../changeOps";
|
||||
|
||||
const fs = (rel: string, unstaged: FileStatus["unstaged"]): FileStatus => ({
|
||||
path: `/r/${rel}`,
|
||||
relPath: rel,
|
||||
staged: null,
|
||||
unstaged,
|
||||
renamedFrom: null,
|
||||
});
|
||||
|
||||
describe("rollback candidates with a submodule", () => {
|
||||
const roots = ["/r", "/r/libs/core"];
|
||||
const status = [
|
||||
fs("app.txt", "modified"),
|
||||
fs("libs/core", "modified"),
|
||||
fs("libs/core/core.txt", "modified"),
|
||||
fs("libs/core/wip.txt", "untracked"),
|
||||
];
|
||||
const paths = (files: FileStatus[]) => files.map((f) => f.path);
|
||||
|
||||
it("never offers the submodule's own entry", () => {
|
||||
expect(isNestedRepoEntry("/r/libs/core", roots)).toBe(true);
|
||||
expect(isNestedRepoEntry("/r", roots)).toBe(false);
|
||||
expect(paths(rollbackCandidates(undefined, status, roots))).toEqual(["/r/app.txt", "/r/libs/core/core.txt"]);
|
||||
});
|
||||
|
||||
it("takes a selected change alone, not the submodule's changes below its path", () => {
|
||||
expect(rollbackCandidates(["/r/libs/core"], status, roots)).toEqual([]);
|
||||
expect(paths(rollbackCandidates(["/r/app.txt", "/r/libs/core"], status, roots))).toEqual(["/r/app.txt"]);
|
||||
});
|
||||
|
||||
it("takes the changes below a selected folder", () => {
|
||||
expect(paths(rollbackCandidates(["/r/libs"], status, roots))).toEqual(["/r/libs/core/core.txt"]);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { messageProblems, wrapAtMargin } from "../CommitView";
|
||||
import { linkifyIssues } from "../issueLinks";
|
||||
import { isProtectedBranch, isPushRejected } from "../remoteUi";
|
||||
import { defaultPushChecked, isProtectedBranch, isPushRejected, pushCandidates, type RepoPush } from "../remoteUi";
|
||||
import { attentionRepo } from "../store";
|
||||
import { statusDecorations } from "../model";
|
||||
|
||||
const cfg = { blankLineAfterSubject: true, limitSubject: true, subjectLimit: 10, limitBody: true, bodyLimit: 8 };
|
||||
@@ -59,3 +60,34 @@ describe("git settings helpers", () => {
|
||||
expect(statusDecorations(status, false).get("/p/src/a.ts")?.propagate).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("several repositories", () => {
|
||||
it("selects a repository that just stopped in an operation", () => {
|
||||
expect(attentionRepo("/p", {}, { "/p/lib": "merge" })).toBe("/p/lib");
|
||||
expect(attentionRepo("/p", { "/p/lib": "merge" }, { "/p/lib": "merge" })).toBeNull();
|
||||
expect(attentionRepo("/p", {}, { "/p": "rebase", "/p/lib": "merge" })).toBeNull();
|
||||
expect(attentionRepo("/p", {}, {})).toBeNull();
|
||||
});
|
||||
|
||||
it("lists repositories with something to push", () => {
|
||||
const branch = (head: string | null, upstream: string | null) => ({
|
||||
head,
|
||||
headCommit: "c1",
|
||||
upstream,
|
||||
ahead: 0,
|
||||
behind: 0,
|
||||
operation: null,
|
||||
});
|
||||
const commit = { id: "c1", shortId: "c1" } as RepoPush["commits"][number];
|
||||
const repos: RepoPush[] = [
|
||||
{ root: "/p", branch: branch("main", "origin/main"), commits: [commit] },
|
||||
{ root: "/p/a", branch: branch("main", "origin/main"), commits: [] },
|
||||
{ root: "/p/b", branch: branch("feature", null), commits: [commit] },
|
||||
{ root: "/p/c", branch: branch(null, null), commits: [] },
|
||||
];
|
||||
const candidates = pushCandidates(repos);
|
||||
expect(candidates.map((r) => r.root)).toEqual(["/p", "/p/b"]);
|
||||
expect([...defaultPushChecked(candidates, "/p")]).toEqual(["/p"]);
|
||||
expect([...defaultPushChecked(candidates, "/p/b")]).toEqual(["/p", "/p/b"]);
|
||||
});
|
||||
});
|
||||
@@ -7,7 +7,7 @@ import { editorService, maybeEditorService, notifications, toolWindowService } f
|
||||
import { annotationsShown, toggleAnnotations } from "./blame";
|
||||
import { showBranchesPopup } from "./BranchWidget";
|
||||
import { checkoutRevision, newBranch } from "./branchOps";
|
||||
import { addToVcs, rollbackCandidates, showRollbackDialog, stashChanges } from "./changeOps";
|
||||
import { addToVcs, isNestedRepoEntry, rollbackCandidates, showRollbackDialog, stashChanges } from "./changeOps";
|
||||
import { useCommit } from "./commitStore";
|
||||
import { gotoConflict, resolveAtCaret, showConflictsDialog } from "./conflictsUi";
|
||||
import { focusedDiffNavigator } from "./diffNavigator";
|
||||
@@ -16,11 +16,11 @@ import { openDialog } from "./dialogs";
|
||||
import { gotoChange } from "./gutter";
|
||||
import { openLocalHistory } from "./localHistoryKind";
|
||||
import { revealCommit, setLogFilters, useGitLog, emptyFilters } from "./logStore";
|
||||
import { runRemote } from "./ops";
|
||||
import { allRepos, runRemote } from "./ops";
|
||||
import { showPushDialog, showUpdateDialog, type PushTarget } from "./remoteUi";
|
||||
import { chooseRevision } from "./RevisionChooser";
|
||||
import { showCloneDialog } from "./clone";
|
||||
import { refreshNow } from "./store";
|
||||
import { refreshNow, repoName } from "./store";
|
||||
|
||||
const VCS = "vcsAvailable";
|
||||
|
||||
@@ -150,7 +150,7 @@ export function registerVcsActions(): () => void {
|
||||
category: "Git",
|
||||
icon: "git-fetch",
|
||||
when: VCS,
|
||||
run: () => void runRemote({ op: "fetch" }),
|
||||
run: () => void runRemote({ op: "fetch" }, undefined, allRepos()),
|
||||
},
|
||||
{
|
||||
id: "vcs.refresh",
|
||||
@@ -171,7 +171,18 @@ export function registerVcsActions(): () => void {
|
||||
const explicit = argPaths(arg);
|
||||
const sel = useCommit.getState().selection;
|
||||
const paths = explicit?.length ? explicit : commitWindowFocused() && sel.length ? sel : undefined;
|
||||
if (paths) return showRollbackDialog(rollbackCandidates(paths));
|
||||
if (paths) {
|
||||
const candidates = rollbackCandidates(paths);
|
||||
const submodule = paths.find((p) => isNestedRepoEntry(p));
|
||||
if (!candidates.length && submodule)
|
||||
return notifications().notify({
|
||||
group: "vcs",
|
||||
level: "info",
|
||||
title: "Submodule changes cannot be rolled back here",
|
||||
body: `${repoName(submodule)} points to another commit. Check out the recorded commit in the submodule (git submodule update) to revert it.`,
|
||||
});
|
||||
return showRollbackDialog(candidates);
|
||||
}
|
||||
const active = maybeEditorService()?.activePath();
|
||||
const activeChanged = active ? rollbackCandidates([active]) : [];
|
||||
showRollbackDialog(activeChanged.length ? activeChanged : rollbackCandidates());
|
||||
|
||||
@@ -7,7 +7,7 @@ import { notifications } from "@/workbench/contributions";
|
||||
import { isFavoriteBranch, pushRecent, shortRemoteName } from "./branches";
|
||||
import { confirmDialog, promptText } from "./dialogs";
|
||||
import { runOp, runRemote, saveAll } from "./ops";
|
||||
import { conflictedFiles, refreshNow, useVcs } from "./store";
|
||||
import { conflictedFiles, currentRepo, refreshNow, useVcs } from "./store";
|
||||
|
||||
const recentKey = () => `openidea.vcs.recentBranches:${useVcs.getState().root ?? ""}`;
|
||||
|
||||
@@ -46,7 +46,7 @@ export function validateBranchName(name: string): string | null {
|
||||
export async function checkoutBranch(name: string) {
|
||||
const previous = useVcs.getState().branch?.head;
|
||||
await saveAll();
|
||||
const ok = await runOp(`Checkout ${name}`, () => call(commands.vcsCheckout(name, false)), {
|
||||
const ok = await runOp(`Checkout ${name}`, () => call(commands.vcsCheckout(currentRepo(), name, false)), {
|
||||
success: () => `Checked out ${useVcs.getState().branch?.head ?? name}`,
|
||||
});
|
||||
if (ok !== undefined) {
|
||||
@@ -72,7 +72,8 @@ export async function newBranch(from?: string) {
|
||||
const checkout = r.checked;
|
||||
const previous = useVcs.getState().branch?.head;
|
||||
if (checkout) await saveAll();
|
||||
const ok = await runOp(`Create branch ${r.value}`, () => call(commands.vcsCreateBranch(r.value, from ?? null, checkout)), {
|
||||
const create = () => call(commands.vcsCreateBranch(currentRepo(), r.value, from ?? null, checkout));
|
||||
const ok = await runOp(`Create branch ${r.value}`, create, {
|
||||
success: checkout ? `Created and checked out ${r.value}` : `Created branch ${r.value}`,
|
||||
});
|
||||
if (ok !== undefined && checkout) {
|
||||
@@ -91,7 +92,7 @@ export async function checkoutRevision() {
|
||||
});
|
||||
if (!r) return;
|
||||
await saveAll();
|
||||
await runOp(`Checkout ${r.value}`, () => call(commands.vcsCheckout(r.value, false)), {
|
||||
await runOp(`Checkout ${r.value}`, () => call(commands.vcsCheckout(currentRepo(), r.value, false)), {
|
||||
success: `Checked out ${r.value}`,
|
||||
});
|
||||
}
|
||||
@@ -116,7 +117,7 @@ async function openConflictsInstead(): Promise<boolean> {
|
||||
export async function mergeIntoCurrent(branch: string) {
|
||||
const current = useVcs.getState().branch?.head ?? "HEAD";
|
||||
await saveAll();
|
||||
await runOp(`Merge ${branch} into ${current}`, () => call(commands.vcsMerge(branch)), {
|
||||
await runOp(`Merge ${branch} into ${current}`, () => call(commands.vcsMerge(currentRepo(), branch)), {
|
||||
success: `Merged ${branch} into ${current}`,
|
||||
errorActions: conflictActions,
|
||||
onError: openConflictsInstead,
|
||||
@@ -126,7 +127,7 @@ export async function mergeIntoCurrent(branch: string) {
|
||||
export async function rebaseOnto(branch: string) {
|
||||
const current = useVcs.getState().branch?.head ?? "HEAD";
|
||||
await saveAll();
|
||||
await runOp(`Rebase ${current} onto ${branch}`, () => call(commands.vcsRebase(branch)), {
|
||||
await runOp(`Rebase ${current} onto ${branch}`, () => call(commands.vcsRebase(currentRepo(), branch)), {
|
||||
success: `Rebased ${current} onto ${branch}`,
|
||||
errorActions: conflictActions,
|
||||
onError: openConflictsInstead,
|
||||
@@ -144,7 +145,7 @@ export async function renameBranch(name: string) {
|
||||
});
|
||||
if (!r) return;
|
||||
const to = r.value.trim();
|
||||
const ok = await runOp(`Rename branch ${name}`, () => call(commands.vcsRenameBranch(name, to)), {
|
||||
const ok = await runOp(`Rename branch ${name}`, () => call(commands.vcsRenameBranch(currentRepo(), name, to)), {
|
||||
success: `Renamed branch ${name} to ${to}`,
|
||||
});
|
||||
if (ok !== undefined) {
|
||||
@@ -164,7 +165,7 @@ export async function deleteBranch(name: string) {
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
await runOp(`Delete branch ${name}`, () => call(commands.vcsDeleteBranch(name, false)), {
|
||||
await runOp(`Delete branch ${name}`, () => call(commands.vcsDeleteBranch(currentRepo(), name, false)), {
|
||||
success: `Deleted branch ${name}`,
|
||||
errorActions: (m) =>
|
||||
/not fully merged/i.test(m)
|
||||
@@ -172,7 +173,7 @@ export async function deleteBranch(name: string) {
|
||||
{
|
||||
label: "Force Delete",
|
||||
run: () =>
|
||||
void runOp(`Force delete ${name}`, () => call(commands.vcsDeleteBranch(name, true)), {
|
||||
void runOp(`Force delete ${name}`, () => call(commands.vcsDeleteBranch(currentRepo(), name, true)), {
|
||||
success: `Deleted branch ${name}`,
|
||||
}),
|
||||
},
|
||||
@@ -198,7 +199,7 @@ export async function checkoutAndRebase(name: string) {
|
||||
const current = useVcs.getState().branch?.head;
|
||||
if (!current) return;
|
||||
await saveAll();
|
||||
const ok = await runOp(`Checkout ${name}`, () => call(commands.vcsCheckout(name, false)));
|
||||
const ok = await runOp(`Checkout ${name}`, () => call(commands.vcsCheckout(currentRepo(), name, false)));
|
||||
if (ok === undefined) return;
|
||||
rememberBranch(current);
|
||||
rememberBranch(name);
|
||||
|
||||
@@ -4,14 +4,14 @@ import type { FileStatus } from "@/bindings";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { Checkbox, Dialog, Icon, fileIconName } from "@/ui";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { groupOf, planCommit, renamedFromPath } from "./changes";
|
||||
import { commitRepos, groupOf, planCommit, renamedFromPath } from "./changes";
|
||||
import { useChangelists, withListDefaults } from "./changelists";
|
||||
import { runCommitChecks } from "./commitChecks";
|
||||
import { rememberMessage, useCommit } from "./commitStore";
|
||||
import { confirmDialog, openDialog, promptText } from "./dialogs";
|
||||
import { KIND_COLOR, baseName, dirName, effectiveKind, relTo, stripSlash } from "./model";
|
||||
import { logConsole, runOp, saveAll } from "./ops";
|
||||
import { loadStashes, refreshNow, useVcs } from "./store";
|
||||
import { currentRepo, loadStashes, refreshNow, useVcs } from "./store";
|
||||
import styles from "./common.module.css";
|
||||
|
||||
export function firstLine(message: string): string {
|
||||
@@ -48,18 +48,24 @@ export async function commitChanges(): Promise<string | undefined> {
|
||||
}
|
||||
const candidates = plan.included.map((f) => ({ path: stripSlash(f.path), exists: effectiveKind(f) !== "deleted" }));
|
||||
if (!(await runCommitChecks(candidates, amend))) return undefined;
|
||||
// Like IDEA, every repository with included changes gets a commit with the same message.
|
||||
const repos = commitRepos(plan.included, useVcs.getState().roots, currentRepo());
|
||||
const id = await runOp(
|
||||
amend ? "Amend commit" : "Commit",
|
||||
async () => {
|
||||
if (plan.unstage.length) await call(commands.vcsUnstage(plan.unstage));
|
||||
if (plan.stage.length) await call(commands.vcsStage(plan.stage));
|
||||
return call(commands.vcsCommit(message.trim(), { amend, signOff, author: author.trim() || null, runHooks }));
|
||||
const options = { amend, signOff, author: author.trim() || null, runHooks };
|
||||
let id = "";
|
||||
for (const repo of repos) id = await call(commands.vcsCommit(repo, message.trim(), options));
|
||||
return id;
|
||||
},
|
||||
{
|
||||
success: () => {
|
||||
const n = plan.included.length;
|
||||
const summary = firstLine(message);
|
||||
return `${n} file${n === 1 ? "" : "s"} ${amend ? "amended" : "committed"}${summary ? `: ${summary}` : ""}`;
|
||||
const where = repos.length > 1 ? ` in ${repos.length} repositories` : "";
|
||||
return `${n} file${n === 1 ? "" : "s"} ${amend ? "amended" : "committed"}${where}${summary ? `: ${summary}` : ""}`;
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -71,20 +77,32 @@ export async function commitChanges(): Promise<string | undefined> {
|
||||
}
|
||||
|
||||
/** Files the Rollback action applies to by default. */
|
||||
export function rollbackCandidates(paths?: readonly string[]): FileStatus[] {
|
||||
const status = useVcs.getState().status.filter((f) => {
|
||||
export function rollbackCandidates(
|
||||
paths?: readonly string[],
|
||||
status: readonly FileStatus[] = useVcs.getState().status,
|
||||
roots: readonly string[] = useVcs.getState().roots,
|
||||
): FileStatus[] {
|
||||
// A nested repository's own entry (a submodule's checked-out commit) is not rolled back
|
||||
// from the enclosing repository: it is changed by checking out a commit in the submodule.
|
||||
const changed = status.filter((f) => {
|
||||
const g = groupOf(f);
|
||||
return g === "changes" || g === "conflicts";
|
||||
return (g === "changes" || g === "conflicts") && !isNestedRepoEntry(f.path, roots);
|
||||
});
|
||||
if (!paths?.length) return status;
|
||||
if (!paths?.length) return changed;
|
||||
const set = new Set(paths.map(stripSlash));
|
||||
const picked = status.filter((f) => {
|
||||
// A selected change is just that change; other paths are folders and take the changes below them.
|
||||
const entries = new Set(status.map((f) => stripSlash(f.path)));
|
||||
const folders = [...set].filter((s) => !entries.has(s));
|
||||
return changed.filter((f) => {
|
||||
const p = stripSlash(f.path);
|
||||
if (set.has(p)) return true;
|
||||
for (const s of set) if (p.startsWith(s + "/")) return true;
|
||||
return false;
|
||||
return set.has(p) || folders.some((s) => p.startsWith(s + "/"));
|
||||
});
|
||||
return picked;
|
||||
}
|
||||
|
||||
/** `path` is the root of a repository nested in another one (its submodule / untracked-folder entry there). */
|
||||
export function isNestedRepoEntry(path: string, roots: readonly string[] = useVcs.getState().roots): boolean {
|
||||
const p = stripSlash(path);
|
||||
return roots.includes(p) && roots.some((r) => p.startsWith(r + "/"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,7 +239,7 @@ export async function stashChanges() {
|
||||
});
|
||||
if (!r) return;
|
||||
await saveAll();
|
||||
await runOp("Stash changes", () => call(commands.vcsStashPush(r.value || null, r.checked)), {
|
||||
await runOp("Stash changes", () => call(commands.vcsStashPush(currentRepo(), r.value || null, r.checked)), {
|
||||
success: "Changes stashed",
|
||||
});
|
||||
void loadStashes().catch(() => undefined);
|
||||
@@ -229,7 +247,7 @@ export async function stashChanges() {
|
||||
|
||||
export async function applyStash(index: number, pop: boolean) {
|
||||
await saveAll();
|
||||
await runOp(`${pop ? "Pop" : "Apply"} stash@{${index}}`, () => call(commands.vcsStashApply(index, pop)), {
|
||||
await runOp(`${pop ? "Pop" : "Apply"} stash@{${index}}`, () => call(commands.vcsStashApply(currentRepo(), index, pop)), {
|
||||
success: pop ? `Unstashed stash@{${index}}` : `Applied stash@{${index}}`,
|
||||
});
|
||||
void loadStashes().catch((e) => logConsole("err", String(e)));
|
||||
@@ -243,7 +261,7 @@ export async function dropStash(index: number, message: string) {
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
await runOp(`Drop stash@{${index}}`, () => call(commands.vcsStashDrop(index)), {
|
||||
await runOp(`Drop stash@{${index}}`, () => call(commands.vcsStashDrop(currentRepo(), index)), {
|
||||
success: `Dropped stash@{${index}}`,
|
||||
});
|
||||
void loadStashes().catch((e) => logConsole("err", String(e)));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** Commit tool window model: change groups, directory tree, inclusion (pure). */
|
||||
import type { ChangelistState, FileStatus } from "@/bindings";
|
||||
import { baseName, dirName, effectiveKind, relTo, stripSlash, type EffectiveKind } from "./model";
|
||||
import { baseName, dirName, effectiveKind, relTo, repoLabel, rootOf, stripSlash, type EffectiveKind } from "./model";
|
||||
|
||||
export type GroupId = "conflicts" | "changes" | "unversioned";
|
||||
|
||||
@@ -156,6 +156,37 @@ function childNodes(files: readonly FileStatus[], root: string, group: GroupId,
|
||||
.map((f) => fileNode(f, root, group, true, scope));
|
||||
}
|
||||
|
||||
/** With several repositories, a node per repository (IDEA's "Group by Repository") above the files. */
|
||||
function repoNodes(
|
||||
files: readonly FileStatus[],
|
||||
root: string,
|
||||
group: GroupId,
|
||||
groupByDir: boolean,
|
||||
scope: string,
|
||||
repos: readonly string[],
|
||||
): ChangeNode[] {
|
||||
if (repos.length < 2) return childNodes(files, root, group, groupByDir, scope);
|
||||
const byRepo = new Map<string, FileStatus[]>();
|
||||
for (const f of files) {
|
||||
const repo = rootOf(f.path, repos) ?? root;
|
||||
let list = byRepo.get(repo);
|
||||
if (!list) byRepo.set(repo, (list = []));
|
||||
list.push(f);
|
||||
}
|
||||
const order = (r: string) => (repos.includes(r) ? repos.indexOf(r) : repos.length);
|
||||
return [...byRepo]
|
||||
.sort(([a], [b]) => order(a) - order(b))
|
||||
.map(([repo, own]) => ({
|
||||
key: `${scope}:repo:${repo}`,
|
||||
type: "dir" as const,
|
||||
label: repoLabel(repo, root),
|
||||
group,
|
||||
children: childNodes(own, repo, group, groupByDir, `${scope}@${repo}`),
|
||||
files: own,
|
||||
path: repo,
|
||||
}));
|
||||
}
|
||||
|
||||
function tagList(nodes: ChangeNode[], id: string): ChangeNode[] {
|
||||
for (const n of nodes) {
|
||||
n.changelist = id;
|
||||
@@ -167,13 +198,15 @@ function tagList(nodes: ChangeNode[], id: string): ChangeNode[] {
|
||||
/**
|
||||
* Group roots (Merge Conflicts / Changes / Unversioned Files) with flat or directory
|
||||
* children. With change lists, "Changes" is split into one group per list
|
||||
* (`ChangelistState.files` keys are project-relative paths).
|
||||
* (`ChangelistState.files` keys are project-relative paths). With several
|
||||
* repositories (`repos`), each group's files are grouped by repository first.
|
||||
*/
|
||||
export function buildChangeTree(
|
||||
status: readonly FileStatus[],
|
||||
root: string,
|
||||
groupByDir: boolean,
|
||||
lists?: ChangelistState,
|
||||
repos: readonly string[] = [],
|
||||
): ChangeNode[] {
|
||||
const byGroup = new Map<GroupId, FileStatus[]>();
|
||||
for (const fs of status) {
|
||||
@@ -202,7 +235,7 @@ export function buildChangeTree(
|
||||
type: "group",
|
||||
label: l.name,
|
||||
group: g,
|
||||
children: tagList(childNodes(own, root, g, groupByDir, scope), l.id),
|
||||
children: tagList(repoNodes(own, root, g, groupByDir, scope, repos), l.id),
|
||||
files: own,
|
||||
changelist: l.id,
|
||||
active: l.id === lists.active,
|
||||
@@ -212,7 +245,7 @@ export function buildChangeTree(
|
||||
continue;
|
||||
}
|
||||
if (!files.length) continue;
|
||||
const children = childNodes(files, root, g, groupByDir, g);
|
||||
const children = repoNodes(files, root, g, groupByDir, g, repos);
|
||||
roots.push({ key: `group:${g}`, type: "group", label: GROUP_LABEL[g], group: g, children, files });
|
||||
}
|
||||
return roots;
|
||||
@@ -225,6 +258,20 @@ export interface CommitPlan {
|
||||
included: FileStatus[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Repositories to commit: those holding `included` files (the selected one last, so its
|
||||
* commit id is returned), else just the selected one (amend, concluding a merge).
|
||||
*/
|
||||
export function commitRepos(
|
||||
included: readonly FileStatus[],
|
||||
roots: readonly string[],
|
||||
selected: string | null,
|
||||
): Array<string | null> {
|
||||
const repos = [...new Set(included.map((f) => rootOf(f.path, roots)).filter((r): r is string => !!r))];
|
||||
if (!repos.length) return [selected];
|
||||
return selected && repos.includes(selected) ? [...repos.filter((r) => r !== selected), selected] : repos;
|
||||
}
|
||||
|
||||
/** Absolute path of the source of a staged rename (`renamedFrom` is repository-relative). */
|
||||
export function renamedFromPath(fs: FileStatus): string | null {
|
||||
if (!fs.renamedFrom) return null;
|
||||
|
||||
@@ -13,7 +13,7 @@ import { maybeEditorService, toolWindowService } from "@/workbench/contributions
|
||||
import { ask } from "@/workbench/messages";
|
||||
import { baseName, relTo } from "./model";
|
||||
import { logConsole } from "./ops";
|
||||
import { useVcs } from "./store";
|
||||
import { currentRepo, useVcs } from "./store";
|
||||
import styles from "./common.module.css";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -308,7 +308,7 @@ export async function runCommitChecks(files: readonly CommitCandidate[], amend:
|
||||
}
|
||||
|
||||
if (git.warnCrlf) {
|
||||
const autocrlf = (await call(commands.vcsConfigGet("core.autocrlf")).catch(() => null))?.toLowerCase();
|
||||
const autocrlf = (await call(commands.vcsConfigGet(currentRepo(), "core.autocrlf")).catch(() => null))?.toLowerCase();
|
||||
if (autocrlf !== "true" && autocrlf !== "input") {
|
||||
const crlf: string[] = [];
|
||||
for (const p of existing) {
|
||||
|
||||
@@ -4,7 +4,8 @@ import { call, commands } from "@/platform/ipc";
|
||||
import { editorService, type EditorInput } from "@/workbench/contributions";
|
||||
import { baseName, effectiveKind } from "./model";
|
||||
import { readWorkingText } from "./ops";
|
||||
import { statusOf, useVcs } from "./store";
|
||||
import { renamedFromPath } from "./changes";
|
||||
import { currentRepoRoot, statusOf } from "./store";
|
||||
|
||||
export type DiffSide =
|
||||
/** File content at a git revision (`HEAD`, `:0` = index, a commit id, `<id>^`). */
|
||||
@@ -104,15 +105,16 @@ export function workingDiffData(path: string, line?: number): DiffData {
|
||||
kind === "untracked" || kind === "added"
|
||||
? { type: "text", text: "", label: "(does not exist)" }
|
||||
: st?.renamedFrom
|
||||
? { type: "rev", rev: "HEAD", path: joinRoot(st.renamedFrom), label: `HEAD (${st.renamedFrom})` }
|
||||
? { type: "rev", rev: "HEAD", path: renamedFromPath(st) ?? undefined, label: `HEAD (${st.renamedFrom})` }
|
||||
: { type: "rev", rev: "HEAD" };
|
||||
const right: DiffSide =
|
||||
kind === "deleted" ? { type: "text", text: "", label: "(deleted)" } : { type: "worktree" };
|
||||
return { path, left, right, line };
|
||||
}
|
||||
|
||||
/** A path of the selected repository's log (repository-relative) made absolute. */
|
||||
function joinRoot(rel: string): string {
|
||||
const root = useVcs.getState().root;
|
||||
const root = currentRepoRoot();
|
||||
return root ? `${root}/${rel}` : rel;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
} from "./rebase";
|
||||
import { showApplyPatch, showCreatePatchForChanges, showCreatePatchForCommits } from "./patches";
|
||||
import { deleteShelf, renameShelf, shelveChanges, showShelf, unshelve, useShelf } from "./shelf";
|
||||
import { useVcs } from "./store";
|
||||
import { currentRepo, useVcs } from "./store";
|
||||
|
||||
const VCS = "vcsAvailable";
|
||||
const IN_GIT_LOG = "vcsAvailable && activeToolWindow == git";
|
||||
@@ -83,7 +83,7 @@ function withCommits(fn: (cs: Commit[]) => unknown) {
|
||||
async function openCommitInBrowser(c: Commit) {
|
||||
const upstream = useVcs.getState().branch?.upstream;
|
||||
const remote = upstream ? upstream.slice(0, upstream.indexOf("/")) : "origin";
|
||||
const url = await call(commands.vcsConfigGet(`remote.${remote}.url`)).catch(() => null);
|
||||
const url = await call(commands.vcsConfigGet(currentRepo(), `remote.${remote}.url`)).catch(() => null);
|
||||
const page = url ? commitWebUrl(url, c.id) : null;
|
||||
if (page) await openUrl(page);
|
||||
else notifications().notify({ group: "vcs", level: "warning", title: `No web URL for remote '${remote}'` });
|
||||
@@ -122,7 +122,7 @@ function shelfArg(arg: unknown) {
|
||||
|
||||
async function checkoutCommit(c: Commit) {
|
||||
await saveAll();
|
||||
await runOp(`Checkout ${c.shortId}`, () => call(commands.vcsCheckout(c.id, false)), {
|
||||
await runOp(`Checkout ${c.shortId}`, () => call(commands.vcsCheckout(currentRepo(), c.id, false)), {
|
||||
success: `Checked out ${c.shortId} (detached HEAD)`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Channel } from "@tauri-apps/api/core";
|
||||
import { call, commands, isTauri, nextRequestId } from "@/platform/ipc";
|
||||
import { onWorkflowSettingsChange, workflowSettings } from "@/platform/workflowSettings";
|
||||
import { logConsole } from "./ops";
|
||||
import { loadBranches, refreshNow, useVcs } from "./store";
|
||||
import { currentRepo, loadBranches, refreshNow, useVcs } from "./store";
|
||||
|
||||
const FIRST_DELAY = 20_000;
|
||||
const INTERVAL = 15 * 60_000;
|
||||
@@ -32,7 +32,7 @@ export function installIncomingCheck(): () => void {
|
||||
const channel = new Channel<string>();
|
||||
channel.onmessage = () => undefined;
|
||||
try {
|
||||
await call(commands.vcsRemote(nextRequestId(), { op: "fetch" }, channel));
|
||||
await call(commands.vcsRemote(currentRepo(), nextRequestId(), { op: "fetch" }, channel));
|
||||
await refreshNow();
|
||||
if (useVcs.getState().branchesLoaded) void loadBranches().catch(() => undefined);
|
||||
} catch (e) {
|
||||
|
||||
@@ -4,21 +4,23 @@
|
||||
* merge and Local History editors, remote operations.
|
||||
*/
|
||||
import { onWorkflowSettingsChange, workflowSettings } from "@/platform/workflowSettings";
|
||||
import { registerEditorContribution } from "@/editor/api";
|
||||
import { editorsFor, registerEditorContribution } from "@/editor/api";
|
||||
import {
|
||||
notifications,
|
||||
registerEditorKind,
|
||||
registerMenuGroup,
|
||||
registerOverlay,
|
||||
registerTitleItem,
|
||||
registerToolWindow,
|
||||
} from "@/workbench/contributions";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { getContext } from "@/platform/context";
|
||||
import { lazyComponent } from "@/ui";
|
||||
import { registerVcsActions } from "./actions";
|
||||
import { installChangelists } from "./changelists";
|
||||
import { registerHistoryActions, trackOperationContext } from "./historyActions";
|
||||
import { controlLabel, controlOperation, inProgress } from "./operations";
|
||||
import { blameSlot } from "./blame";
|
||||
import { annotationsShown, blameSlot } from "./blame";
|
||||
import { BranchWidget, useBranchesPopup } from "./BranchWidget";
|
||||
import { showConflictsDialog } from "./conflictsUi";
|
||||
import { registerCompareActions } from "./compare";
|
||||
@@ -103,7 +105,10 @@ export function activate(): () => void {
|
||||
installIncomingCheck(),
|
||||
installFileConfirmations(),
|
||||
// Settings › Git › Sign-off commit: the default of Commit Options › Sign-off Commit.
|
||||
onWorkflowSettingsChange((w) => w.vcs.git.signOff, (signOff) => useCommit.setState({ signOff })),
|
||||
onWorkflowSettingsChange(
|
||||
(w) => w.vcs.git.signOff,
|
||||
(signOff) => useCommit.setState({ signOff }),
|
||||
),
|
||||
registerVcsActions(),
|
||||
registerHistoryActions(),
|
||||
registerLocalHistoryActions(),
|
||||
@@ -159,6 +164,21 @@ export function activate(): () => void {
|
||||
order: 60,
|
||||
extensions: (ctx) => [changeMarkers(ctx), blameSlot()],
|
||||
}),
|
||||
registerMenuGroup({
|
||||
id: "vcs.gutter",
|
||||
menus: ["editorGutter"],
|
||||
order: 10,
|
||||
items: (_menu, { paths: [path] }) => {
|
||||
if (!path || !getContext().vcsAvailable) return [];
|
||||
const shown = editorsFor(path).some((h) => annotationsShown(h.view));
|
||||
return [
|
||||
{
|
||||
label: shown ? "Close Annotations" : "Annotate with Git Blame",
|
||||
run: () => void executeAction("vcs.annotate", path),
|
||||
},
|
||||
];
|
||||
},
|
||||
}),
|
||||
];
|
||||
return () => {
|
||||
onConflictsAppeared(() => undefined);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { call, commands } from "@/platform/ipc";
|
||||
import { workflowSettings } from "@/platform/workflowSettings";
|
||||
import { computeGraph, emptyGraphState, type GraphRow, type GraphState } from "./graph";
|
||||
import { clearConsole, errorMessage } from "./ops";
|
||||
import { useVcs } from "./store";
|
||||
import { currentRepo, repoOf, selectRepo, useVcs } from "./store";
|
||||
|
||||
export interface LogFilters {
|
||||
branch: string | null;
|
||||
@@ -71,19 +71,33 @@ export const useGitLog = create<LogState>(() => ({ ...initialLog(), generation:
|
||||
|
||||
let loadPromise: Promise<void> | null = null;
|
||||
|
||||
/** Another repository (the window switched projects): forget its commits, filters, selection and console. */
|
||||
/**
|
||||
* Another project (the window switched projects): forget its commits, filters, selection
|
||||
* and console. Another repository of the project selected: show its log.
|
||||
*/
|
||||
export function installGitLog(): () => void {
|
||||
return useVcs.subscribe((s, prev) => {
|
||||
if (s.root === prev.root) return;
|
||||
loadPromise = null;
|
||||
useGitLog.setState((l) => ({ ...initialLog(), tab: l.tab, generation: l.generation + 1 }));
|
||||
clearConsole();
|
||||
if (s.root !== prev.root) {
|
||||
loadPromise = null;
|
||||
useGitLog.setState((l) => ({ ...initialLog(), tab: l.tab, generation: l.generation + 1 }));
|
||||
clearConsole();
|
||||
} else if (s.repo !== prev.repo && prev.repo !== null) {
|
||||
const l = useGitLog.getState();
|
||||
if (l.generation === 0 && !l.filters.path) return;
|
||||
const { path } = useGitLog.getState().filters;
|
||||
// A path filter belongs to the repository it is in.
|
||||
if (path && repoOf(path) !== s.repo) useGitLog.setState((l) => ({ filters: { ...l.filters, path: null } }));
|
||||
void reloadLog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function setLogFilters(patch: Partial<LogFilters>) {
|
||||
useGitLog.setState((s) => ({ filters: { ...s.filters, ...patch } }));
|
||||
void reloadLog();
|
||||
// History of a file in another repository: that repository's log.
|
||||
const repo = patch.path ? repoOf(patch.path) : null;
|
||||
if (repo && repo !== currentRepo()) void selectRepo(repo);
|
||||
else void reloadLog();
|
||||
}
|
||||
|
||||
/** Drops loaded commits and loads the first page. */
|
||||
@@ -106,7 +120,15 @@ async function loadOutgoing() {
|
||||
if (!upstream) return useGitLog.setState({ outgoing: null });
|
||||
try {
|
||||
const commits = await call(
|
||||
commands.vcsLog({ branch: "HEAD", path: null, author: null, text: null, range: "@{u}..HEAD", skip: 0, limit: 0 }),
|
||||
commands.vcsLog(currentRepo(), {
|
||||
branch: "HEAD",
|
||||
path: null,
|
||||
author: null,
|
||||
text: null,
|
||||
range: "@{u}..HEAD",
|
||||
skip: 0,
|
||||
limit: 0,
|
||||
}),
|
||||
);
|
||||
useGitLog.setState({ outgoing: new Set(commits.map((c) => c.id)) });
|
||||
} catch {
|
||||
@@ -137,7 +159,7 @@ export function loadMore(): Promise<void> {
|
||||
const p = (async () => {
|
||||
try {
|
||||
const page = await call(
|
||||
commands.vcsLog({
|
||||
commands.vcsLog(currentRepo(), {
|
||||
branch: f.branch,
|
||||
path: f.path,
|
||||
author: f.author.trim() || null,
|
||||
|
||||
@@ -92,6 +92,24 @@ export function relTo(root: string, path: string): string {
|
||||
return path.startsWith(root + "/") ? path.slice(root.length + 1) : path;
|
||||
}
|
||||
|
||||
/**
|
||||
* The innermost of `roots` (repository roots) containing `path`. A nested repository's root
|
||||
* is an entry of the enclosing one (submodule, untracked folder), so it belongs there; to
|
||||
* itself only when no root encloses it (as the backend routes it).
|
||||
*/
|
||||
export function rootOf(path: string, roots: readonly string[]): string | null {
|
||||
const p = stripSlash(path);
|
||||
let best: string | null = null;
|
||||
for (const r of roots) if (p.startsWith(`${r}/`) && (!best || r.length > best.length)) best = r;
|
||||
return best ?? (roots.includes(p) ? p : null);
|
||||
}
|
||||
|
||||
/** Repository name for display: its folder relative to the project, else its folder name. */
|
||||
export function repoLabel(root: string, projectRoot: string | null): string {
|
||||
if (projectRoot && root.startsWith(`${projectRoot}/`)) return root.slice(projectRoot.length + 1);
|
||||
return baseName(root) || root;
|
||||
}
|
||||
|
||||
export function baseName(path: string): string {
|
||||
const p = stripSlash(path);
|
||||
const i = p.lastIndexOf("/");
|
||||
|
||||
@@ -14,7 +14,7 @@ import { openDialog, promptText } from "./dialogs";
|
||||
import { KIND_COLOR, baseName, dirName } from "./model";
|
||||
import { runGitOperation, runOp } from "./ops";
|
||||
import { reloadLog, useGitLog } from "./logStore";
|
||||
import { conflictedFiles, refreshNow, useVcs } from "./store";
|
||||
import { conflictedFiles, currentRepo, currentRepoRoot, refreshNow, repoOf, useVcs } from "./store";
|
||||
import styles from "./common.module.css";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -84,7 +84,10 @@ export async function controlOperation(control: "continue" | "skip" | "abort", e
|
||||
await refreshNow();
|
||||
const op = inProgress();
|
||||
if (!op || (expected && op !== expected)) return notInProgress(expected);
|
||||
if (control === "continue" && conflictedFiles().length) {
|
||||
// Only the selected repository's conflicts block it (others may be in their own merge).
|
||||
const repo = currentRepo();
|
||||
const conflicts = conflictedFiles().filter((f) => !repo || repoOf(f.path) === repo);
|
||||
if (control === "continue" && conflicts.length) {
|
||||
notifications().notify({ group: "vcs", level: "warning", title: "Resolve all conflicts before continuing" });
|
||||
void executeAction("vcs.resolveConflicts");
|
||||
return;
|
||||
@@ -301,7 +304,7 @@ export function validateTagName(name: string, existing: readonly string[] = []):
|
||||
|
||||
/** Log › New Tag…: a lightweight tag on the selected commit. */
|
||||
export async function newTagOn(commit: Commit) {
|
||||
const existing = await call(commands.vcsTags()).catch(() => [] as string[]);
|
||||
const existing = await call(commands.vcsTags(currentRepo())).catch(() => [] as string[]);
|
||||
const r = await promptText({
|
||||
title: `Create New Tag On ${short(commit.id)}`,
|
||||
label: "Enter the name of new tag:",
|
||||
@@ -310,7 +313,8 @@ export async function newTagOn(commit: Commit) {
|
||||
validate: (v) => validateTagName(v, existing),
|
||||
});
|
||||
if (!r) return;
|
||||
const ok = await runOp(`Create tag ${r.value}`, () => call(commands.vcsCreateTag(r.value, commit.id, null, false)), {
|
||||
const create = () => call(commands.vcsCreateTag(currentRepo(), r.value, commit.id, null, false));
|
||||
const ok = await runOp(`Create tag ${r.value}`, create, {
|
||||
success: `Created tag ${r.value} on ${short(commit.id)}`,
|
||||
});
|
||||
// Tags are not part of the refs signature that reloads the log.
|
||||
@@ -329,7 +333,7 @@ function TagDialog({ onClose }: { onClose: () => void }) {
|
||||
const [force, setForce] = useState(false);
|
||||
const [existing, setExisting] = useState<string[]>([]);
|
||||
useEffect(() => {
|
||||
void call(commands.vcsTags()).then(setExisting, () => undefined);
|
||||
void call(commands.vcsTags(currentRepo())).then(setExisting, () => undefined);
|
||||
}, []);
|
||||
const error = validateTagName(name, force ? [] : existing);
|
||||
const run = async () => {
|
||||
@@ -338,7 +342,7 @@ function TagDialog({ onClose }: { onClose: () => void }) {
|
||||
const tag = name.trim();
|
||||
const ok = await runOp(
|
||||
`Create tag ${tag}`,
|
||||
() => call(commands.vcsCreateTag(tag, commit.trim() || "HEAD", message || null, force)),
|
||||
() => call(commands.vcsCreateTag(currentRepo(), tag, commit.trim() || "HEAD", message || null, force)),
|
||||
{ success: `Created tag ${tag}` },
|
||||
);
|
||||
if (ok !== undefined && useGitLog.getState().commits.length) void reloadLog();
|
||||
@@ -405,19 +409,21 @@ function CompareWithLocalDialog({ rev, label, onClose }: { rev: string; label: s
|
||||
const [active, setActive] = useState(0);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
call(commands.vcsDiffWithWorktree(rev))
|
||||
call(commands.vcsDiffWithWorktree(currentRepo(), rev))
|
||||
.then((f) => alive && setFiles(f))
|
||||
.catch((e) => alive && setError(e instanceof Error ? e.message : String(e)));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [rev]);
|
||||
const open = (f: ChangedFile) =>
|
||||
const open = (f: ChangedFile) => {
|
||||
const repoRoot = currentRepoRoot() ?? root;
|
||||
void openDiff({
|
||||
path: `${root}/${f.path}`,
|
||||
left: { type: "rev", rev, label, path: f.oldPath ? `${root}/${f.oldPath}` : undefined },
|
||||
path: `${repoRoot}/${f.path}`,
|
||||
left: { type: "rev", rev, label, path: f.oldPath ? `${repoRoot}/${f.oldPath}` : undefined },
|
||||
right: { type: "worktree" },
|
||||
});
|
||||
};
|
||||
const current = files?.[active];
|
||||
return (
|
||||
<Dialog
|
||||
|
||||
@@ -9,7 +9,7 @@ import { call, commands, emitLocalIdeEvent, isCancelled, nextRequestId } from "@
|
||||
import { editorsFor } from "@/editor/api";
|
||||
import { maybeEditorService, notifications } from "@/workbench/contributions";
|
||||
import { progressFraction } from "./model";
|
||||
import { refreshNow, useVcs } from "./store";
|
||||
import { currentRepo, refreshNow, repoName, useVcs } from "./store";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Console (Git tool window → Console tab)
|
||||
@@ -130,8 +130,21 @@ export function cancelRemote() {
|
||||
if (activeRemote !== null) void commands.cancelRequest(activeRemote);
|
||||
}
|
||||
|
||||
/** Runs fetch / pull / push with progress in the status bar and output in the console. */
|
||||
export async function runRemote(op: RemoteOp, detail?: string): Promise<boolean> {
|
||||
/** Every repository of the project (Fetch and Update Project act on all of them, as in IDEA). */
|
||||
export function allRepos(): Array<string | null> {
|
||||
const roots = useVcs.getState().roots;
|
||||
return roots.length ? roots : [null];
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs fetch / pull / push with progress in the status bar and output in the console,
|
||||
* in each of `repos` (default: the selected repository) in turn.
|
||||
*/
|
||||
export async function runRemote(
|
||||
op: RemoteOp,
|
||||
detail?: string,
|
||||
repos: ReadonlyArray<string | null> = [currentRepo()],
|
||||
): Promise<boolean> {
|
||||
if (useVcs.getState().remoteBusy) {
|
||||
notifications().notify({ group: "vcs", level: "warning", title: "Another remote operation is in progress" });
|
||||
return false;
|
||||
@@ -163,7 +176,28 @@ export async function runRemote(op: RemoteOp, detail?: string): Promise<boolean>
|
||||
task(text || null, progressFraction(text), false);
|
||||
};
|
||||
try {
|
||||
await call(commands.vcsRemote(request, op, channel));
|
||||
// Every repository is tried; the failures are reported together. A pull skips the
|
||||
// repositories that have nothing to pull from (detached HEAD, e.g. submodules; no upstream).
|
||||
const failures: string[] = [];
|
||||
for (const repo of repos) {
|
||||
const name = repos.length > 1 && repo ? repoName(repo) : null;
|
||||
if (name) logConsole("info", name);
|
||||
if (op.op === "pull" && repos.length > 1) {
|
||||
const info = await call(commands.vcsBranchInfo(repo)).catch(() => null);
|
||||
if (info && (!info.head || !info.upstream)) {
|
||||
logConsole("info", info.head ? "No upstream branch, skipped" : "Detached HEAD, skipped");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
await call(commands.vcsRemote(repo, request, op, channel));
|
||||
} catch (e) {
|
||||
if (isCancelled(e) || !name) throw e;
|
||||
logConsole("err", errorMessage(e));
|
||||
failures.push(`${name}: ${errorMessage(e)}`);
|
||||
}
|
||||
}
|
||||
if (failures.length) throw new Error(failures.join("\n"));
|
||||
lastRemoteError = null;
|
||||
notifications().notify({
|
||||
group: "vcs",
|
||||
@@ -239,7 +273,7 @@ export async function runGitOperation(op: GitOperation, opts: GitOperationOption
|
||||
task(line.trim() || null, false);
|
||||
};
|
||||
try {
|
||||
await call(commands.vcsOperation(request, op, channel));
|
||||
await call(commands.vcsOperation(currentRepo(), request, op, channel));
|
||||
let success = opts.success;
|
||||
if (typeof success === "function") {
|
||||
await refreshNow();
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
type RebaseRange,
|
||||
type RebaseRow,
|
||||
} from "./rebasePlan";
|
||||
import { refreshNow, useVcs } from "./store";
|
||||
import { currentRepo, refreshNow, useVcs } from "./store";
|
||||
import styles from "./common.module.css";
|
||||
|
||||
const short = (id: string) => id.slice(0, 8);
|
||||
@@ -56,7 +56,8 @@ export async function undoCommit(commit: Commit) {
|
||||
});
|
||||
if (!ok) return;
|
||||
}
|
||||
const message = await runOp(`Undo commit ${short(commit.id)}`, () => call(commands.vcsUndoCommit(commit.id)), {
|
||||
const undo = () => call(commands.vcsUndoCommit(currentRepo(), commit.id));
|
||||
const message = await runOp(`Undo commit ${short(commit.id)}`, undo, {
|
||||
success: `Undid commit ${short(commit.id)} “${commit.summary}”; its changes are staged`,
|
||||
});
|
||||
// IDEA offers the undone message for the next commit.
|
||||
@@ -78,7 +79,7 @@ async function rangeFrom(target: Commit, verb: string): Promise<RebaseRange | nu
|
||||
const parent = target.parents[0];
|
||||
try {
|
||||
const history = await call(
|
||||
commands.vcsLog({
|
||||
commands.vcsLog(currentRepo(), {
|
||||
branch: "HEAD",
|
||||
path: null,
|
||||
author: null,
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
/** Update Project and Push dialogs. */
|
||||
import { useEffect, useState } from "react";
|
||||
import type { Commit, PushTags, RemoteOp } from "@/bindings";
|
||||
import type { BranchInfo, Commit, PushTags, RemoteOp } from "@/bindings";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { workflowSettings } from "@/platform/workflowSettings";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { Checkbox, Dialog, List, Select, Spinner, T } from "@/ui";
|
||||
import { openDialog } from "./dialogs";
|
||||
import { formatTime } from "./model";
|
||||
import { lastRemoteFailure, runRemote, saveAll } from "./ops";
|
||||
import { refreshNow, useVcs } from "./store";
|
||||
import { allRepos, lastRemoteFailure, runRemote, saveAll } from "./ops";
|
||||
import { currentRepo, refreshNow, repoName, useVcs } from "./store";
|
||||
import styles from "./common.module.css";
|
||||
|
||||
export function showUpdateDialog() {
|
||||
@@ -22,7 +23,14 @@ function UpdateDialog({ onClose }: { onClose: () => void }) {
|
||||
const run = async () => {
|
||||
onClose();
|
||||
await saveAll();
|
||||
await runRemote({ op: "pull", rebase }, branch?.upstream ? `${branch.head} ← ${branch.upstream}` : undefined);
|
||||
const repos = allRepos();
|
||||
const detail =
|
||||
repos.length > 1
|
||||
? `${repos.length} repositories`
|
||||
: branch?.upstream
|
||||
? `${branch.head} ← ${branch.upstream}`
|
||||
: undefined;
|
||||
await runRemote({ op: "pull", rebase }, detail, repos);
|
||||
};
|
||||
return (
|
||||
<Dialog
|
||||
@@ -70,8 +78,8 @@ function UpdateDialog({ onClose }: { onClose: () => void }) {
|
||||
);
|
||||
}
|
||||
|
||||
const logOf = (branch: string, limit: number, range: string | null = null) =>
|
||||
call(commands.vcsLog({ branch, path: null, author: null, text: null, range, skip: 0, limit }));
|
||||
const logOf = (branch: string, limit: number, range: string | null = null, repo = currentRepo()) =>
|
||||
call(commands.vcsLog(repo, { branch, path: null, author: null, text: null, range, skip: 0, limit }));
|
||||
|
||||
/** Outgoing commits of the current branch: `@{u}..HEAD`, or recent HEAD history without an upstream. */
|
||||
export function outgoingQuery(upstream: string | null): { branch: string; range: string | null; limit: number } {
|
||||
@@ -87,7 +95,174 @@ export interface PushTarget {
|
||||
|
||||
export async function showPushDialog(target: PushTarget = {}) {
|
||||
await refreshNow();
|
||||
openDialog((close) => <PushDialog target={target} onClose={close} />);
|
||||
// Several repositories: IDEA's dialog lists each one with outgoing commits.
|
||||
const multi = useVcs.getState().roots.length > 1 && !target.branch && !target.revision;
|
||||
openDialog((close) => (multi ? <MultiPushDialog onClose={close} /> : <PushDialog target={target} onClose={close} />));
|
||||
}
|
||||
|
||||
/** A repository in the multi-repository Push dialog. */
|
||||
export interface RepoPush {
|
||||
root: string;
|
||||
branch: BranchInfo;
|
||||
commits: Commit[];
|
||||
}
|
||||
|
||||
/** Repositories with something to push: outgoing commits, or a branch without upstream. */
|
||||
export function pushCandidates(repos: readonly RepoPush[]): RepoPush[] {
|
||||
return repos.filter((r) => r.branch.head && (r.branch.upstream ? r.commits.length > 0 : true));
|
||||
}
|
||||
|
||||
/** Checked by default: repositories with outgoing commits (a new branch only in the selected one). */
|
||||
export function defaultPushChecked(repos: readonly RepoPush[], selected: string | null): Set<string> {
|
||||
return new Set(repos.filter((r) => (r.branch.upstream ? r.commits.length > 0 : r.root === selected)).map((r) => r.root));
|
||||
}
|
||||
|
||||
type PushRow = { type: "repo"; repo: RepoPush } | { type: "commit"; repo: RepoPush; commit: Commit };
|
||||
|
||||
function MultiPushDialog({ onClose }: { onClose: () => void }) {
|
||||
const roots = useVcs((s) => s.roots);
|
||||
const [repos, setRepos] = useState<RepoPush[] | null>(null);
|
||||
const [checked, setChecked] = useState<Set<string>>(() => new Set());
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [force, setForce] = useState(false);
|
||||
const [pushTags, setPushTags] = useState(false);
|
||||
const [tagsMode, setTagsMode] = useState<PushTags>("all");
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
// A repository that cannot be read (e.g. its upstream branch was deleted) is left out.
|
||||
Promise.allSettled(
|
||||
roots.map(async (root) => {
|
||||
const branch = await call(commands.vcsBranchInfo(root));
|
||||
const q = outgoingQuery(branch.upstream);
|
||||
const commits = branch.head ? await logOf(q.branch, q.limit, q.range, root) : [];
|
||||
return { root, branch, commits };
|
||||
}),
|
||||
).then((results) => {
|
||||
if (!alive) return;
|
||||
const loaded = results.flatMap((r) => (r.status === "fulfilled" ? [r.value] : []));
|
||||
const failed = results.find((r): r is PromiseRejectedResult => r.status === "rejected");
|
||||
if (!loaded.length && failed) {
|
||||
setError(failed.reason instanceof Error ? failed.reason.message : String(failed.reason));
|
||||
return;
|
||||
}
|
||||
const list = pushCandidates(loaded);
|
||||
setRepos(list);
|
||||
setChecked(defaultPushChecked(list, currentRepo()));
|
||||
});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [roots]);
|
||||
|
||||
const toggle = (root: string) =>
|
||||
setChecked((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (!next.delete(root)) next.add(root);
|
||||
return next;
|
||||
});
|
||||
const targetOf = (r: RepoPush) => (r.branch.upstream ? r.branch.upstream.slice(r.branch.upstream.indexOf("/") + 1) : r.branch.head!);
|
||||
const picked = (repos ?? []).filter((r) => checked.has(r.root));
|
||||
const push = async () => {
|
||||
onClose();
|
||||
for (const r of picked) {
|
||||
const upstream = r.branch.upstream;
|
||||
const ok = await pushWithAutoUpdate(
|
||||
{
|
||||
op: "push",
|
||||
force_with_lease: force && !isProtectedBranch(targetOf(r)),
|
||||
set_upstream: !upstream,
|
||||
tags: pushTags ? tagsMode : null,
|
||||
},
|
||||
`${repoName(r.root)}: ${r.branch.head} → ${upstream ?? "new remote branch"}`,
|
||||
r.root,
|
||||
);
|
||||
if (!ok) return;
|
||||
}
|
||||
};
|
||||
const rows: PushRow[] = (repos ?? []).flatMap((repo) => [
|
||||
{ type: "repo" as const, repo },
|
||||
...repo.commits.map((commit) => ({ type: "commit" as const, repo, commit })),
|
||||
]);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open
|
||||
title="Push Commits"
|
||||
onClose={onClose}
|
||||
width={620}
|
||||
footerStart={
|
||||
<>
|
||||
<Checkbox checked={force} onChange={setForce} label="Force (with lease)" />
|
||||
<Checkbox checked={pushTags} onChange={setPushTags} label="Push tags:" />
|
||||
<Select<PushTags>
|
||||
value={tagsMode}
|
||||
disabled={!pushTags}
|
||||
aria-label="Tags to push"
|
||||
onChange={setTagsMode}
|
||||
options={[
|
||||
{ value: "all", label: "All" },
|
||||
{ value: "currentBranch", label: "Current Branch" },
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
buttons={[
|
||||
{
|
||||
label: force ? "Force Push" : "Push",
|
||||
role: "default",
|
||||
autoFocus: true,
|
||||
disabled: !picked.length,
|
||||
onClick: () => void push(),
|
||||
},
|
||||
{ label: "Cancel", role: "cancel" },
|
||||
]}
|
||||
>
|
||||
<div style={{ height: 340, display: "flex", flexDirection: "column", padding: "14px" }}>
|
||||
{error ? (
|
||||
<div className={styles.error}>{error}</div>
|
||||
) : !repos ? (
|
||||
<div className={styles.empty}>
|
||||
<Spinner size={14} />
|
||||
</div>
|
||||
) : (
|
||||
<List
|
||||
items={rows}
|
||||
getKey={(r) => (r.type === "repo" ? `repo:${r.repo.root}` : `${r.repo.root}:${r.commit.id}`)}
|
||||
rowHeight={22}
|
||||
aria-label="Outgoing commits"
|
||||
className={styles.boxList}
|
||||
// Clicks on the checkbox toggle it themselves.
|
||||
onActivate={(r, _i, e) => {
|
||||
if (r.type === "repo" && !(e.target as HTMLElement | null)?.closest?.("label")) toggle(r.repo.root);
|
||||
}}
|
||||
empty={<span>Everything is up to date</span>}
|
||||
renderItem={(r) =>
|
||||
r.type === "repo" ? (
|
||||
<span className={styles.commitRow} style={{ flex: 1, padding: 0 }}>
|
||||
<Checkbox
|
||||
checked={checked.has(r.repo.root)}
|
||||
onChange={() => toggle(r.repo.root)}
|
||||
label={repoName(r.repo.root)}
|
||||
/>
|
||||
<span className={styles.commitMeta}>
|
||||
{r.repo.branch.head} → {r.repo.branch.upstream ?? tx("new remote branch")}
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
<span className={styles.commitRow} style={{ flex: 1, padding: "0 0 0 24px" }}>
|
||||
<span className={styles.commitHash}>{r.commit.shortId}</span>
|
||||
<span className={styles.commitSubject}>{r.commit.summary}</span>
|
||||
<span className={styles.commitMeta}>{r.commit.author}</span>
|
||||
<span className={styles.commitMeta}>{formatTime(r.commit.timeMs)}</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function PushDialog({ target: pushTarget, onClose }: { target: PushTarget; onClose: () => void }) {
|
||||
@@ -262,16 +437,20 @@ export function isPushRejected(message: string): boolean {
|
||||
* update method) and pushes again ("Auto-update if push of the current branch
|
||||
* was rejected") or offers to.
|
||||
*/
|
||||
export async function pushWithAutoUpdate(op: Extract<RemoteOp, { op: "push" }>, detail: string): Promise<boolean> {
|
||||
if (await runRemote(op, detail)) return true;
|
||||
export async function pushWithAutoUpdate(
|
||||
op: Extract<RemoteOp, { op: "push" }>,
|
||||
detail: string,
|
||||
repo: string | null = currentRepo(),
|
||||
): Promise<boolean> {
|
||||
if (await runRemote(op, detail, [repo])) return true;
|
||||
const error = lastRemoteFailure();
|
||||
if (!error || op.force_with_lease || !isPushRejected(error)) return false;
|
||||
const git = workflowSettings().vcs.git;
|
||||
const updateAndPush = async () => {
|
||||
await saveAll();
|
||||
if (!(await runRemote({ op: "pull", rebase: git.updateMethod === "rebase" }, "updating after rejected push")))
|
||||
return false;
|
||||
return runRemote(op, detail);
|
||||
const pull = { op: "pull" as const, rebase: git.updateMethod === "rebase" };
|
||||
if (!(await runRemote(pull, "updating after rejected push", [repo]))) return false;
|
||||
return runRemote(op, detail, [repo]);
|
||||
};
|
||||
if (git.autoUpdateOnPushRejected) return updateAndPush();
|
||||
notifications().notify({
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
* Repository state shared by all VCS views: working tree status, HEAD /
|
||||
* upstream info, branches and stashes. Refreshed (debounced) on `vcsChanged`
|
||||
* and `fsChanged` events and after every operation.
|
||||
*
|
||||
* A project may hold several repositories (IDEA's VCS roots: nested clones,
|
||||
* submodules). Status covers all of them; branch info, branches and stashes are
|
||||
* those of the selected repository (`repo`), which branch / log / remote
|
||||
* operations act on.
|
||||
*/
|
||||
import { onWorkflowSettingsChange, workflowSettings } from "@/platform/workflowSettings";
|
||||
import { create } from "zustand";
|
||||
@@ -10,12 +15,18 @@ import { call, commands, isTauri, onIdeEvent } from "@/platform/ipc";
|
||||
import { setContext } from "@/platform/context";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { setFileDecorations } from "@/workbench/contributions";
|
||||
import { effectiveKind, statusDecorations, stripSlash } from "./model";
|
||||
import { effectiveKind, repoLabel, rootOf, statusDecorations, stripSlash } from "./model";
|
||||
|
||||
export interface VcsState {
|
||||
/** The open project is a git repository. */
|
||||
available: boolean;
|
||||
root: string | null;
|
||||
/** Repository roots, the project's own repository first. */
|
||||
roots: string[];
|
||||
/** Root → merge / rebase / cherry-pick / revert in progress there. */
|
||||
operations: Record<string, string>;
|
||||
/** The selected repository's root (branch widget, log, push…). */
|
||||
repo: string | null;
|
||||
status: FileStatus[];
|
||||
/** `status` reflects the repository (false until the first refresh). */
|
||||
statusLoaded: boolean;
|
||||
@@ -37,6 +48,9 @@ export interface VcsState {
|
||||
const initial: VcsState = {
|
||||
available: false,
|
||||
root: null,
|
||||
roots: [],
|
||||
operations: {},
|
||||
repo: null,
|
||||
status: [],
|
||||
statusLoaded: false,
|
||||
byPath: new Map(),
|
||||
@@ -53,6 +67,48 @@ const initial: VcsState = {
|
||||
|
||||
export const useVcs = create<VcsState>(() => ({ ...initial }));
|
||||
|
||||
/** Root of the selected repository; `null` = the project's primary one. */
|
||||
export function currentRepo(): string | null {
|
||||
return useVcs.getState().repo;
|
||||
}
|
||||
|
||||
/** Root of the selected repository, which its log's and diffs' repository-relative paths are relative to. */
|
||||
export function currentRepoRoot(): string | null {
|
||||
const s = useVcs.getState();
|
||||
return s.repo ?? s.roots[0] ?? s.root;
|
||||
}
|
||||
|
||||
/** Root of the innermost repository containing `path`. */
|
||||
export function repoOf(path: string, roots: readonly string[] = useVcs.getState().roots): string | null {
|
||||
return rootOf(path, roots);
|
||||
}
|
||||
|
||||
/** Repository name for display. */
|
||||
export function repoName(root: string): string {
|
||||
return repoLabel(root, useVcs.getState().root);
|
||||
}
|
||||
|
||||
/**
|
||||
* A repository that just stopped in a merge / rebase / cherry-pick / revert (e.g. on
|
||||
* conflicts after Update Project) while `shown` has none in progress: it is selected so
|
||||
* the banner, the branch widget and Continue / Abort act on it.
|
||||
*/
|
||||
export function attentionRepo(
|
||||
shown: string | null,
|
||||
before: Record<string, string>,
|
||||
now: Record<string, string>,
|
||||
): string | null {
|
||||
if (shown && now[shown]) return null;
|
||||
return Object.keys(now).find((root) => !before[root]) ?? null;
|
||||
}
|
||||
|
||||
/** Selects the repository branch / log / remote operations act on. */
|
||||
export function selectRepo(root: string): Promise<void> {
|
||||
if (useVcs.getState().repo === root) return Promise.resolve();
|
||||
useVcs.setState({ repo: root, branches: [], branchesLoaded: false, stashes: [], stashesLoaded: false });
|
||||
return refreshNow();
|
||||
}
|
||||
|
||||
export function conflictedFiles(status: readonly FileStatus[] = useVcs.getState().status): FileStatus[] {
|
||||
return status.filter((f) => effectiveKind(f) === "conflicted");
|
||||
}
|
||||
@@ -98,14 +154,41 @@ export function refreshNow(): Promise<void> {
|
||||
useVcs.setState({ loading: true });
|
||||
try {
|
||||
const s = useVcs.getState();
|
||||
const [status, branch, branches, stashes] = await Promise.all([
|
||||
const scoped = Promise.all([
|
||||
call(commands.vcsBranchInfo(s.repo)),
|
||||
s.branchesLoaded ? call(commands.vcsBranches(s.repo)) : Promise.resolve(s.branches),
|
||||
s.stashesLoaded ? call(commands.vcsStashes(s.repo)) : Promise.resolve(s.stashes),
|
||||
]).then(
|
||||
(values) => ({ values }),
|
||||
(error: unknown) => ({ error }),
|
||||
);
|
||||
const [vcsRoots, status, selected] = await Promise.all([
|
||||
call(commands.vcsRoots()),
|
||||
call(commands.vcsStatus()),
|
||||
call(commands.vcsBranchInfo()),
|
||||
s.branchesLoaded ? call(commands.vcsBranches()) : Promise.resolve(s.branches),
|
||||
s.stashesLoaded ? call(commands.vcsStashes()) : Promise.resolve(s.stashes),
|
||||
scoped,
|
||||
]);
|
||||
const roots = vcsRoots.map((r) => r.root);
|
||||
if ("error" in selected) {
|
||||
// The selected repository is gone (removed since the last scan): fall back to the primary one.
|
||||
if (!s.repo || roots.includes(s.repo)) throw selected.error;
|
||||
useVcs.setState({ roots, repo: null, branchesLoaded: false, stashesLoaded: false });
|
||||
void refreshNow();
|
||||
return;
|
||||
}
|
||||
const [branch, branches, stashes] = selected.values;
|
||||
const operations = Object.fromEntries(vcsRoots.filter((r) => r.operation).map((r) => [r.root, r.operation!]));
|
||||
// `null` (before the first refresh) is the primary repository, listed first.
|
||||
const shown = s.repo && roots.includes(s.repo) ? s.repo : (roots[0] ?? null);
|
||||
const repo = attentionRepo(shown, s.operations, operations) ?? shown;
|
||||
useVcs.setState({ operations });
|
||||
if (repo !== s.repo || roots.join("\n") !== s.roots.join("\n")) useVcs.setState({ roots, repo });
|
||||
applyStatus(status, branch);
|
||||
useVcs.setState({ branches, stashes, error: null });
|
||||
// Branch info and branches above are of another repository: load the selected one's.
|
||||
if (repo !== shown || (s.repo && repo !== s.repo)) {
|
||||
useVcs.setState({ branchesLoaded: false, stashesLoaded: false });
|
||||
void refreshNow();
|
||||
}
|
||||
} catch (e) {
|
||||
useVcs.setState({ error: e instanceof Error ? e.message : String(e) });
|
||||
} finally {
|
||||
@@ -127,13 +210,13 @@ export function applyStatus(status: FileStatus[], branch: BranchInfo | null) {
|
||||
}
|
||||
|
||||
export async function loadBranches(): Promise<Branch[]> {
|
||||
const branches = await call(commands.vcsBranches());
|
||||
const branches = await call(commands.vcsBranches(currentRepo()));
|
||||
useVcs.setState({ branches, branchesLoaded: true });
|
||||
return branches;
|
||||
}
|
||||
|
||||
export async function loadStashes(): Promise<Stash[]> {
|
||||
const stashes = await call(commands.vcsStashes());
|
||||
const stashes = await call(commands.vcsStashes(currentRepo()));
|
||||
useVcs.setState({ stashes, stashesLoaded: true });
|
||||
return stashes;
|
||||
}
|
||||
@@ -142,6 +225,17 @@ export function statusOf(path: string): FileStatus | undefined {
|
||||
return useVcs.getState().byPath.get(stripSlash(path));
|
||||
}
|
||||
|
||||
/** Repositories found below a project that is not itself under git (scanned in the background). */
|
||||
async function discoverRoots() {
|
||||
const root = useVcs.getState().root;
|
||||
if (!root || !isTauri()) return;
|
||||
const roots = await call(commands.vcsRoots()).catch(() => []);
|
||||
if (!roots.length || useVcs.getState().root !== root || useVcs.getState().available) return;
|
||||
useVcs.setState({ available: true });
|
||||
setContext("vcsAvailable", true);
|
||||
void refreshNow();
|
||||
}
|
||||
|
||||
/** Tracks the open project and backend events. Returns a disposer. */
|
||||
export function installVcsStore(): () => void {
|
||||
const onProject = () => {
|
||||
@@ -154,12 +248,16 @@ export function installVcsStore(): () => void {
|
||||
setContext("vcsAvailable", available);
|
||||
setFileDecorations("vcs", new Map());
|
||||
if (available && isTauri()) void refreshNow();
|
||||
else if (project) void discoverRoots();
|
||||
};
|
||||
onProject();
|
||||
const unsubProject = useProject.subscribe((s, prev) => {
|
||||
if (s.project !== prev.project) onProject();
|
||||
});
|
||||
const offVcs = onIdeEvent("vcsChanged", () => scheduleRefresh(200));
|
||||
const offVcs = onIdeEvent("vcsChanged", () => {
|
||||
if (useVcs.getState().available) scheduleRefresh(200);
|
||||
else void discoverRoots();
|
||||
});
|
||||
const offFs = onIdeEvent("fsChanged", () => scheduleRefresh(250));
|
||||
const offSettings = onWorkflowSettingsChange(
|
||||
(s) => s.vcs.showDirtyDirectories,
|
||||
|
||||
@@ -11,7 +11,11 @@ export interface LanguagesValid {
|
||||
rust: { toolchain: string; stdlib: string; checkOnSave: boolean; checkCommand: "check" | "clippy"; rustfmtArgs: string };
|
||||
go: { goroot: string; gopath: string };
|
||||
typescript: { version: string };
|
||||
java: { jdtlsVmArgs: string };
|
||||
java: {
|
||||
jdk: string;
|
||||
jdtlsVmArgs: string;
|
||||
maven: { home: string; userSettings: string; localRepository: string };
|
||||
};
|
||||
}
|
||||
|
||||
export interface ProjectStructureValid {
|
||||
@@ -30,7 +34,7 @@ export const DEFAULT_LANGUAGES: LanguagesValid = {
|
||||
rust: { toolchain: "", stdlib: "", checkOnSave: true, checkCommand: "check", rustfmtArgs: "" },
|
||||
go: { goroot: "", gopath: "" },
|
||||
typescript: { version: "bundled" },
|
||||
java: { jdtlsVmArgs: "" },
|
||||
java: { jdk: "", jdtlsVmArgs: "", maven: { home: "", userSettings: "", localRepository: "" } },
|
||||
};
|
||||
|
||||
export const DEFAULT_PROJECT_STRUCTURE: ProjectStructureValid = {
|
||||
@@ -76,6 +80,7 @@ export function validateLanguages(raw: unknown): LanguagesValid {
|
||||
const go = obj(l.go);
|
||||
const ts = obj(l.typescript);
|
||||
const java = obj(l.java);
|
||||
const maven = obj(java.maven);
|
||||
return {
|
||||
python: {
|
||||
interpreter: text(py.interpreter, d.python.interpreter),
|
||||
@@ -94,7 +99,15 @@ export function validateLanguages(raw: unknown): LanguagesValid {
|
||||
},
|
||||
go: { goroot: text(go.goroot, d.go.goroot), gopath: text(go.gopath, d.go.gopath) },
|
||||
typescript: { version: text(ts.version, d.typescript.version) || d.typescript.version },
|
||||
java: { jdtlsVmArgs: text(java.jdtlsVmArgs, d.java.jdtlsVmArgs) },
|
||||
java: {
|
||||
jdk: text(java.jdk, d.java.jdk),
|
||||
jdtlsVmArgs: text(java.jdtlsVmArgs, d.java.jdtlsVmArgs),
|
||||
maven: {
|
||||
home: text(maven.home, d.java.maven.home),
|
||||
userSettings: text(maven.userSettings, d.java.maven.userSettings),
|
||||
localRepository: text(maven.localRepository, d.java.maven.localRepository),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -345,6 +345,7 @@
|
||||
"Compare with Clipboard": "与剪贴板比较",
|
||||
"Compare with Local": "与本地比较",
|
||||
"Compilation failed: fix the errors and reload again.": "编译失败:请修复错误后重新加载。",
|
||||
"Compiles and runs the project: the default jdtls runtime, Run/Debug, and JAVA_HOME for Maven and Gradle.": "用于编译和运行项目:jdtls 的默认运行时、运行/调试,以及 Maven 和 Gradle 的 JAVA_HOME。",
|
||||
"Compiles the module of the current file": "编译当前文件所在的模块",
|
||||
"Compiles the project's sources and tests with its build system": "使用项目的构建系统编译其源代码和测试",
|
||||
"Completions": "补全",
|
||||
@@ -629,6 +630,7 @@
|
||||
"Evaluate expression (↩) or add a watch (⇧⌘↩)": "计算表达式 (↩) 或添加监视 (⇧⌘↩)",
|
||||
"Evaluate in the debug console": "在调试控制台中计算",
|
||||
"Evaluation result": "计算结果",
|
||||
"Everything is up to date": "一切都是最新的",
|
||||
"Exception Breakpoints": "异常断点",
|
||||
"Exception breakpoints": "异常断点",
|
||||
"Exclude": "排除",
|
||||
@@ -766,6 +768,7 @@
|
||||
"Fragment": "片段",
|
||||
"Frames": "帧",
|
||||
"From Template…": "从模板…",
|
||||
"From settings.xml, else ~/.m2/repository": "取自 settings.xml,否则为 ~/.m2/repository",
|
||||
"Function": "函数",
|
||||
"Function component": "函数组件",
|
||||
"Function with return type": "带返回类型的函数",
|
||||
@@ -1001,6 +1004,7 @@
|
||||
"Local History of all projects will be deleted.": "所有项目的本地历史记录都将被删除。",
|
||||
"Local History: Put Label…": "本地历史记录:添加标签…",
|
||||
"Local History: Show History": "本地历史记录:显示历史记录",
|
||||
"Local repository": "本地仓库",
|
||||
"Locate Duplicates": "查找重复项",
|
||||
"Locate Duplicates…": "查找重复项…",
|
||||
"Location": "位置",
|
||||
@@ -1036,8 +1040,10 @@
|
||||
"Matches": "匹配项",
|
||||
"Maven actions": "Maven 操作",
|
||||
"Maven command line": "Maven 命令行",
|
||||
"Maven home path": "Maven 主路径",
|
||||
"Maven projects": "Maven 项目",
|
||||
"Maven sync finished with errors": "Maven 同步完成,但有错误",
|
||||
"Maven wrapper, else mvn on PATH": "Maven wrapper,否则使用 PATH 中的 mvn",
|
||||
"Maximize": "最大化",
|
||||
"Maximize Tool Window": "最大化工具窗口",
|
||||
"Maximum local history size per project": "每个项目的最大本地历史记录大小",
|
||||
@@ -1301,6 +1307,8 @@
|
||||
"Parses (hit / incr. / full)": "解析(命中/增量/完整)",
|
||||
"Partially staged: only staged hunks are committed": "部分暂存:仅提交已暂存的块",
|
||||
"Passed": "已通过",
|
||||
"Passed as -Dmaven.repo.local.": "以 -Dmaven.repo.local 传入。",
|
||||
"Passed as -s (mirrors, servers, proxies).": "以 -s 传入(镜像、服务器、代理)。",
|
||||
"Passed to rustfmt when reformatting, e.g. --edition 2024": "重新格式化时传递给 rustfmt,例如 --edition 2024",
|
||||
"Passed to the JVM running jdtls (java.jdt.ls.vmargs), e.g. -Xmx2g. A Lombok agent is added automatically when the project uses Lombok.": "传递给运行 jdtls 的 JVM (java.jdt.ls.vmargs),例如 -Xmx2g。项目使用 Lombok 时会自动添加 Lombok 代理。",
|
||||
"Password": "密码",
|
||||
@@ -1394,6 +1402,7 @@
|
||||
"Project Errors": "项目错误",
|
||||
"Project Files": "项目文件",
|
||||
"Project GOPATH": "项目 GOPATH",
|
||||
"Project JDK": "项目 JDK",
|
||||
"Project Production Files": "项目生产文件",
|
||||
"Project Settings": "项目设置",
|
||||
"Project Structure": "项目结构",
|
||||
@@ -1428,6 +1437,7 @@
|
||||
"Purple": "紫色",
|
||||
"Push": "推送",
|
||||
"Push All up to Here…": "推送到此处为止的所有提交…",
|
||||
"Push Commits": "推送提交",
|
||||
"Push rejected": "推送被拒绝",
|
||||
"Push tags:": "推送标签:",
|
||||
"Push…": "推送…",
|
||||
@@ -1556,6 +1566,7 @@
|
||||
"Replacements": "替换项",
|
||||
"Replacing…": "正在替换…",
|
||||
"Reports errors and warnings from language servers.": "报告来自语言服务器的错误和警告。",
|
||||
"Repository": "仓库",
|
||||
"Request": "请求",
|
||||
"Request Changes…": "请求更改…",
|
||||
"Require": "必需",
|
||||
@@ -1669,6 +1680,7 @@
|
||||
"Runs Maven with -o": "使用 -o 运行 Maven",
|
||||
"Runs Optimize Imports when the file has no errors, unless it would change the caret line.": "文件没有错误时运行“优化导入”,除非这会更改光标所在行。",
|
||||
"Runs npm scripts and Node-based language servers (vtsls, eslint, pyright…).": "运行 npm 脚本和基于 Node 的语言服务器(vtsls、eslint、pyright…)。",
|
||||
"Runs sync, builds and Maven run configurations. A chosen home is used instead of the project's mvnw.": "用于同步、构建和 Maven 运行配置。选定后将代替项目的 mvnw。",
|
||||
"Runs the language server's Organize Imports action.": "运行语言服务器的“整理导入”操作。",
|
||||
"Runs the language server's formatter before an explicit save (Actions on Save).": "在显式保存前运行语言服务器的格式化程序(保存时操作)。",
|
||||
"Runs this project": "运行此项目",
|
||||
@@ -1727,6 +1739,10 @@
|
||||
"Select Base Interpreter": "选择基础解释器",
|
||||
"Select Folders…": "选择文件夹…",
|
||||
"Select GOPATH": "选择 GOPATH",
|
||||
"Select JDK Home Directory": "选择 JDK 主目录",
|
||||
"Select Local Repository": "选择本地仓库",
|
||||
"Select Maven Home Directory": "选择 Maven 主目录",
|
||||
"Select Maven settings.xml": "选择 Maven settings.xml",
|
||||
"Select Next Tab": "选择下一个标签页",
|
||||
"Select Opened File": "选择已打开的文件",
|
||||
"Select Previous Tab": "选择上一个标签页",
|
||||
@@ -1929,6 +1945,7 @@
|
||||
"Structure unavailable": "结构不可用",
|
||||
"Subject line length": "主题行长度",
|
||||
"Submit": "提交",
|
||||
"Submodule changes cannot be rolled back here": "子模块的变更无法在此回滚",
|
||||
"Subpixel": "子像素",
|
||||
"Suggested names": "建议的名称",
|
||||
"Super Method": "超方法",
|
||||
@@ -2140,6 +2157,7 @@
|
||||
"Used for new files.": "用于新文件。",
|
||||
"User": "用户",
|
||||
"User name or email": "用户名或电子邮件",
|
||||
"User settings file": "用户设置文件",
|
||||
"User:": "用户:",
|
||||
"Uses HostName, User, Port, IdentityFile and ProxyJump from ~/.ssh/config, and keys of the SSH agent.": "使用 ~/.ssh/config 中的 HostName、User、Port、IdentityFile 和 ProxyJump,以及 SSH 代理中的密钥。",
|
||||
"VCS Operations": "VCS 操作",
|
||||
@@ -2242,6 +2260,7 @@
|
||||
"match expression": "match 表达式",
|
||||
"match one node,": "匹配一个节点,",
|
||||
"new column definition": "新列定义",
|
||||
"new remote branch": "新远程分支",
|
||||
"new table definition": "新表定义",
|
||||
"new view definition": "新视图定义",
|
||||
"no file is open in the editor": "编辑器中没有打开的文件",
|
||||
@@ -2251,6 +2270,7 @@
|
||||
"occurrences ·": "个匹配项 ·",
|
||||
"or click a line number to set a breakpoint.": "或点击行号设置断点。",
|
||||
"or pick one in the toolbar.": "或在工具栏中选择一个。",
|
||||
"per module, the JDK of its Java version": "按模块使用与其 Java 版本匹配的 JDK",
|
||||
"pip output": "pip 输出",
|
||||
"places the caret. A line with": "放置光标。包含",
|
||||
"println! with Debug": "使用 Debug 的 println!",
|
||||
@@ -2293,5 +2313,16 @@
|
||||
"Group By": "分组依据",
|
||||
"The search hit its limit; only usages found so far are replaced.": "搜索已达上限,只替换目前找到的用法。",
|
||||
"Review": "审查",
|
||||
"Commit and Push…": "提交并推送…"
|
||||
"Commit and Push…": "提交并推送…",
|
||||
"Language server": "语言服务器",
|
||||
"Path": "路径",
|
||||
"Missing": "缺失",
|
||||
"Leave empty to use the IDE-installed copy, else the one on PATH.": "留空则使用 IDE 安装的副本,否则使用 PATH 上的版本。",
|
||||
"Installs into the IDE's own tools folder via": "安装到 IDE 自己的工具目录,方式:",
|
||||
"No tool selected": "未选择工具",
|
||||
"Use auto-detected": "使用自动检测",
|
||||
"Custom": "自定义",
|
||||
"On PATH": "PATH 中",
|
||||
"Reinstall": "重新安装",
|
||||
"Auto-detect": "自动检测"
|
||||
}
|
||||
@@ -72,13 +72,35 @@
|
||||
flex: none;
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.sizer {
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
visibility: hidden;
|
||||
}
|
||||
/* Mirrors a List row: inset, padding and gap. */
|
||||
.sizerRow {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin: 0 var(--list-inset, 6px);
|
||||
padding: 0 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.optionLabel {
|
||||
flex: 1;
|
||||
flex: 1 0 auto;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* The label keeps its width (up to most of the row); a long detail (a path) is cut instead. */
|
||||
.withDetail {
|
||||
max-width: 70%;
|
||||
}
|
||||
.detail {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.detail {
|
||||
white-space: nowrap;
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.disabled {
|
||||
|
||||
@@ -127,6 +127,16 @@ export function Select<V extends string = string>({
|
||||
className={styles.popup}
|
||||
>
|
||||
<div tabIndex={-1} data-autofocus onKeyDown={onPopupKey} className={styles.popupInner}>
|
||||
{/* Virtualised rows are absolutely positioned; this sizes the popup to the widest label. */}
|
||||
<div aria-hidden className={styles.sizer}>
|
||||
{options.map((o) => (
|
||||
<div key={o.value} className={styles.sizerRow}>
|
||||
<span className={styles.check} />
|
||||
{o.icon && <Icon name={o.icon} size={14} />}
|
||||
<span>{tx(o.label)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<List
|
||||
items={options}
|
||||
getKey={(o) => o.value}
|
||||
@@ -144,8 +154,12 @@ export function Select<V extends string = string>({
|
||||
<>
|
||||
<span className={styles.check}>{o.value === value && <Icon name="check" size={12} />}</span>
|
||||
{o.icon && <Icon name={o.icon} size={14} />}
|
||||
<span className={styles.optionLabel}>{tx(o.label)}</span>
|
||||
{o.detail && <span className={styles.detail}>{o.detail}</span>}
|
||||
<span className={clsx(styles.optionLabel, o.detail && styles.withDetail)}>{tx(o.label)}</span>
|
||||
{o.detail && (
|
||||
<span className={styles.detail} title={o.detail}>
|
||||
{tx(o.detail)}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
|
||||
Loaded 100 of 103 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Заблокувати користувача