Skip to content
Merged
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
61 changes: 57 additions & 4 deletions packages/nx/src/native/ide/detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::OnceLock;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SupportedEditor {
VSCode,
VSCodeInsiders,
Cursor,
Windsurf,
JetBrains,
Expand All @@ -19,7 +20,7 @@ pub fn get_current_editor() -> &'static SupportedEditor {
})
}

pub fn detect_editor(env_map: HashMap<String, String>) -> SupportedEditor {
fn detect_editor(env_map: HashMap<String, String>) -> SupportedEditor {
// Check for Cursor-specific environment variable first
if get_env_var("CURSOR_TRACE_ID", &env_map).is_some() {
return SupportedEditor::Cursor;
Expand All @@ -28,7 +29,18 @@ pub fn detect_editor(env_map: HashMap<String, String>) -> SupportedEditor {
let term_editor = if let Some(term) = get_env_var("TERM_PROGRAM", &env_map) {
let term_lower = term.to_lowercase();
match term_lower.as_str() {
"vscode" => SupportedEditor::VSCode,
"vscode" => {
// Check if it's VS Code Insiders by looking at TERM_PROGRAM_VERSION
if let Some(version) = get_env_var("TERM_PROGRAM_VERSION", &env_map) {
if version.contains("-insider") {
SupportedEditor::VSCodeInsiders
} else {
SupportedEditor::VSCode
}
} else {
SupportedEditor::VSCode
}
}
"cursor" => SupportedEditor::Cursor,
"windsurf" => SupportedEditor::Windsurf,
"jetbrains" => SupportedEditor::JetBrains,
Expand All @@ -43,15 +55,18 @@ pub fn detect_editor(env_map: HashMap<String, String>) -> SupportedEditor {
return term_editor;
}

if matches!(term_editor, SupportedEditor::VSCode) {
if matches!(
term_editor,
SupportedEditor::VSCode | SupportedEditor::VSCodeInsiders
) {
if let Some(vscode_git_var) = get_env_var("VSCODE_GIT_ASKPASS_NODE", &env_map) {
let vscode_git_var_lowercase = vscode_git_var.to_lowercase();
if vscode_git_var_lowercase.contains("cursor") {
return SupportedEditor::Cursor;
} else if vscode_git_var_lowercase.contains("windsurf") {
return SupportedEditor::Windsurf;
} else {
return SupportedEditor::VSCode;
return term_editor;
}
} else {
return term_editor;
Expand Down Expand Up @@ -81,6 +96,33 @@ mod tests {
assert_eq!(detect_editor(test_env), SupportedEditor::VSCode);
}

#[test]
fn test_detect_vscode_with_regular_version() {
let mut test_env = HashMap::new();
test_env.insert("TERM_PROGRAM".to_string(), "vscode".to_string());
test_env.insert("TERM_PROGRAM_VERSION".to_string(), "1.104.0".to_string());
test_env.insert(
"VSCODE_GIT_ASKPASS_NODE".to_string(),
"some/path/with/vscode-insiders/in/it".to_string(),
);
assert_eq!(detect_editor(test_env), SupportedEditor::VSCode);
}

#[test]
fn test_detect_vscode_insiders() {
let mut test_env = HashMap::new();
test_env.insert("TERM_PROGRAM".to_string(), "vscode".to_string());
test_env.insert(
"TERM_PROGRAM_VERSION".to_string(),
"1.104.0-insider".to_string(),
);
test_env.insert(
"VSCODE_GIT_ASKPASS_NODE".to_string(),
"some/path/with/vscode/in/it".to_string(),
);
assert_eq!(detect_editor(test_env), SupportedEditor::VSCodeInsiders);
}

#[test]
fn test_detect_cursor() {
let mut test_env = HashMap::new();
Expand Down Expand Up @@ -154,6 +196,17 @@ mod tests {
assert_eq!(detect_editor(test_env), SupportedEditor::VSCode);
}

#[test]
fn test_vscode_insiders_without_askpass() {
let mut test_env = HashMap::new();
test_env.insert("TERM_PROGRAM".to_string(), "vscode".to_string());
test_env.insert(
"TERM_PROGRAM_VERSION".to_string(),
"1.104.0-insider".to_string(),
);
assert_eq!(detect_editor(test_env), SupportedEditor::VSCodeInsiders);
}

#[test]
fn test_cursor_without_askpass_confirmation() {
let mut test_env = HashMap::new();
Expand Down
11 changes: 11 additions & 0 deletions packages/nx/src/native/ide/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ pub fn get_install_command() -> Option<&'static str> {
Some("code")
}
}
SupportedEditor::VSCodeInsiders => {
debug!("Installing Nx Console extension for VS Code Insiders");
#[cfg(target_os = "windows")]
{
Some("code-insiders.cmd")
}
#[cfg(not(target_os = "windows"))]
{
Some("code-insiders")
}
}
SupportedEditor::Cursor => {
debug!("Installing Nx Console extension for Cursor");
if cfg!(target_os = "windows") {
Expand Down
Loading