Skip to content

Commit 875be9e

Browse files
MaxKlessFrozenPandaz
authored andcommitted
fix(core): detect vscode insiders as separate editor (#32679)
1 parent b8f8f2e commit 875be9e

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

packages/nx/src/native/ide/detection.rs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::sync::OnceLock;
44
#[derive(Debug, Clone, PartialEq, Eq)]
55
pub enum SupportedEditor {
66
VSCode,
7+
VSCodeInsiders,
78
Cursor,
89
Windsurf,
910
JetBrains,
@@ -19,7 +20,7 @@ pub fn get_current_editor() -> &'static SupportedEditor {
1920
})
2021
}
2122

22-
pub fn detect_editor(env_map: HashMap<String, String>) -> SupportedEditor {
23+
fn detect_editor(env_map: HashMap<String, String>) -> SupportedEditor {
2324
// Check for Cursor-specific environment variable first
2425
if get_env_var("CURSOR_TRACE_ID", &env_map).is_some() {
2526
return SupportedEditor::Cursor;
@@ -28,7 +29,18 @@ pub fn detect_editor(env_map: HashMap<String, String>) -> SupportedEditor {
2829
let term_editor = if let Some(term) = get_env_var("TERM_PROGRAM", &env_map) {
2930
let term_lower = term.to_lowercase();
3031
match term_lower.as_str() {
31-
"vscode" => SupportedEditor::VSCode,
32+
"vscode" => {
33+
// Check if it's VS Code Insiders by looking at TERM_PROGRAM_VERSION
34+
if let Some(version) = get_env_var("TERM_PROGRAM_VERSION", &env_map) {
35+
if version.contains("-insider") {
36+
SupportedEditor::VSCodeInsiders
37+
} else {
38+
SupportedEditor::VSCode
39+
}
40+
} else {
41+
SupportedEditor::VSCode
42+
}
43+
}
3244
"cursor" => SupportedEditor::Cursor,
3345
"windsurf" => SupportedEditor::Windsurf,
3446
"jetbrains" => SupportedEditor::JetBrains,
@@ -43,15 +55,18 @@ pub fn detect_editor(env_map: HashMap<String, String>) -> SupportedEditor {
4355
return term_editor;
4456
}
4557

46-
if matches!(term_editor, SupportedEditor::VSCode) {
58+
if matches!(
59+
term_editor,
60+
SupportedEditor::VSCode | SupportedEditor::VSCodeInsiders
61+
) {
4762
if let Some(vscode_git_var) = get_env_var("VSCODE_GIT_ASKPASS_NODE", &env_map) {
4863
let vscode_git_var_lowercase = vscode_git_var.to_lowercase();
4964
if vscode_git_var_lowercase.contains("cursor") {
5065
return SupportedEditor::Cursor;
5166
} else if vscode_git_var_lowercase.contains("windsurf") {
5267
return SupportedEditor::Windsurf;
5368
} else {
54-
return SupportedEditor::VSCode;
69+
return term_editor;
5570
}
5671
} else {
5772
return term_editor;
@@ -81,6 +96,33 @@ mod tests {
8196
assert_eq!(detect_editor(test_env), SupportedEditor::VSCode);
8297
}
8398

99+
#[test]
100+
fn test_detect_vscode_with_regular_version() {
101+
let mut test_env = HashMap::new();
102+
test_env.insert("TERM_PROGRAM".to_string(), "vscode".to_string());
103+
test_env.insert("TERM_PROGRAM_VERSION".to_string(), "1.104.0".to_string());
104+
test_env.insert(
105+
"VSCODE_GIT_ASKPASS_NODE".to_string(),
106+
"some/path/with/vscode-insiders/in/it".to_string(),
107+
);
108+
assert_eq!(detect_editor(test_env), SupportedEditor::VSCode);
109+
}
110+
111+
#[test]
112+
fn test_detect_vscode_insiders() {
113+
let mut test_env = HashMap::new();
114+
test_env.insert("TERM_PROGRAM".to_string(), "vscode".to_string());
115+
test_env.insert(
116+
"TERM_PROGRAM_VERSION".to_string(),
117+
"1.104.0-insider".to_string(),
118+
);
119+
test_env.insert(
120+
"VSCODE_GIT_ASKPASS_NODE".to_string(),
121+
"some/path/with/vscode/in/it".to_string(),
122+
);
123+
assert_eq!(detect_editor(test_env), SupportedEditor::VSCodeInsiders);
124+
}
125+
84126
#[test]
85127
fn test_detect_cursor() {
86128
let mut test_env = HashMap::new();
@@ -154,6 +196,17 @@ mod tests {
154196
assert_eq!(detect_editor(test_env), SupportedEditor::VSCode);
155197
}
156198

199+
#[test]
200+
fn test_vscode_insiders_without_askpass() {
201+
let mut test_env = HashMap::new();
202+
test_env.insert("TERM_PROGRAM".to_string(), "vscode".to_string());
203+
test_env.insert(
204+
"TERM_PROGRAM_VERSION".to_string(),
205+
"1.104.0-insider".to_string(),
206+
);
207+
assert_eq!(detect_editor(test_env), SupportedEditor::VSCodeInsiders);
208+
}
209+
157210
#[test]
158211
fn test_cursor_without_askpass_confirmation() {
159212
let mut test_env = HashMap::new();

packages/nx/src/native/ide/install.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ pub fn get_install_command() -> Option<&'static str> {
177177
Some("code")
178178
}
179179
}
180+
SupportedEditor::VSCodeInsiders => {
181+
debug!("Installing Nx Console extension for VS Code Insiders");
182+
#[cfg(target_os = "windows")]
183+
{
184+
Some("code-insiders.cmd")
185+
}
186+
#[cfg(not(target_os = "windows"))]
187+
{
188+
Some("code-insiders")
189+
}
190+
}
180191
SupportedEditor::Cursor => {
181192
debug!("Installing Nx Console extension for Cursor");
182193
if cfg!(target_os = "windows") {

0 commit comments

Comments
 (0)