Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions packages/cli/src/build/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,21 @@ impl AppBuilder {
}

pub(crate) async fn open_debugger(&mut self, server: &WebServer) -> Result<()> {
// Get the preferred editor from workspace settings, defaulting to VS Code
use crate::settings::SupportedEditor;
let preferred_editor = self
.build
.workspace
.settings
.preferred_editor
.unwrap_or(SupportedEditor::Vscode);

// Map the editor to its binary and URL scheme
let (editor_binary, url_scheme) = match preferred_editor {
SupportedEditor::Vscode => ("code", "vscode"),
SupportedEditor::Cursor => ("cursor", "cursor"),
};

let url = match self.build.bundle {
BundleFormat::MacOS
| BundleFormat::Windows
Expand All @@ -1504,7 +1519,7 @@ impl AppBuilder {
};

format!(
"vscode://vadimcn.vscode-lldb/launch/config?{{'request':'attach','pid':{pid}}}"
"{url_scheme}://vadimcn.vscode-lldb/launch/config?{{'request':'attach','pid':{pid}}}"
)
}

Expand All @@ -1519,7 +1534,7 @@ impl AppBuilder {
Some(base_path) => format!("/{}", base_path.trim_matches('/')),
None => "".to_owned(),
};
format!("vscode://DioxusLabs.dioxus/debugger?uri={protocol}://{address}{base_path}")
format!("{url_scheme}://DioxusLabs.dioxus/debugger?uri={protocol}://{address}{base_path}")
}

BundleFormat::Ios => {
Expand All @@ -1529,7 +1544,7 @@ impl AppBuilder {
};

format!(
"vscode://vadimcn.vscode-lldb/launch/config?{{'request':'attach','pid':{pid}}}"
"{url_scheme}://vadimcn.vscode-lldb/launch/config?{{'request':'attach','pid':{pid}}}"
)
}

Expand Down Expand Up @@ -1624,7 +1639,7 @@ impl AppBuilder {

let program_path = self.build.main_exe();
format!(
r#"vscode://vadimcn.vscode-lldb/launch/config?{{
r#"{url_scheme}://vadimcn.vscode-lldb/launch/config?{{
'name':'Attach to Android',
'type':'lldb',
'request':'attach',
Expand All @@ -1651,7 +1666,7 @@ impl AppBuilder {

tracing::info!("Opening debugger for [{}]: {url}", self.build.bundle);

_ = tokio::process::Command::new("code")
_ = tokio::process::Command::new(editor_binary)
.arg("--open-url")
.arg(url)
.spawn();
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/cli/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::{CliSettings, TraceSrc, Workspace};
use crate::{settings::SupportedEditor, CliSettings, TraceSrc, Workspace};

/// Dioxus config file controls
#[derive(Clone, Debug, Deserialize, Subcommand)]
Expand Down Expand Up @@ -38,6 +38,8 @@ pub(crate) enum Setting {
WSLFilePollInterval { value: u16 },
/// Disable the built-in telemetry for the CLI
DisableTelemetry { value: BoolValue },
/// Set the preferred editor for debug sessions
PreferredEditor { value: SupportedEditor },
}

impl Display for Setting {
Expand All @@ -48,6 +50,7 @@ impl Display for Setting {
Self::AlwaysOnTop { value: _ } => write!(f, "always-on-top"),
Self::WSLFilePollInterval { value: _ } => write!(f, "wsl-file-poll-interval"),
Self::DisableTelemetry { value: _ } => write!(f, "disable-telemetry"),
Self::PreferredEditor { value: _ } => write!(f, "preferred-editor"),
}
}
}
Expand Down Expand Up @@ -114,6 +117,9 @@ impl Config {
Setting::DisableTelemetry { value } => {
settings.disable_telemetry = Some(value.into());
}
Setting::PreferredEditor { value } => {
settings.preferred_editor = Some(value);
}
})?;
tracing::info!(dx_src = ?TraceSrc::Dev, "🚩 CLI setting `{setting}` has been set.");
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ impl TraceController {
Setting::AlwaysOnTop { value } => json!({ "value": value }),
Setting::WSLFilePollInterval { value } => json!({ "value": value }),
Setting::DisableTelemetry { value } => json!({ "value": value }),
Setting::PreferredEditor { value } => json!({ "value": format!("{:?}", value) }),
},
),
},
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ use std::sync::LazyLock;
use std::{fs, path::PathBuf, sync::Arc};
use tracing::{error, trace, warn};

/// Supported editors for debug sessions
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, clap::ValueEnum)]
#[serde(rename_all = "kebab-case")]
pub(crate) enum SupportedEditor {
/// Visual Studio Code
Vscode,
/// Cursor editor
Cursor,
}

impl Default for SupportedEditor {
fn default() -> Self {
SupportedEditor::Vscode
}
}

/// Describes cli settings from project or global level.
/// The order of priority goes:
/// 1. CLI Flags/Arguments
Expand All @@ -29,6 +45,8 @@ pub(crate) struct CliSettings {
pub(crate) ignore_version_update: Option<String>,
/// Disable telemetry
pub(crate) disable_telemetry: Option<bool>,
/// Preferred editor for debug sessions
pub(crate) preferred_editor: Option<SupportedEditor>,
}

impl CliSettings {
Expand Down