дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
feat(unreal): support Unreal Engine projects (#5444)
A folder whose top level holds a .uproject is now an Unreal project. The Project tool window switches to an Unreal view: Source is a source root, Config a resources root, and Binaries, Intermediate, Saved and DerivedDataCache are excluded from the tree, index, search and file watching even before Unreal creates them. The root label names the engine the project's EngineAssociation resolves to (HKCU Builds / HKLM InstalledDirectory on Windows; a registered directory that no longer exists is dropped), and three run configurations start UnrealEditor with the project as the editor, as a game (-game) or as a dedicated server (-server), debugged through lldb-dap. Nested projects are detected like Godot and Flutter ones, and the .NET detector skips the same generated directories case-insensitively. Also sets the new field in the remote_dev test ProjectInfo and keeps "Unreal Engine" and the .uproject placeholder in English in the catalogs. Co-authored-by: fengling375 <[email protected]>
Цей коміт міститься в:
1 джерело
1119467ab4
коміт
62e26fa7e3
23 files changed
+457
-16
No files matched your search
Створено
@@ -4816,6 +4816,7 @@ dependencies = [
|
||||
"ide-build",
|
||||
"ide-core",
|
||||
"ide-language",
|
||||
"ide-workspace",
|
||||
"libc",
|
||||
"parking_lot",
|
||||
"portable-pty",
|
||||
@@ -5096,6 +5097,7 @@ dependencies = [
|
||||
"toml_edit 0.25.17+spec-1.1.0",
|
||||
"tracing",
|
||||
"uuid",
|
||||
"winreg 0.56.0",
|
||||
"zip",
|
||||
]
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ pub struct ProjectInfo {
|
||||
pub workspace: Option<ide_workspace::workspace::Workspace>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub unity: Option<ide_workspace::unity::UnityProjectInfo>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub unreal: Option<ide_workspace::unreal::UnrealProjectInfo>,
|
||||
}
|
||||
|
||||
pub fn info(project: &Project) -> ProjectInfo {
|
||||
@@ -45,6 +47,7 @@ pub fn info(project: &Project) -> ProjectInfo {
|
||||
root: project.root.clone().into(),
|
||||
workspace,
|
||||
unity: ide_workspace::unity::detect(&project.root),
|
||||
unreal: ide_workspace::unreal::detect(&project.root),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ license.workspace = true
|
||||
[dependencies]
|
||||
ide-core.workspace = true
|
||||
ide-language.workspace = true
|
||||
ide-workspace.workspace = true
|
||||
dunce.workspace = true
|
||||
encoding_rs.workspace = true
|
||||
serde.workspace = true
|
||||
|
||||
@@ -84,11 +84,16 @@ pub(crate) fn detect_with_profiles(
|
||||
}
|
||||
}
|
||||
detect_projects(root, &["build.zig"], zig::detect, &mut out);
|
||||
dotnet::detect(root, &mut out);
|
||||
// A UE project's `.sln` lists the engine's own tool projects; expanding it would bury the
|
||||
// run menu under dozens of `.NET Project` entries that cannot run from here.
|
||||
if !ide_workspace::unreal::is_project(root) {
|
||||
dotnet::detect(root, &mut out);
|
||||
}
|
||||
detect_projects(root, &["Makefile", "makefile", "GNUmakefile"], detect_make, &mut out);
|
||||
detect_projects(root, &["justfile", "Justfile", ".justfile"], detect_just, &mut out);
|
||||
detect_godot(root, &mut out);
|
||||
detect_projects(root, &["pubspec.yaml"], detect_flutter, &mut out);
|
||||
detect_unreal(root, &mut out);
|
||||
crate::external::detect(root, &mut out);
|
||||
|
||||
let mut seen = HashSet::new();
|
||||
@@ -1608,6 +1613,49 @@ pub(crate) fn just_recipes(src: &str) -> Vec<String> {
|
||||
|
||||
// ---------------------------------------------------------------- godot
|
||||
|
||||
// ---------------------------------------------------------------- unreal
|
||||
|
||||
/// Unreal Engine projects (`.uproject`) run through the engine's editor executable, which reads
|
||||
/// its start-up mode from the command line: no flag is the editor, `-game` the game and `-server`
|
||||
/// a dedicated server. All three exist for every project, blueprint-only ones included, because
|
||||
/// the mode is decided at start-up rather than built.
|
||||
fn detect_unreal(root: &Path, out: &mut Vec<RunConfig>) {
|
||||
detect_projects_matching(root, |dir| ide_workspace::unreal::project_file(dir).is_some(), detect_one_unreal, out);
|
||||
}
|
||||
|
||||
/// One Unreal project: the editor, the game and a dedicated server, all run by the same
|
||||
/// `UnrealEditor.exe` and differing only in the flag.
|
||||
fn detect_one_unreal(root: &Path, out: &mut Vec<RunConfig>) {
|
||||
let Some(info) = ide_workspace::unreal::detect(root) else { return };
|
||||
// Detection already resolved the engine; a project without one offers nothing to run.
|
||||
let Some(found) = info.engine.as_ref() else {
|
||||
tracing::debug!("no Unreal Engine installation for {}", root.display());
|
||||
return;
|
||||
};
|
||||
let engine =
|
||||
ide_workspace::unreal::engine::EngineInstall { id: found.id.clone(), root: PathBuf::from(&found.root) };
|
||||
let Some(project) = ide_workspace::unreal::project_file(root) else { return };
|
||||
let editor = engine.editor().to_string_lossy().into_owned();
|
||||
out.extend(unreal_configs(&project, &editor));
|
||||
}
|
||||
|
||||
/// The editor, the game and a dedicated server: the three start-up modes the engine documents,
|
||||
/// all run by `UnrealEditor.exe` and differing only in the flag.
|
||||
fn unreal_configs(project: &Path, editor: &str) -> Vec<RunConfig> {
|
||||
let project = project.to_string_lossy().into_owned();
|
||||
[
|
||||
("unreal:editor", "Unreal Editor", None),
|
||||
("unreal:game", "Unreal Game", Some("-game")),
|
||||
("unreal:server", "Unreal Server", Some("-server")),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(id, name, flag)| {
|
||||
let args: Vec<&str> = std::iter::once(project.as_str()).chain(flag).collect();
|
||||
config(id.to_owned(), name, "unreal", editor, &args).debug("lldb-dap")
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- rebar3 / mix
|
||||
|
||||
/// rebar3 (Erlang): the shell with the applications started, the EUnit tests and, with
|
||||
@@ -1690,3 +1738,23 @@ fn detect_just(root: &Path, out: &mut Vec<RunConfig>) {
|
||||
out.push(c);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn every_unreal_project_offers_the_editor_the_game_and_a_dedicated_server() {
|
||||
let configs = unreal_configs(Path::new("/p/Game.uproject"), "UE/UnrealEditor.exe");
|
||||
let listed: Vec<(&str, &str)> = configs.iter().map(|c| (c.id.as_str(), c.name.as_str())).collect();
|
||||
assert_eq!(
|
||||
listed,
|
||||
[("unreal:editor", "Unreal Editor"), ("unreal:game", "Unreal Game"), ("unreal:server", "Unreal Server"),]
|
||||
);
|
||||
assert_eq!(configs[0].args, ["/p/Game.uproject"]);
|
||||
assert_eq!(configs[1].args, ["/p/Game.uproject", "-game"]);
|
||||
assert_eq!(configs[2].args, ["/p/Game.uproject", "-server"]);
|
||||
assert!(configs.iter().all(|c| c.command == "UE/UnrealEditor.exe" && c.cwd.is_none()));
|
||||
assert!(configs.iter().all(|c| c.debug_adapter.as_deref() == Some("lldb-dap") && c.kind == "unreal"));
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,15 @@ pub(crate) fn detect(root: &Path, out: &mut Vec<RunConfig>) {
|
||||
let path = entry.path();
|
||||
let name = entry.file_name().to_string_lossy().into_owned();
|
||||
if entry.file_type().is_ok_and(|t| t.is_dir()) {
|
||||
if !name.starts_with('.')
|
||||
// Case-insensitive: Unreal's generated trees (`Binaries`, `Intermediate`, …) hold
|
||||
// tens of thousands of files and copies of the engine's own tool projects.
|
||||
let lower = name.to_ascii_lowercase();
|
||||
if !lower.starts_with('.')
|
||||
&& !matches!(
|
||||
name.as_str(),
|
||||
lower.as_str(),
|
||||
"bin" | "obj" | "node_modules" | "target" | "build" | "dist" | "vendor" | "packages"
|
||||
)
|
||||
&& !ide_workspace::unreal::GENERATED_DIRS.iter().any(|dir| dir.eq_ignore_ascii_case(&lower))
|
||||
{
|
||||
dirs.push(path);
|
||||
}
|
||||
|
||||
@@ -1417,3 +1417,40 @@ fn sbt_projects() {
|
||||
assert_eq!(cmdline(&detect(dir.path())[1]), "./sbt test");
|
||||
}
|
||||
}
|
||||
|
||||
/// UE writes a `.sln` listing the engine's own tool projects; expanding it buries the run menu.
|
||||
#[test]
|
||||
fn a_solution_in_a_unreal_project_is_not_expanded_into_dotnet_configurations() {
|
||||
let dir = project(&[
|
||||
("Game.uproject", r#"{"FileVersion":3,"EngineAssociation":"5.8"}"#),
|
||||
(
|
||||
"Game.sln",
|
||||
r#"Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Game", "Source\Game\Game.csproj", "{00000000-0000-0000-0000-000000000000}"
|
||||
EndProject
|
||||
"#,
|
||||
),
|
||||
(
|
||||
"Source/Game/Game.csproj",
|
||||
r#"<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType></PropertyGroup></Project>"#,
|
||||
),
|
||||
]);
|
||||
let c = detect(dir.path());
|
||||
assert!(c.iter().all(|c| !c.kind.starts_with("dotnet")), "{:?}", ids(&c));
|
||||
}
|
||||
|
||||
/// The engine keeps copies of its tool projects under the generated trees, which hold no code
|
||||
/// anyone runs from here — and on a real project they are deep enough to slow detection down.
|
||||
#[test]
|
||||
fn csproj_under_unreal_generated_directories_is_not_detected() {
|
||||
let exe =
|
||||
r#"<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType></PropertyGroup></Project>"#;
|
||||
let dir = project(&[
|
||||
("Intermediate/ProjectFiles/UnrealBuildTool/UnrealBuildTool.csproj", exe),
|
||||
("Binaries/Win64/ShaderCopy/ShaderCopy.csproj", exe),
|
||||
("Saved/Tools/Helper/Helper.csproj", exe),
|
||||
("DerivedDataCache/Worker/Worker.csproj", exe),
|
||||
]);
|
||||
let c = detect(dir.path());
|
||||
assert!(c.is_empty(), "{:?}", ids(&c));
|
||||
}
|
||||
@@ -25,5 +25,8 @@ uuid.workspace = true
|
||||
zip.workspace = true
|
||||
encoding_rs.workspace = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winreg = "0.56"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile.workspace = true
|
||||
@@ -18,6 +18,7 @@ pub mod roots;
|
||||
pub mod settings;
|
||||
pub mod text_refs;
|
||||
pub mod unity;
|
||||
pub mod unreal;
|
||||
pub mod window_groups;
|
||||
pub mod workspace;
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
//! Unreal Engine project identity, read from the `.uproject` at the root.
|
||||
//!
|
||||
//! Only the root and the engine tree are looked at: everything else in a UE project is
|
||||
//! content, generated output, or engine code, and must never be walked.
|
||||
|
||||
pub mod engine;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Generated directory beside the project root; excluded from the index, the search and the tree.
|
||||
pub const GENERATED_DIRS: &[&str] = &["Binaries", "Intermediate", "Saved", "DerivedDataCache"];
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UnrealProjectInfo {
|
||||
/// The engine the project builds against. `None` means none could be located, which is the
|
||||
/// only reason such a project offers no run configuration at all.
|
||||
pub engine: Option<UnrealEngine>,
|
||||
}
|
||||
|
||||
/// A located engine, shown so a project without run configurations says why.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UnrealEngine {
|
||||
/// `5.8` for a launcher install, or the registry key a source build registered under.
|
||||
pub id: String,
|
||||
/// Absolute engine root.
|
||||
pub root: String,
|
||||
}
|
||||
|
||||
/// The `.uproject` directly inside `root`, picked by name order when a folder has several.
|
||||
pub fn project_file(root: &Path) -> Option<PathBuf> {
|
||||
let mut found: Vec<PathBuf> = std::fs::read_dir(root)
|
||||
.ok()?
|
||||
.flatten()
|
||||
.filter(|e| e.file_type().is_ok_and(|t| t.is_file()))
|
||||
.map(|e| e.path())
|
||||
.filter(|p| p.extension().is_some_and(|ext| ext.eq_ignore_ascii_case("uproject")))
|
||||
.collect();
|
||||
found.sort();
|
||||
found.into_iter().next()
|
||||
}
|
||||
|
||||
pub fn is_project(root: &Path) -> bool {
|
||||
project_file(root).is_some()
|
||||
}
|
||||
|
||||
pub fn detect(root: &Path) -> Option<UnrealProjectInfo> {
|
||||
let file = project_file(root)?;
|
||||
let association = std::fs::read_to_string(&file)
|
||||
.ok()
|
||||
.and_then(|text| serde_json::from_str::<serde_json::Value>(&text).ok())
|
||||
.and_then(|json| json.get("EngineAssociation")?.as_str().map(|v| v.trim().to_owned()))
|
||||
.filter(|v| !v.is_empty());
|
||||
let engine = engine::locate(association.as_deref())
|
||||
.map(|found| UnrealEngine { id: found.id, root: found.root.to_string_lossy().into_owned() });
|
||||
Some(UnrealProjectInfo { engine })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn write(path: &Path, text: &str) {
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(path, text).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_directory_holding_a_uproject_is_a_project() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let root = temp.path();
|
||||
write(&root.join("Arts.uproject"), r#"{"FileVersion":3,"EngineAssociation":"5.8","Plugins":[]}"#);
|
||||
std::fs::create_dir_all(root.join("Content")).unwrap();
|
||||
assert!(is_project(root));
|
||||
assert!(detect(root).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_directory_without_a_uproject_is_not_a_project() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
write(&temp.path().join("Source/Game.Target.cs"), "");
|
||||
assert!(!is_project(temp.path()));
|
||||
assert!(detect(temp.path()).is_none());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
//! Locating an installed Unreal Engine.
|
||||
//!
|
||||
//! A launcher install registers its directory per version under `HKLM` and a source build under
|
||||
//! `HKCU`, keyed by whatever the `.uproject`'s `EngineAssociation` names.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// A registered engine, keyed by whatever the machine calls it.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct EngineInstall {
|
||||
/// `5.8` for a launcher install, a GUID-like key for a source build.
|
||||
pub id: String,
|
||||
pub root: PathBuf,
|
||||
}
|
||||
|
||||
impl EngineInstall {
|
||||
/// The editor executable, which runs every start-up mode.
|
||||
pub fn editor(&self) -> PathBuf {
|
||||
self.root.join("Engine").join("Binaries").join("Win64").join("UnrealEditor.exe")
|
||||
}
|
||||
}
|
||||
|
||||
/// The engine `association` names, following Unreal's own lookup: the association is the key a
|
||||
/// registered directory is stored under, so an unknown or empty one locates nothing.
|
||||
pub fn locate(association: Option<&str>) -> Option<EngineInstall> {
|
||||
pick(installed(), association)
|
||||
}
|
||||
|
||||
fn pick(installs: Vec<EngineInstall>, association: Option<&str>) -> Option<EngineInstall> {
|
||||
let id = association?;
|
||||
// A registered directory that is gone is a leftover from an uninstalled engine.
|
||||
installs.into_iter().find(|i| i.id.eq_ignore_ascii_case(id) && i.root.is_dir())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn installed() -> Vec<EngineInstall> {
|
||||
use winreg::RegKey;
|
||||
use winreg::enums::{HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE};
|
||||
|
||||
let mut out = Vec::new();
|
||||
if let Ok(key) = RegKey::predef(HKEY_LOCAL_MACHINE).open_subkey(r"SOFTWARE\EpicGames\Unreal Engine") {
|
||||
for id in key.enum_keys().flatten() {
|
||||
let Ok(sub) = key.open_subkey(&id) else { continue };
|
||||
let Ok(dir) = sub.get_value::<String, _>("InstalledDirectory") else { continue };
|
||||
if !dir.trim().is_empty() {
|
||||
out.push(EngineInstall { id, root: PathBuf::from(dir) });
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Ok(key) = RegKey::predef(HKEY_CURRENT_USER).open_subkey(r"SOFTWARE\Epic Games\Unreal Engine\Builds") {
|
||||
for (id, _) in key.enum_values().flatten() {
|
||||
let Ok(dir) = key.get_value::<String, _>(&id) else { continue };
|
||||
if !dir.trim().is_empty() {
|
||||
out.push(EngineInstall { id, root: PathBuf::from(dir) });
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn installed() -> Vec<EngineInstall> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A fake install whose directory exists, so `pick` treats it as usable.
|
||||
fn install(dir: &std::path::Path, id: &str) -> EngineInstall {
|
||||
let root = dir.join(format!("UE_{id}"));
|
||||
std::fs::create_dir_all(root.join("Engine/Binaries/Win64")).unwrap();
|
||||
EngineInstall { id: id.to_owned(), root }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_association_picks_that_install_and_nothing_else() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let installs = vec![install(temp.path(), "5.8"), install(temp.path(), "5.3")];
|
||||
assert_eq!(pick(installs.clone(), Some("5.3")).unwrap().id, "5.3");
|
||||
assert_eq!(pick(installs, Some("4.27")), None);
|
||||
assert_eq!(pick(Vec::new(), None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_registered_engine_that_was_deleted_is_not_picked() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let ghost = EngineInstall { id: "5.8".to_owned(), root: temp.path().join("gone") };
|
||||
assert_eq!(pick(vec![ghost], Some("5.8")), None);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
id = "json"
|
||||
name = "JSON"
|
||||
formatter = { tool = "prettier", parser = "json", range = true }
|
||||
extensions = ["json", "geojson", "topojson", "webmanifest", "har", "avsc", "jsonl", "ndjson", "json.map"]
|
||||
extensions = ["json", "geojson", "topojson", "webmanifest", "har", "avsc", "jsonl", "ndjson", "json.map", "uproject", "uplugin"]
|
||||
filenames = [".prettierrc", ".watchmanconfig", "composer.lock", ".arcconfig"]
|
||||
indent = { tab-size = 2, insert-spaces = true }
|
||||
ui-mode = "JSON"
|
||||
|
||||
@@ -1529,6 +1529,7 @@ mod tests {
|
||||
settings: Default::default(),
|
||||
workspace: None,
|
||||
unity: None,
|
||||
unreal: None,
|
||||
})
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
@@ -1463,6 +1463,7 @@ export const commands = {
|
||||
settings: Settings_Serialize,
|
||||
workspace?: Workspace_Serialize | null,
|
||||
unity?: UnityProjectInfo | null,
|
||||
unreal?: UnrealProjectInfo | null,
|
||||
} | null>("project_current"),
|
||||
/**
|
||||
* File › Rename Project…: the project's display name (title bar, recent
|
||||
@@ -11626,6 +11627,7 @@ export type ProjectInfo_Deserialize = {
|
||||
settings: Settings_Deserialize,
|
||||
workspace?: Workspace_Deserialize | null,
|
||||
unity?: UnityProjectInfo | null,
|
||||
unreal?: UnrealProjectInfo | null,
|
||||
};
|
||||
|
||||
export type ProjectInfo_Serialize = {
|
||||
@@ -11637,6 +11639,7 @@ export type ProjectInfo_Serialize = {
|
||||
settings: Settings_Serialize,
|
||||
workspace?: Workspace_Serialize | null,
|
||||
unity?: UnityProjectInfo | null,
|
||||
unreal?: UnrealProjectInfo | null,
|
||||
};
|
||||
|
||||
/** An interpreter another project uses: the project root and the SDK itself. */
|
||||
@@ -14360,6 +14363,22 @@ export type UnityProjectInfo = {
|
||||
projects: string[],
|
||||
};
|
||||
|
||||
/** A located engine, shown so a project without run configurations says why. */
|
||||
export type UnrealEngine = {
|
||||
/** `5.8` for a launcher install, or the registry key a source build registered under. */
|
||||
id: string,
|
||||
/** Absolute engine root. */
|
||||
root: string,
|
||||
};
|
||||
|
||||
export type UnrealProjectInfo = {
|
||||
/**
|
||||
* The engine the project builds against. `None` means none could be located, which is the
|
||||
* only reason such a project offers no run configuration at all.
|
||||
*/
|
||||
engine: UnrealEngine | null,
|
||||
};
|
||||
|
||||
/** A requirement the project's interpreter does not satisfy. */
|
||||
export type UnsatisfiedRequirement = {
|
||||
dependency: ManifestDependency,
|
||||
|
||||
@@ -344,6 +344,14 @@ describe("loose files (LightEdit)", () => {
|
||||
expect(fsReadDir).toHaveBeenCalledWith("/x/a.txt");
|
||||
expect(lightEditOpen).toHaveBeenCalledWith("/x/a.txt");
|
||||
});
|
||||
|
||||
it("opens the folder of a dropped .uproject instead of the file", async () => {
|
||||
windowOpenProject.mockResolvedValue(ok({ kind: "current" }));
|
||||
await openPaths(["/work/Game/Game.uproject"], async () => false);
|
||||
expect(windowOpenFiles).not.toHaveBeenCalled();
|
||||
expect(lightEditOpen).not.toHaveBeenCalled();
|
||||
expect(openProject).toHaveBeenCalledWith("/work/Game");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Open Containing Folder as Project", () => {
|
||||
|
||||
@@ -128,14 +128,19 @@ export async function openFiles(files: readonly string[]): Promise<void> {
|
||||
|
||||
const pathIsDir = (path: string) => call(commands.fsReadDir(path)).then(() => true);
|
||||
|
||||
/** A file that names the project around it: dropping it opens that folder, as a double-click would. */
|
||||
const projectMarker = /\.uproject$/i;
|
||||
|
||||
/** Opens dropped paths: files as loose files ({@link openFiles}), the first folder as a project. */
|
||||
export async function openPaths(
|
||||
paths: readonly string[],
|
||||
isDir: (path: string) => Promise<boolean> = pathIsDir,
|
||||
): Promise<void> {
|
||||
const kinds = await Promise.all(paths.map((p) => isDir(p).catch(() => false)));
|
||||
const files = paths.filter((_, i) => !kinds[i]);
|
||||
const dir = paths.find((_, i) => kinds[i]);
|
||||
// An Unreal project is dragged in as its `.uproject`, which names the folder to open.
|
||||
const marker = paths.find((p, i) => !kinds[i] && projectMarker.test(p));
|
||||
const files = paths.filter((p, i) => !kinds[i] && p !== marker);
|
||||
const dir = paths.find((_, i) => kinds[i]) ?? (marker ? dirname(marker) : undefined);
|
||||
await openFiles(files);
|
||||
if (dir) await openProjectWithPolicy(dir);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,12 @@ export function useProjectTitleMenu(): { label: string; items: MenuItem[] } {
|
||||
const mode = useProjectTree((s) => s.mode);
|
||||
const scope = useProjectTree((s) => s.scope);
|
||||
const unity = useProjectTree((s) => s.unity);
|
||||
const unreal = useProjectTree((s) => s.unreal);
|
||||
// The engine panes only exist in a project of that engine.
|
||||
const available = (id: string) => (id !== "unity" || Boolean(unity)) && (id !== "unreal" || Boolean(unreal));
|
||||
// User scopes (Settings › Scopes) follow the built-in panes, as in IDEA.
|
||||
const scopes = userScopes(useProject((s) => (s.settings as { scopes?: unknown } | null)?.scopes));
|
||||
const items: MenuItem[] = VIEW_MODES.filter(([id]) => id !== "unity" || unity).map(([id, label]) => ({
|
||||
const items: MenuItem[] = VIEW_MODES.filter(([id]) => available(id)).map(([id, label]) => ({
|
||||
id,
|
||||
label,
|
||||
checked: id === mode,
|
||||
|
||||
@@ -62,11 +62,19 @@ export function activate(): () => void {
|
||||
const p = useProject.getState().project;
|
||||
const s = useProjectTree.getState();
|
||||
if ((p?.root ?? null) !== s.root || p?.workspace?.projects !== (s.members ?? undefined))
|
||||
initProjectTree(p?.root ?? null, p?.name ?? "", p?.workspace?.projects ?? null, p?.unity ?? null);
|
||||
initProjectTree(
|
||||
p?.root ?? null,
|
||||
p?.name ?? "",
|
||||
p?.workspace?.projects ?? null,
|
||||
p?.unity ?? null,
|
||||
p?.unreal ?? null,
|
||||
);
|
||||
else if (p) {
|
||||
useProjectTree.setState({ name: p.name, unity: p.unity ?? null });
|
||||
useProjectTree.setState({ name: p.name, unity: p.unity ?? null, unreal: p.unreal ?? null });
|
||||
if (p.unity && !s.unity && s.mode === "project") setViewMode("unity");
|
||||
if (!p.unity && s.mode === "unity") setViewMode("project");
|
||||
if (p.unreal && !s.unreal && s.mode === "project") setViewMode("unreal");
|
||||
if (!p.unreal && s.mode === "unreal") setViewMode("project");
|
||||
}
|
||||
};
|
||||
sync();
|
||||
|
||||
@@ -10,7 +10,10 @@ import { ancestorsWithin, insideAnyOf, isInside, isSameOrInside, nameOf, parentO
|
||||
export interface TreeOptions {
|
||||
/** Applied only by the Unity pane, never persisted as a user preference. */
|
||||
unityRoot?: string;
|
||||
/** Applied only by the Unreal pane, never persisted as a user preference. */
|
||||
unrealRoot?: string;
|
||||
showUnityMeta: boolean;
|
||||
/** Generated build output, shared by the engine panes (Unity's Library, Unreal's Binaries/Intermediate). */
|
||||
showUnityGenerated: boolean;
|
||||
/** Show ignored names (`files.ignoredNames`: `.git`, `.DS_Store`, …). Dotfiles are always shown. */
|
||||
showHidden: boolean;
|
||||
@@ -90,8 +93,21 @@ export function unityPathVisible(path: string, opts: TreeOptions): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** The Unreal pane hides what UBT writes: build output, and the project files it generates. */
|
||||
export function unrealPathVisible(path: string, opts: TreeOptions): boolean {
|
||||
if (opts.unrealRoot && path.startsWith(opts.unrealRoot + "/")) {
|
||||
const relative = path.slice(opts.unrealRoot.length + 1);
|
||||
if (!opts.showUnityGenerated) {
|
||||
if (/^(Binaries|Intermediate|Saved|DerivedDataCache|\.vs)(\/|$)/.test(relative)) return false;
|
||||
if (!relative.includes("/") && /\.(sln|slnx|suo|user|vcxproj|pidb)$/i.test(relative)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function isVisible(entry: FileEntry, opts: TreeOptions): boolean {
|
||||
if (!unityPathVisible(entry.path, opts)) return false;
|
||||
if (!unrealPathVisible(entry.path, opts)) return false;
|
||||
// Ignored names are also excluded on the backend; only "Show Hidden" brings them back.
|
||||
if (isIgnoredName(entry.name)) return opts.showHidden;
|
||||
if (!opts.showExcluded && entry.ignored) return false;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Kept outside React so actions (keyboard, Find Action, context menu) share it.
|
||||
*/
|
||||
import { create } from "zustand";
|
||||
import type { UnityProjectInfo } from "@/bindings";
|
||||
import type { UnrealProjectInfo, UnityProjectInfo } from "@/bindings";
|
||||
import { call } from "@/platform/ipc";
|
||||
import { commands, type FileEntry, type OutlineItem } from "@/bindings";
|
||||
import { withDocument } from "@/editor/lsp/files";
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
visibleEntries,
|
||||
visibleInfo,
|
||||
unityPathVisible,
|
||||
unrealPathVisible,
|
||||
type Placeholder,
|
||||
type ProjectNode,
|
||||
type TreeModel,
|
||||
@@ -89,10 +90,19 @@ function storedOptions(): ViewOptions {
|
||||
}
|
||||
|
||||
/** IDEA's Project view panes ("Project ▾" in the tool window header). */
|
||||
export type ViewMode = "unity" | "project" | "projectFiles" | "openFiles" | "changedFiles" | "scratches" | "scope";
|
||||
export type ViewMode =
|
||||
| "unity"
|
||||
| "unreal"
|
||||
| "project"
|
||||
| "projectFiles"
|
||||
| "openFiles"
|
||||
| "changedFiles"
|
||||
| "scratches"
|
||||
| "scope";
|
||||
|
||||
export const VIEW_MODES: ReadonlyArray<[ViewMode, string]> = [
|
||||
["unity", "Unity"],
|
||||
["unreal", "Unreal"],
|
||||
["project", "Project"],
|
||||
["projectFiles", "Project Files"],
|
||||
["openFiles", "Open Files"],
|
||||
@@ -118,6 +128,7 @@ export interface Clipboard {
|
||||
|
||||
interface ProjectTreeState {
|
||||
unity: UnityProjectInfo | null;
|
||||
unreal: UnrealProjectInfo | null;
|
||||
root: string | null;
|
||||
name: string;
|
||||
members: readonly string[] | null;
|
||||
@@ -172,6 +183,7 @@ function writeJson(key: string, value: unknown) {
|
||||
|
||||
export const useProjectTree = create<ProjectTreeState>(() => ({
|
||||
unity: null,
|
||||
unreal: null,
|
||||
root: null,
|
||||
name: "",
|
||||
members: null,
|
||||
@@ -207,6 +219,7 @@ const set = (patch: Partial<ProjectTreeState>) => useProjectTree.setState(patch)
|
||||
|
||||
let memo: {
|
||||
unity: UnityProjectInfo | null;
|
||||
unreal: UnrealProjectInfo | null;
|
||||
root: string | null;
|
||||
name: string;
|
||||
members: readonly string[] | null;
|
||||
@@ -232,7 +245,9 @@ const filesOf = (s: ProjectTreeState) =>
|
||||
: null;
|
||||
|
||||
function treeOptions(s: ProjectTreeState): TreeOptions {
|
||||
return s.mode === "unity" && s.unity && s.root ? { ...s.options, compact: false, unityRoot: s.root } : s.options;
|
||||
if (s.mode === "unity" && s.unity && s.root) return { ...s.options, compact: false, unityRoot: s.root };
|
||||
if (s.mode === "unreal" && s.unreal && s.root) return { ...s.options, compact: false, unrealRoot: s.root };
|
||||
return s.options;
|
||||
}
|
||||
|
||||
export function selectModel(s: ProjectTreeState): TreeModel {
|
||||
@@ -240,6 +255,7 @@ export function selectModel(s: ProjectTreeState): TreeModel {
|
||||
if (
|
||||
memo &&
|
||||
memo.unity === s.unity &&
|
||||
memo.unreal === s.unreal &&
|
||||
memo.root === s.root &&
|
||||
memo.name === s.name &&
|
||||
memo.members === s.members &&
|
||||
@@ -300,6 +316,8 @@ export function selectModel(s: ProjectTreeState): TreeModel {
|
||||
else model = withExtraRoots(project(), contributed, s.listings, options, placeholder);
|
||||
if (s.unity && s.mode === "unity" && model.roots[0])
|
||||
model.roots[0].detail = s.unity.editorVersion ? `Unity ${s.unity.editorVersion}` : "Unity";
|
||||
if (s.unreal && s.mode === "unreal" && model.roots[0])
|
||||
model.roots[0].detail = s.unreal.engine ? `Unreal ${s.unreal.engine.id}` : "Unreal · engine not found";
|
||||
const libraries = extraFolders(contributed).flatMap((r) =>
|
||||
r.readOnly && r.path !== undefined && isSameOrInside(r.path, s.root!) ? [r.path] : [],
|
||||
);
|
||||
@@ -307,6 +325,7 @@ export function selectModel(s: ProjectTreeState): TreeModel {
|
||||
}
|
||||
memo = {
|
||||
unity: s.unity,
|
||||
unreal: s.unreal,
|
||||
root: s.root,
|
||||
name: s.name,
|
||||
members: s.members,
|
||||
@@ -350,6 +369,7 @@ export function initProjectTree(
|
||||
name = "",
|
||||
members: readonly string[] | null = null,
|
||||
unity: UnityProjectInfo | null = null,
|
||||
unreal: UnrealProjectInfo | null = null,
|
||||
) {
|
||||
cancelExpansion();
|
||||
generation++;
|
||||
@@ -363,8 +383,13 @@ export function initProjectTree(
|
||||
autoExpanded.clear();
|
||||
const previous = get();
|
||||
const previousMode = previous.mode;
|
||||
const engineMode: ViewMode | null = unreal ? "unreal" : unity ? "unity" : null;
|
||||
const mode =
|
||||
unity && previousMode === "project" ? "unity" : !unity && previousMode === "unity" ? "project" : previousMode;
|
||||
engineMode && previousMode === "project"
|
||||
? engineMode
|
||||
: !engineMode && (previousMode === "unity" || previousMode === "unreal")
|
||||
? "project"
|
||||
: previousMode;
|
||||
// Keep the remaining members' types visible while the workspace is rescanned.
|
||||
const projectTypes = new Map<string, ProjectType>();
|
||||
if (root === previous.root && members) {
|
||||
@@ -375,6 +400,7 @@ export function initProjectTree(
|
||||
}
|
||||
set({
|
||||
unity,
|
||||
unreal,
|
||||
mode,
|
||||
root,
|
||||
name,
|
||||
@@ -411,7 +437,7 @@ function initialExpanded(root: string | null, mode: ViewMode, members = get().me
|
||||
// Keys of nodes that no longer exist are inert. Only a first open expands the roots.
|
||||
const scope = projectLocation(root) ?? root;
|
||||
const persisted =
|
||||
mode === "project" || mode === "unity"
|
||||
mode === "project" || mode === "unity" || mode === "unreal"
|
||||
? (readJson<string[]>(expandedKey(scope)) ?? (scope !== root ? readJson<string[]>(expandedKey(root)) : null))
|
||||
: null;
|
||||
if (persisted) return new Set(persisted);
|
||||
@@ -419,11 +445,11 @@ function initialExpanded(root: string | null, mode: ViewMode, members = get().me
|
||||
}
|
||||
|
||||
function persistExpanded() {
|
||||
if (get().mode !== "project" && get().mode !== "unity") return;
|
||||
if (get().mode !== "project" && get().mode !== "unity" && get().mode !== "unreal") return;
|
||||
clearTimeout(persistTimer);
|
||||
persistTimer = setTimeout(() => {
|
||||
const { root, expanded, mode } = get();
|
||||
if (root && (mode === "project" || mode === "unity"))
|
||||
if (root && (mode === "project" || mode === "unity" || mode === "unreal"))
|
||||
writeJson(expandedKey(projectLocation(root) ?? root), [...expanded].slice(0, MAX_PERSISTED));
|
||||
}, 300);
|
||||
}
|
||||
@@ -432,6 +458,7 @@ function persistExpanded() {
|
||||
export function setViewMode(mode: ViewMode) {
|
||||
const s = get();
|
||||
if (mode === "unity" && !s.unity) return;
|
||||
if (mode === "unreal" && !s.unreal) return;
|
||||
if (s.mode === mode) return;
|
||||
cancelExpansion();
|
||||
modeExpanded.set(s.mode, s.expanded);
|
||||
@@ -901,6 +928,8 @@ export function modeShows(path: string, mode = get().mode): boolean {
|
||||
switch (mode) {
|
||||
case "unity":
|
||||
return !!state.unity && unityPathVisible(path, treeOptions({ ...state, mode }));
|
||||
case "unreal":
|
||||
return !!state.unreal && unrealPathVisible(path, treeOptions({ ...state, mode }));
|
||||
case "project":
|
||||
return true;
|
||||
case "projectFiles":
|
||||
|
||||
@@ -205,6 +205,47 @@ const godot: RunConfigTypeContribution = {
|
||||
},
|
||||
};
|
||||
|
||||
const isUProject = (a: string) => !a.startsWith("-") && /\.uproject$/i.test(a);
|
||||
|
||||
/**
|
||||
* Unreal Engine: `<editor> <project>.uproject [-game|-server]`. The editor comes from the
|
||||
* detected configuration (the engine is registered per version); the mode stays in the
|
||||
* arguments, so the editor, a game and a server are the same type.
|
||||
*/
|
||||
const unreal: RunConfigTypeContribution = {
|
||||
id: "unreal",
|
||||
label: "Unreal Engine",
|
||||
icon: "file-cpp",
|
||||
group: "Unreal",
|
||||
description: "Open an Unreal Engine project in the editor, or in game mode",
|
||||
debugAdapter: "lldb-dap",
|
||||
fields: [
|
||||
{
|
||||
key: "project",
|
||||
label: "Project",
|
||||
mono: true,
|
||||
browse: "file",
|
||||
required: true,
|
||||
placeholder: "…/Game.uproject",
|
||||
},
|
||||
{ key: "arguments", label: "Arguments", mono: true, placeholder: "e.g. -game" },
|
||||
],
|
||||
commandLine: (p) => ({
|
||||
command: p.executable || "UnrealEditor.exe",
|
||||
args: [p.project ?? "", ...parseArgs(p.arguments ?? "")],
|
||||
cwd: null,
|
||||
}),
|
||||
paramsFrom(c) {
|
||||
const project = c.args.find(isUProject);
|
||||
if (!project) return null;
|
||||
return {
|
||||
project,
|
||||
arguments: formatArgs(c.args.filter((a) => a !== project)),
|
||||
...(c.command !== "UnrealEditor.exe" ? { executable: c.command } : {}),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
||||
const NPM_COMMANDS = ["run", "test", "start", "install", "ci", "publish", "pack"];
|
||||
|
||||
@@ -576,6 +617,7 @@ export const BUILTIN_TYPES: readonly RunConfigTypeContribution[] = [
|
||||
maven,
|
||||
godot,
|
||||
flutterType,
|
||||
unreal,
|
||||
pythonType,
|
||||
pytest,
|
||||
rubyScriptType,
|
||||
|
||||
@@ -356,6 +356,9 @@ describe("catalogs", () => {
|
||||
"DuckDB",
|
||||
"JDBC URL",
|
||||
"path/to/database.duckdb",
|
||||
// Unreal Engine projects: the product name and the .uproject path placeholder.
|
||||
"Unreal Engine",
|
||||
"…/Game.uproject",
|
||||
]);
|
||||
const translated = SUPPORTED_LOCALES.filter((locale) => locale !== "en").sort();
|
||||
|
||||
|
||||
@@ -5304,6 +5304,12 @@
|
||||
"Scene": "场景",
|
||||
"Main scene": "主场景",
|
||||
"Godot command line options, e.g. --debug-collisions": "Godot 命令行选项,例如 --debug-collisions",
|
||||
"Unreal Engine": "Unreal Engine",
|
||||
"Unreal": "Unreal 项目",
|
||||
"Unreal · engine not found": "Unreal · 未找到引擎",
|
||||
"Open an Unreal Engine project in the editor, or in game mode": "用编辑器打开 Unreal Engine 项目,或以游戏模式运行",
|
||||
"…/Game.uproject": "…/Game.uproject",
|
||||
"e.g. -game": "例如 -game",
|
||||
"Bookmark description": "书签描述",
|
||||
"Cannot open {path}": "无法打开 {path}",
|
||||
"Search context": "搜索上下文",
|
||||
|
||||
@@ -36,6 +36,8 @@ export const PROJECT_TYPES = {
|
||||
godot: { name: "Godot", icon: "file-godot", markers: ["project.godot"] },
|
||||
cmake: { name: "CMake", icon: "file-cmake", markers: ["CMakeLists.txt"] },
|
||||
make: { name: "Make", icon: "file-makefile", markers: ["Makefile", "makefile", "GNUmakefile"] },
|
||||
// Before .NET: the `.sln` a UE project generates belongs to the project, not to C#.
|
||||
unreal: { name: "Unreal Engine", icon: "file-cpp", markers: [/^[^/]+\.uproject$/i] },
|
||||
dotnet: { name: ".NET", icon: "file-csharp", markers: [/^[^/]+\.(?:[cf]sproj|slnx?)$/i] },
|
||||
} as const satisfies Record<string, ProjectTypeDefinition>;
|
||||
|
||||
|
||||
Reference in new issue
Заблокувати користувача