diff --git a/crates/ide-core/src/tool_path.rs b/crates/ide-core/src/tool_path.rs index 44f327884a..45e800e353 100644 --- a/crates/ide-core/src/tool_path.rs +++ b/crates/ide-core/src/tool_path.rs @@ -8,6 +8,21 @@ use std::collections::HashSet; use std::ffi::{OsStr, OsString}; use std::path::{Path, PathBuf}; +/// Why netcoredbg can't be installed here, for the two platforms Samsung publishes no build +/// for; the tool installer and the debugger's "not found" error both say it. +pub fn netcoredbg_no_prebuilt(intel_mac: bool, windows_arm64: bool) -> Option { + let platform = match (intel_mac, windows_arm64) { + (true, _) => "Intel Macs", + (_, true) => "Windows on ARM64", + _ => return None, + }; + Some(format!( + "Samsung publishes no prebuilt netcoredbg for {platform}. Build it from source \ + (https://github.com/Samsung/netcoredbg#building-from-source-code), then put `netcoredbg` on PATH \ + or set its executable path in Settings › Languages & Frameworks › Language Servers" + )) +} + /// Where executables are looked up: this process's `PATH` (the login shell's in the /// app), the login shell's `PATH` as last read, then per-user directories and mise's, /// asdf's and pyenv's shims, for when the shell's setup didn't reach the app. Language server diff --git a/crates/ide-dap/src/adapter.rs b/crates/ide-dap/src/adapter.rs index 4d6b90638a..4ba7e381e7 100644 --- a/crates/ide-dap/src/adapter.rs +++ b/crates/ide-dap/src/adapter.rs @@ -613,11 +613,20 @@ pub fn not_standalone(spec: &AdapterSpec) -> IdeError { } pub fn missing(spec: &AdapterSpec) -> IdeError { + let no_prebuilt = ide_core::tool_path::netcoredbg_no_prebuilt( + cfg!(all(target_os = "macos", target_arch = "x86_64")), + cfg!(all(windows, target_arch = "aarch64")), + ) + .filter(|_| spec.adapter == "netcoredbg"); + missing_with(spec, no_prebuilt.as_deref().or(spec.install_hint.as_deref())) +} + +fn missing_with(spec: &AdapterSpec, hint: Option<&str>) -> IdeError { let mut msg = format!( "debug adapter `{}` not found (`{}` is neither installed by OpenIDEA nor on PATH)", spec.adapter, spec.command ); - if let Some(hint) = &spec.install_hint { + if let Some(hint) = hint { msg.push_str(". "); msg.push_str(hint); } @@ -1205,6 +1214,17 @@ mod tests { assert!(err.message.contains("Settings › Languages & Frameworks › Language Servers")); } + #[test] + fn missing_netcoredbg_without_a_build_says_how_to_get_one() { + let spec = resolve(&builtin("netcoredbg").unwrap(), std::env::temp_dir()); + let hint = ide_core::tool_path::netcoredbg_no_prebuilt(true, false).unwrap(); + let message = missing_with(&spec, Some(&hint)).message; + assert!(message.starts_with("debug adapter `netcoredbg` not found"), "{message}"); + assert!(message.contains("no prebuilt netcoredbg for Intel Macs"), "{message}"); + assert!(message.contains("on PATH"), "{message}"); + assert_eq!(ide_core::tool_path::netcoredbg_no_prebuilt(false, false), None); + } + #[tokio::test] async fn process_launcher_reports_missing_binary() { let mut spec = resolve(&builtin("netcoredbg").unwrap(), std::env::temp_dir()); diff --git a/crates/ide-tools/src/lib.rs b/crates/ide-tools/src/lib.rs index fd359cb7ca..b2d310cfcb 100644 --- a/crates/ide-tools/src/lib.rs +++ b/crates/ide-tools/src/lib.rs @@ -36,7 +36,7 @@ use ide_core::settings::ToolDownloadSettings; use ide_core::{CancellationToken, IdeError, IdeResult}; use ide_language::LanguageConfig; use parking_lot::Mutex; -use platform::{Os, Platform}; +use platform::{Arch, Os, Platform}; pub use process::progress_event; pub use process::{ Emit, Http, PUBLIC_NPM_REGISTRY, is_npm_registry_miss, npm_public_registry_args, run_npm_with_public_fallback, @@ -740,6 +740,16 @@ impl Tools { /// Requirement check for installing `spec` right now. fn unavailable_reason(&self, spec: &ToolSpec) -> Option { + // Where netcoredbg has no prebuilt download, say how to get it instead of "no release asset". + let (os, arch) = (self.platform.os, self.platform.arch); + if spec.name == "netcoredbg" + && let Some(why) = ide_core::tool_path::netcoredbg_no_prebuilt( + os == Os::Mac && arch == Arch::X64, + os == Os::Windows && arch == Arch::Arm64, + ) + { + return Some(why); + } self.method_missing(self.install_method(spec)) .or_else(|| spec.needs.iter().find(|(cmd, _)| self.which(cmd).is_none()).map(|(_, why)| why.to_string())) } @@ -770,9 +780,9 @@ impl Tools { } Method::Release { assets, .. } => { let p = self.platform; - let has_rule = assets.iter().any(|r| { - r.os == p.os && (r.arch.is_none_or(|a| a == p.arch) || (p.os == Os::Mac && r.arch.is_some())) - }); + // Apple silicon also runs x64 builds (Rosetta); an Intel Mac runs no arm64 one. + let rosetta = p.os == Os::Mac && p.arch == Arch::Arm64; + let has_rule = assets.iter().any(|r| r.os == p.os && (r.arch.is_none_or(|a| a == p.arch) || rosetta)); if !has_rule { return Some(format!("No prebuilt release for {:?} {:?}", p.os, p.arch)); } diff --git a/crates/ide-tools/src/tests.rs b/crates/ide-tools/src/tests.rs index 973d373b2c..5282a31bc1 100644 --- a/crates/ide-tools/src/tests.rs +++ b/crates/ide-tools/src/tests.rs @@ -1575,3 +1575,68 @@ fn an_npm_tsserver_plugin_is_installed_at_its_pinned_version_only() { assert_eq!(status().status, ToolStatus::Missing); assert_eq!(managed_npm_plugin(app_data, "css-modules-kit"), None); } + +#[test] +fn netcoredbg_is_installable_only_where_samsung_publishes_a_build() { + for (os, arch, no_build) in [ + (Os::Mac, platform::Arch::Arm64, None), + (Os::Mac, platform::Arch::X64, Some("for Intel Macs")), + (Os::Linux, platform::Arch::X64, None), + (Os::Linux, platform::Arch::Arm64, None), + (Os::Windows, platform::Arch::X64, None), + (Os::Windows, platform::Arch::Arm64, Some("for Windows on ARM64")), + ] { + let env = Env::new(); + // curl exists, so a platform with a build is installable. + let curl = env.sys.join(if os == Os::Windows { "curl.exe" } else { "curl" }); + fs::write(&curl, "").unwrap(); + #[cfg(unix)] + archive::make_executable(&curl).unwrap(); + let path = std::env::join_paths([&env.sys]).unwrap(); + let tools = Tools::with_paths(env.root.clone(), path, Platform { os, arch }); + let info = tools.info("netcoredbg", &langs()).unwrap(); + let reason = info.unavailable_reason.unwrap_or_default(); + match no_build { + Some(platform) => { + assert!(!info.can_install, "{os:?} {arch:?}"); + assert!(reason.contains(platform) && reason.contains("Build it from source"), "{reason}"); + // Refused before anything is downloaded, so offline says the same. + let error = tools.install("netcoredbg", &langs(), &CancellationToken::new(), &|_| {}).unwrap_err(); + assert_eq!(error.message, reason); + } + None => assert!(!reason.contains("netcoredbg"), "{os:?} {arch:?}: {reason}"), + } + } +} + +#[test] +fn an_intel_mac_cannot_install_an_arm64_only_release() { + let method = registry::find("netcoredbg").unwrap().method; + for (arch, buildable) in [(platform::Arch::X64, false), (platform::Arch::Arm64, true)] { + let env = Env::new(); + // No curl on the fake PATH: a platform with a build asks for it, one without says so. + let tools = Tools::with_paths(env.root.clone(), OsString::new(), Platform { os: Os::Mac, arch }); + let reason = tools.method_missing(method).unwrap(); + assert_eq!(reason.contains("curl"), buildable, "{reason}"); + } +} + +#[cfg(unix)] +#[test] +fn netcoredbg_on_path_or_in_settings_is_used_without_a_prebuilt_release() { + let env = Env::new(); + env.script(&env.sys, "netcoredbg", "echo"); + let chosen = env.sys.join("netcoredbg"); + let intel = Platform { os: Os::Mac, arch: platform::Arch::X64 }; + let path = std::env::join_paths([&env.sys]).unwrap(); + let info = Tools::with_paths(env.root.clone(), path, intel).info("netcoredbg", &langs()).unwrap(); + assert_eq!(info.status, ToolStatus::OnPath); + assert_eq!(info.path, Some(chosen.clone().into())); + + let info = Tools::with_paths(env.root.clone(), OsString::new(), intel) + .with_custom_paths([("netcoredbg".to_owned(), chosen.clone())].into()) + .info("netcoredbg", &langs()) + .unwrap(); + assert_eq!(info.status, ToolStatus::Custom); + assert_eq!(info.path, Some(chosen.into())); +} diff --git a/docs/en/languages/csharp.mdx b/docs/en/languages/csharp.mdx index a93ce0e0fd..bdaf56a07b 100644 --- a/docs/en/languages/csharp.mdx +++ b/docs/en/languages/csharp.mdx @@ -111,7 +111,7 @@ See [Debugging](/en/guide/debugging). - Builds always use the `Debug` configuration; there is no setting to build `Release` from the Project view. - Test configurations run without a debugger; there is no Debug action for .NET tests. - There is no Visual Basic language server. -- netcoredbg has no prebuilt download for Windows on Arm. +- netcoredbg has no prebuilt download for Intel Macs or Windows on ARM64, so **Install** isn't offered there. [Build it from source](https://github.com/Samsung/netcoredbg#building-from-source-code), then put `netcoredbg` on `PATH` or set its executable path in **Settings › Languages & Frameworks › Language Servers**. - There is no designer for WinForms, WPF or XAML. - Razor needs roslyn-language-server (and so the .NET 10 SDK); with csharp-ls, `.cshtml` and `.razor` files have highlighting and the IDE's own features only. - Razor views of .NET Framework (ASP.NET MVC 5) projects get highlighting only: Roslyn's Razor support is for ASP.NET Core. diff --git a/docs/zh/languages/csharp.mdx b/docs/zh/languages/csharp.mdx index fb5115d880..0cbc0ac668 100644 --- a/docs/zh/languages/csharp.mdx +++ b/docs/zh/languages/csharp.mdx @@ -90,5 +90,5 @@ C# 在装了 Roslyn 语言服务器时用它,否则用 csharp-ls。Roslyn 是 - 构建始终使用 `Debug` 配置,项目视图中无法选择构建 `Release`。 - 测试配置不带调试器运行,.NET 测试没有调试入口。 - 没有 Visual Basic 语言服务器。 -- netcoredbg 没有 Windows on Arm 的预编译包。 +- netcoredbg 没有 Intel Mac 和 Windows ARM64 的预编译包,这两个平台不提供**安装**。请[从源码编译](https://github.com/Samsung/netcoredbg#building-from-source-code),然后把 `netcoredbg` 放到 `PATH` 上,或在 **Settings › Languages & Frameworks › Language Servers** 里设置它的可执行文件路径。 - 没有 WinForms、WPF 或 XAML 设计器。 diff --git a/e2e/netcoredbgPlatform.spec.ts b/e2e/netcoredbgPlatform.spec.ts new file mode 100644 index 0000000000..5ba91793ac --- /dev/null +++ b/e2e/netcoredbgPlatform.spec.ts @@ -0,0 +1,78 @@ +/** + * netcoredbg on a platform Samsung publishes no build for (Intel Macs, Windows on ARM64): a failed + * debug start says how to get one and opens the settings instead of offering an install. The host is + * stubbed at the IPC layer with the backend's messages; `ide-tools` and `ide-dap` tests cover them. + */ +import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures"; + +const SHOTS = process.env.E2E_SHOTS; +const WHY = + "Samsung publishes no prebuilt netcoredbg for Intel Macs. Build it from source (https://github.com/Samsung/netcoredbg#building-from-source-code), then put `netcoredbg` on PATH or set its executable path in Settings › Languages & Frameworks › Language Servers"; + +test("a missing netcoredbg with no build opens the settings and does not retry", async ({ workbench: page }) => { + await openFromTree(page, "build.gradle.kts"); + await stubDesktop(page); + await page.evaluate(async (why) => { + const config = { + id: "program:app", + name: "App", + kind: "program", + command: "App.dll", + args: [], + cwd: "/dev/acme-api", + env: {}, + detected: false, + isTest: false, + debugAdapter: "netcoredbg", + }; + const h = window.__ipc.handlers; + h.run_configs = () => [config]; + h.run_apply_settings = (args) => args.configs; + h.debug_set_breakpoints = () => []; + h.debug_start = () => { + const message = `debug adapter \`netcoredbg\` not found (\`netcoredbg\` is neither installed by OpenIDEA nor on PATH). ${why}`; + throw { kind: "unavailable", message, detail: null }; + }; + h.tools_list = () => [ + { + name: "netcoredbg", + displayName: "netcoredbg (.NET debugger)", + kind: "debugger", + command: "netcoredbg", + languages: ["C#", "F#"], + status: "missing", + path: null, + version: null, + installMethod: "GitHub release", + canInstall: false, + unavailableReason: why, + canUninstall: false, + installHint: null, + homepage: "https://github.com/Samsung/netcoredbg", + customError: null, + defaultArgs: [], + defaultInitializationOptions: null, + alternatives: [], + companion: false, + }, + ]; + const runModule = "/src/features/run/store.ts"; + const { loadConfigs, selectConfig } = await import(/* @vite-ignore */ runModule); + await loadConfigs(); + selectConfig(config.id); + }, WHY); + + await page.keyboard.press("Control+d"); + const toast = page.getByText("netcoredbg is not installed"); + await expect(toast).toBeVisible(); + await expect(page.getByText("Samsung publishes no prebuilt netcoredbg for Intel Macs.").first()).toBeVisible(); + await expect(page.getByRole("button", { name: "Install and Debug" })).toBeHidden(); + if (SHOTS) await page.screenshot({ path: `${SHOTS}/netcoredbg-notification.png`, animations: "disabled" }); + + await page.getByRole("button", { name: "Language Servers…" }).click(); + const details = page.getByLabel("netcoredbg (.NET debugger) details"); + await expect(details.getByRole("note")).toContainText("Build it from source"); + await expect(details.getByRole("button", { name: /Install/ })).toHaveCount(0); + if (SHOTS) await page.screenshot({ path: `${SHOTS}/netcoredbg-settings.png`, animations: "disabled" }); + expect(await ipcCalls(page, "debug_start")).toHaveLength(1); +}); diff --git a/src/features/debugger/__tests__/missingAdapter.test.ts b/src/features/debugger/__tests__/missingAdapter.test.ts index 67f3d5190d..8e60a51eff 100644 --- a/src/features/debugger/__tests__/missingAdapter.test.ts +++ b/src/features/debugger/__tests__/missingAdapter.test.ts @@ -32,6 +32,20 @@ describe("missing debug adapters", () => { ); }); + it("only opens the settings where netcoredbg has no build to install", () => { + const e = unavailable( + "debug adapter `netcoredbg` not found (x). Samsung publishes no prebuilt netcoredbg for Intel Macs.", + ); + expect(missingAdapter("netcoredbg", e)).toMatchObject({ + action: "Language Servers…", + manual: true, + body: e.message, + }); + expect( + missingAdapter("netcoredbg", unavailable("debug adapter `netcoredbg` not found (x)"))?.manual, + ).toBeUndefined(); + }); + it("offers CodeLLDB when a C/C++ launch finds no debugger on its host (#7001)", () => { const e = unavailable( "No C/C++ debugger found: lldb-dap and CodeLLDB are not installed, and GDB 12.1 cannot debug through DAP (it needs GDB 14 or newer). Install CodeLLDB, or install lldb-dap or GDB 14 or newer on this host", diff --git a/src/features/debugger/missingAdapter.ts b/src/features/debugger/missingAdapter.ts index 7c22272972..b03c6085a4 100644 --- a/src/features/debugger/missingAdapter.ts +++ b/src/features/debugger/missingAdapter.ts @@ -40,6 +40,8 @@ export interface MissingAdapter { body: string; /** The action's label when "Install and Debug" doesn't fit (a stale adapter's reinstall). */ action?: string; + /** Nothing to install: the action only opens the tool's settings, without launching again. */ + manual?: boolean; } /** The install offer for a failed start, or null when the failure is something else. */ @@ -68,6 +70,10 @@ export function missingAdapter(adapter: string, e: unknown): MissingAdapter | nu }; } if (!e.message.startsWith(`debug adapter \`${adapter}\` not found`)) return null; + // ide-core `netcoredbg_no_prebuilt`: this platform has no build to install. + if (adapter === "netcoredbg" && e.message.includes("no prebuilt netcoredbg")) { + return { tool: entry.tool, title: entry.title, body: e.message, action: "Language Servers…", manual: true }; + } return { tool: entry.tool, title: entry.title, diff --git a/src/features/debugger/state.ts b/src/features/debugger/state.ts index 77c8ebddf3..c88ec1e702 100644 --- a/src/features/debugger/state.ts +++ b/src/features/debugger/state.ts @@ -1107,7 +1107,10 @@ export async function startSession( actions: [ { label: missing.action ?? "Install and Debug", - run: () => void executeAction("tools.install", missing.tool).then(() => startSession(launch, options)), + run: () => + void executeAction("tools.install", missing.tool).then(() => + missing.manual ? undefined : startSession(launch, options), + ), }, ], });