@@ -1106,7 +1106,7 @@ fn cmd_version() -> Result<()> {
11061106}
11071107
11081108fn cmd_lsp ( cwd : & Path , editors : Vec < String > ) -> Result < ( ) > {
1109- let all_editors = [ "helix" , "zed" ] ;
1109+ let all_editors = [ "helix" , "vscode" , " zed"] ;
11101110
11111111 let selected: Vec < String > = if editors. is_empty ( ) {
11121112 // Interactive picker
@@ -1134,6 +1134,7 @@ fn cmd_lsp(cwd: &Path, editors: Vec<String>) -> Result<()> {
11341134 for editor in & selected {
11351135 match editor. as_str ( ) {
11361136 "helix" => write_helix_lsp_config ( cwd) ?,
1137+ "vscode" => write_vscode_lsp_config ( cwd) ?,
11371138 "zed" => write_zed_lsp_config ( cwd) ?,
11381139 _ => { }
11391140 }
@@ -1298,6 +1299,46 @@ args = [
12981299 Ok ( ( ) )
12991300}
13001301
1302+ fn write_vscode_lsp_config ( project_dir : & Path ) -> Result < ( ) > {
1303+ let vscode_dir = project_dir. join ( ".vscode" ) ;
1304+ std:: fs:: create_dir_all ( & vscode_dir) ?;
1305+
1306+ let config_path = vscode_dir. join ( "settings.json" ) ;
1307+ let nu_bin_path = project_dir
1308+ . join ( ".nu-env" )
1309+ . join ( "bin" )
1310+ . join ( installer:: nu_env_binary_name ( ) ) ;
1311+
1312+ let nu_bin_path_str = nu_bin_path. to_string_lossy ( ) . into_owned ( ) ;
1313+
1314+ let mut settings = serde_json:: json!( { } ) ;
1315+ if config_path. exists ( ) {
1316+ if let Ok ( content) = std:: fs:: read_to_string ( & config_path) {
1317+ if let Ok ( parsed) = serde_json:: from_str :: < serde_json:: Value > ( & content) {
1318+ if parsed. is_object ( ) {
1319+ settings = parsed;
1320+ }
1321+ }
1322+ }
1323+ }
1324+
1325+ if let Some ( obj) = settings. as_object_mut ( ) {
1326+ obj. insert (
1327+ "nushellLanguageServer.includeDirs" . to_string ( ) ,
1328+ serde_json:: json!( [ ".nu-env/modules/" ] ) ,
1329+ ) ;
1330+ obj. insert (
1331+ "nushellLanguageServer.nushellExecutablePath" . to_string ( ) ,
1332+ serde_json:: json!( nu_bin_path_str) ,
1333+ ) ;
1334+ }
1335+
1336+ let config = serde_json:: to_string_pretty ( & settings) . unwrap_or_default ( ) + "\n " ;
1337+ std:: fs:: write ( & config_path, config) ?;
1338+ eprintln ! ( "Generated .vscode/settings.json" ) ;
1339+ Ok ( ( ) )
1340+ }
1341+
13011342fn write_zed_lsp_config ( project_dir : & Path ) -> Result < ( ) > {
13021343 let zed_dir = project_dir. join ( ".zed" ) ;
13031344 std:: fs:: create_dir_all ( & zed_dir) ?;
@@ -2430,9 +2471,18 @@ sha256 = "bbb"
24302471 fn cmd_lsp_with_explicit_editors_generates_configs ( ) {
24312472 let project_dir = make_temp_dir ( "lsp_explicit" ) ;
24322473
2433- cmd_lsp ( & project_dir, vec ! [ "helix" . to_string( ) , "zed" . to_string( ) ] ) . unwrap ( ) ;
2474+ cmd_lsp (
2475+ & project_dir,
2476+ vec ! [
2477+ "helix" . to_string( ) ,
2478+ "vscode" . to_string( ) ,
2479+ "zed" . to_string( ) ,
2480+ ] ,
2481+ )
2482+ . unwrap ( ) ;
24342483
24352484 assert ! ( project_dir. join( ".helix" ) . join( "languages.toml" ) . exists( ) ) ;
2485+ assert ! ( project_dir. join( ".vscode" ) . join( "settings.json" ) . exists( ) ) ;
24362486 assert ! ( project_dir. join( ".zed" ) . join( "settings.json" ) . exists( ) ) ;
24372487
24382488 let _ = std:: fs:: remove_dir_all ( project_dir) ;
0 commit comments