дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 10:07:11 +02:00
fix(sdk): add a JDK from disk in Settings opened from the Welcome screen
sdk_jdk_at was a trusted command, which needs an open trusted project, so Add JDK from Disk on the Welcome screen always failed and the error was shown as 'not a valid home for JDK'. SDKs are IDE-wide: sdk_jdk_at, sdk_flutter_at, sdk_locate_tools and sdk_php_xdebug now run outside Restricted Mode like sdk_detect (a restricted project still refuses them). A failed check now shows its error instead of calling the folder invalid. Fixes #7361
Цей коміт міститься в:
1 джерело
90d98f3edd
коміт
e07a2833f0
5 files changed
+49
-19
No files matched your search
@@ -204,15 +204,15 @@ pub fn sdk_php_effective(host: &Host, window: &str) -> IdeResult<Option<ide_core
|
||||
}
|
||||
|
||||
/// The version of the PHP interpreter `php` and of the Xdebug it loads, run in `cwd` (default: the
|
||||
/// project root).
|
||||
#[command(trust = trusted)]
|
||||
/// project root). Also from Settings on the Welcome screen.
|
||||
#[command(trust = outside_restricted)]
|
||||
pub async fn sdk_php_xdebug(
|
||||
host: &Host,
|
||||
window: &str,
|
||||
php: PathBuf,
|
||||
cwd: Option<PathBuf>,
|
||||
) -> IdeResult<ide_sdk::php::PhpXdebug> {
|
||||
host.require_trust(window)?;
|
||||
host.require_trust_if_project(window)?;
|
||||
let cwd = cwd.or_else(|| host.project(window).ok().map(|p| p.root.clone()));
|
||||
blocking(move || ide_sdk::php::xdebug(&php, cwd.as_deref())).await
|
||||
}
|
||||
@@ -349,14 +349,15 @@ pub async fn sdk_project_libraries(
|
||||
}
|
||||
|
||||
/// Looks up `names` (bare command names): `node_modules/.bin` above `near`, then the search path.
|
||||
#[command(trust = trusted)]
|
||||
/// Also from Settings on the Welcome screen (the PHP interpreter).
|
||||
#[command(trust = outside_restricted)]
|
||||
pub async fn sdk_locate_tools(
|
||||
host: &Host,
|
||||
window: &str,
|
||||
names: Vec<String>,
|
||||
near: Option<PathBuf>,
|
||||
) -> IdeResult<LocatedTools> {
|
||||
host.require_trust(window)?;
|
||||
host.require_trust_if_project(window)?;
|
||||
blocking_value(move || LocatedTools {
|
||||
tools: ide_sdk::locate::locate_tools(&names, near.as_deref()),
|
||||
compile_dir: ide_sdk::locate::compile_dir().into(),
|
||||
@@ -475,16 +476,18 @@ pub async fn sdk_python_pip(
|
||||
result
|
||||
}
|
||||
|
||||
/// The JDK whose home is `path`, as the SDK list shows it; `None` when it is no JDK home.
|
||||
#[command(trust = trusted)]
|
||||
/// The JDK whose home is `path`, as the SDK list shows it; `None` when it is no JDK home. SDKs
|
||||
/// are IDE-wide, so Add JDK from Disk works from the Welcome screen as well (#7361).
|
||||
#[command(trust = outside_restricted)]
|
||||
pub async fn sdk_jdk_at(path: String) -> IdeResult<Option<Sdk>> {
|
||||
// A macOS bundle too (Add JDK from Disk…).
|
||||
blocking_value(move || ide_sdk::java::jdk_at(std::path::Path::new(&path)).map(|j| ide_sdk::jdk_sdk(&j))).await
|
||||
}
|
||||
|
||||
/// `flutter --version --machine` of the Flutter SDK at `path`, or of the `flutter` on the
|
||||
/// search path when `path` is empty; `None` when there is no Flutter SDK.
|
||||
#[command(trust = trusted)]
|
||||
/// search path when `path` is empty; `None` when there is no Flutter SDK. Also from Settings on
|
||||
/// the Welcome screen, as the SDK list.
|
||||
#[command(trust = outside_restricted)]
|
||||
pub async fn sdk_flutter_at(
|
||||
host: &Host,
|
||||
window: &str,
|
||||
|
||||
@@ -720,13 +720,13 @@ scope_files always project_host bin
|
||||
sdk_container_python trusted project_host bindings async
|
||||
sdk_container_python_refresh trusted project_host bindings async
|
||||
sdk_detect outside_restricted project_host bindings async
|
||||
sdk_flutter_at trusted project_host bindings async
|
||||
sdk_jdk_at trusted project_host bindings async
|
||||
sdk_locate_tools trusted project_host bindings async
|
||||
sdk_flutter_at outside_restricted project_host bindings async
|
||||
sdk_jdk_at outside_restricted project_host bindings async
|
||||
sdk_locate_tools outside_restricted project_host bindings async
|
||||
sdk_php_composer_install trusted project_host bindings async
|
||||
sdk_php_effective trusted project_host bindings sync
|
||||
sdk_php_language_level trusted project_host bindings async
|
||||
sdk_php_xdebug trusted project_host bindings async
|
||||
sdk_php_xdebug outside_restricted project_host bindings async
|
||||
sdk_project_libraries trusted project_host bindings async
|
||||
sdk_python_create_venv outside_restricted project_host bindings async
|
||||
sdk_python_effective trusted project_host bindings async
|
||||
|
||||
+11
-4
@@ -2087,7 +2087,8 @@ export const commands = {
|
||||
sdkDetect: (kind: SdkKind) => typedError<Sdk[], IdeError>(__TAURI_INVOKE("sdk_detect", { kind })),
|
||||
/**
|
||||
* `flutter --version --machine` of the Flutter SDK at `path`, or of the `flutter` on the
|
||||
* search path when `path` is empty; `None` when there is no Flutter SDK.
|
||||
* search path when `path` is empty; `None` when there is no Flutter SDK. Also from Settings on
|
||||
* the Welcome screen, as the SDK list.
|
||||
*/
|
||||
sdkFlutterAt: (path: string) => typedError<{
|
||||
/** SDK root (not part of Flutter's answer). */
|
||||
@@ -2096,7 +2097,10 @@ export const commands = {
|
||||
channel?: string | null,
|
||||
dartSdkVersion?: string | null,
|
||||
} | null, IdeError>(__TAURI_INVOKE("sdk_flutter_at", { path })),
|
||||
/** The JDK whose home is `path`, as the SDK list shows it; `None` when it is no JDK home. */
|
||||
/**
|
||||
* The JDK whose home is `path`, as the SDK list shows it; `None` when it is no JDK home. SDKs
|
||||
* are IDE-wide, so Add JDK from Disk works from the Welcome screen as well (#7361).
|
||||
*/
|
||||
sdkJdkAt: (path: string) => typedError<{
|
||||
/**
|
||||
* Executable (`python`, `node`, `pnpm`) or directory (Rust toolchain bin
|
||||
@@ -2116,7 +2120,10 @@ export const commands = {
|
||||
/** Rust standard library sources, Go default GOPATH. */
|
||||
extra: IpcPath | null,
|
||||
} | null, IdeError>(__TAURI_INVOKE("sdk_jdk_at", { path })),
|
||||
/** Looks up `names` (bare command names): `node_modules/.bin` above `near`, then the search path. */
|
||||
/**
|
||||
* Looks up `names` (bare command names): `node_modules/.bin` above `near`, then the search path.
|
||||
* Also from Settings on the Welcome screen (the PHP interpreter).
|
||||
*/
|
||||
sdkLocateTools: (names: string[], near: string | null) => typedError<LocatedTools, IdeError>(__TAURI_INVOKE("sdk_locate_tools", { names, near })),
|
||||
/** The Composer project `path` belongs to, when its dependencies need `composer install`. */
|
||||
sdkPhpComposerInstall: (path: string) => typedError<{
|
||||
@@ -2129,7 +2136,7 @@ export const commands = {
|
||||
sdkPhpLanguageLevel: (path: string) => typedError<PhpLanguageLevels, IdeError>(__TAURI_INVOKE("sdk_php_language_level", { path })),
|
||||
/**
|
||||
* The version of the PHP interpreter `php` and of the Xdebug it loads, run in `cwd` (default: the
|
||||
* project root).
|
||||
* project root). Also from Settings on the Welcome screen.
|
||||
*/
|
||||
sdkPhpXdebug: (php: string, cwd: string | null) => typedError<PhpXdebug, IdeError>(__TAURI_INVOKE("sdk_php_xdebug", { php, cwd })),
|
||||
/**
|
||||
|
||||
@@ -86,6 +86,19 @@ describe("SDKs › Add JDK from Disk…", () => {
|
||||
expect(added() ?? []).toEqual([]);
|
||||
});
|
||||
|
||||
it("shows why the check failed instead of calling the folder invalid (#7361)", async () => {
|
||||
const { commands } = await import("@/platform/ipc");
|
||||
vi.mocked(commands.sdkJdkAt).mockResolvedValueOnce({
|
||||
status: "error",
|
||||
error: { kind: "untrusted", message: "This project is not trusted" },
|
||||
} as never);
|
||||
open.mockResolvedValue("/opt/jdks/acme-17");
|
||||
await act(async () => addMenuItem("Add JDK from Disk…"));
|
||||
expect(screen.getByRole("alert")).toHaveTextContent("This project is not trusted");
|
||||
expect(screen.getByRole("alert")).not.toHaveTextContent("not a valid home");
|
||||
expect(added() ?? []).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps detected SDKs from being removed", async () => {
|
||||
await act(async () => useSdks.setState({ byKind: { jdk: [JDK] } }));
|
||||
fireEvent.click(screen.getByRole("option", { name: /Acme 17\.0\.9/ }));
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
T,
|
||||
} from "@/ui";
|
||||
import { SettingsFormContext } from "@/workbench/contributions";
|
||||
import { call, commands, isTauri, nextRequestId, type FileEntry } from "@/platform/ipc";
|
||||
import { call, commands, isTauri, nextRequestId, type FileEntry, type Sdk } from "@/platform/ipc";
|
||||
import { mergeLibraryGroups } from "@/platform/libraries";
|
||||
import type { BuildModel, LibraryGroup, WebArtifact } from "@/bindings";
|
||||
import { relativePath, useProject } from "@/platform/project";
|
||||
@@ -1926,7 +1926,14 @@ function SdksSection() {
|
||||
setAddError(null);
|
||||
const picked = await choosePath({ directory: true, title: tx("Select Home Directory for JDK") });
|
||||
if (!picked) return;
|
||||
const sdk = await call(commands.sdkJdkAt(picked)).catch(() => null);
|
||||
let sdk: Sdk | null;
|
||||
try {
|
||||
sdk = await call(commands.sdkJdkAt(picked));
|
||||
} catch (e) {
|
||||
// Not a verdict on the directory: say what failed instead of calling it invalid.
|
||||
setAddError(e instanceof Error ? e.message : String(e));
|
||||
return;
|
||||
}
|
||||
if (!sdk) {
|
||||
setAddError(tx`The selected directory is not a valid home for JDK: ${tildify(picked)}`);
|
||||
return;
|
||||
|
||||
Reference in new issue
Заблокувати користувача