@@ -242,6 +242,11 @@ fn quick_copy_dir<P: AsRef<Path>>(src: P, dest: P, files: Option<P>) -> io::Resu
242242 }
243243}
244244
245+ fn copy_file < P : AsRef < Path > + std:: fmt:: Debug > ( src : P , dest : P ) -> io:: Result < ( ) > {
246+ println ! ( "copy {src:?} -> {dest:?}" ) ;
247+ fs:: copy ( src, dest) . map ( |_| ( ) )
248+ }
249+
245250fn remove_dir_all_if_exists < P : AsRef < Path > + std:: fmt:: Display > ( path : P ) -> io:: Result < ( ) > {
246251 if Path :: new ( path. as_ref ( ) ) . try_exists ( ) . unwrap ( ) {
247252 fs:: remove_dir_all ( path. as_ref ( ) ) ?;
@@ -357,6 +362,8 @@ fn run_install(dev: bool) -> io::Result<()> {
357362 run_cmd ! (
358363 info "Builder: cargo fetch" ;
359364 cargo fetch --manifest-path=../builder/Cargo . toml;
365+ info "VSCode extension: cargo fetch" ;
366+ cargo fetch --manifest-path=../extensions/VSCode /Cargo . toml;
360367 info "cargo fetch" ;
361368 cargo fetch;
362369 ) ?;
@@ -387,6 +394,8 @@ fn run_update() -> io::Result<()> {
387394 run_cmd ! (
388395 info "Builder: cargo update" ;
389396 cargo update --manifest-path=../builder/Cargo . toml;
397+ info "VSCoe extension: cargo update" ;
398+ cargo update --manifest-path=../extensions/VSCode /Cargo . toml;
390399 info "cargo update" ;
391400 cargo update;
392401 ) ?;
@@ -396,6 +405,8 @@ fn run_update() -> io::Result<()> {
396405 run_cmd ! (
397406 info "Builder: cargo outdated" ;
398407 cargo outdated --manifest-path=../builder/Cargo . toml;
408+ info "VSCode extension: cargo outdated" ;
409+ cargo outdated --manifest-path=../extensions/VSCode /Cargo . toml;
399410 info "cargo outdated" ;
400411 cargo outdated;
401412 ) ?;
@@ -412,11 +423,17 @@ fn run_test() -> io::Result<()> {
412423 info "Builder: cargo clippy and fmt" ;
413424 cargo clippy --all-targets --manifest-path=../builder/Cargo . toml -- -D warnings;
414425 cargo fmt --check --manifest-path=../builder/Cargo . toml;
426+ info "VSCode extension: cargo clippy and fmt" ;
427+ cargo clippy --all-targets --manifest-path=../extensions/VSCode /Cargo . toml -- -D warnings;
428+ cargo fmt --check --manifest-path=../extensions/VSCode /Cargo . toml;
415429 info "cargo sort" ;
416430 cargo sort --check;
417431 cd ../builder;
418432 info "Builder: cargo sort" ;
419433 cargo sort --check;
434+ cd ../extensions/VSCode ;
435+ info "VSCode extension: cargo sort" ;
436+ cargo sort --check;
420437 ) ?;
421438 run_build ( ) ?;
422439 // Verify that compiling for release produces no errors.
@@ -428,6 +445,8 @@ fn run_test() -> io::Result<()> {
428445 run_cmd ! (
429446 info "Builder: cargo test" ;
430447 cargo test --manifest-path=../builder/Cargo . toml;
448+ info "VSCode extension: cargo test" ;
449+ cargo test --manifest-path=../extensions/VSCode /Cargo . toml;
431450 info "cargo test" ;
432451 cargo test;
433452 ) ?;
@@ -458,6 +477,12 @@ fn run_client_build(
458477 // checks.
459478 skip_check_errors : bool ,
460479) -> io:: Result < ( ) > {
480+ // Ensure the JavaScript data structured generated from Rust are up to date.
481+ run_cmd ! (
482+ info "cargo test export_bindings" ;
483+ cargo test export_bindings;
484+ ) ?;
485+
461486 let esbuild = PathBuf :: from_slash ( "node_modules/.bin/esbuild" ) ;
462487 let distflag = if dist { "--minify" } else { "--sourcemap" } ;
463488 // This makes the program work from either the `server/` or `client/`
@@ -549,6 +574,13 @@ fn run_extensions_build(
549574 // directories.
550575 let rel_path = "../extensions/VSCode" ;
551576
577+ // The NAPI build.
578+ let mut napi_args = vec ! [ "napi" , "build" , "--platform" , "--output-dir" , "src" ] ;
579+ if dist {
580+ napi_args. push ( "--release" ) ;
581+ }
582+ run_script ( "npx" , & napi_args, rel_path, true ) ?;
583+
552584 // The main build for the Client.
553585 run_script (
554586 & esbuild,
@@ -561,6 +593,11 @@ fn run_extensions_build(
561593 "--external:vscode" ,
562594 "--outdir=./out" ,
563595 distflag,
596+ // The binaries produced by NAPI-RS should be copied over.
597+ "--loader:.node=copy" ,
598+ // Avoid the default of adding hash names to the `.node` file
599+ // generated.
600+ "--asset-names=[name]" ,
564601 ] ,
565602 rel_path,
566603 true ,
@@ -578,10 +615,12 @@ fn run_extensions_build(
578615}
579616
580617fn run_change_version ( new_version : & String ) -> io:: Result < ( ) > {
618+ let cargo_regex = r#"(\r?\nversion = ")[\d.]+("\r?\n)"# ;
581619 let replacement_string = format ! ( "${{1}}{new_version}${{2}}" ) ;
620+ search_and_replace_file ( "Cargo.toml" , cargo_regex, & replacement_string) ?;
582621 search_and_replace_file (
583- "Cargo.toml" ,
584- r#"(\r?\nversion = ")[\d.]+("\r?\n)"# ,
622+ "../extensions/VSCode/ Cargo.toml" ,
623+ cargo_regex ,
585624 & replacement_string,
586625 ) ?;
587626 search_and_replace_file (
@@ -601,18 +640,20 @@ fn run_prerelease() -> io::Result<()> {
601640 // Clean out all bundled files before the rebuild.
602641 remove_dir_all_if_exists ( "../client/static/bundled" ) ?;
603642 run_install ( true ) ?;
604- run_cmd ! (
605- info "cargo test export_bindings" ;
606- cargo test export_bindings;
607- ) ?;
608- run_script ( "pnpm" , & [ "run" , "dist" ] , "../client" , true ) ?;
609- Ok ( ( ) )
643+ run_client_build ( true , false )
610644}
611645
612646fn run_postrelease ( target : & str ) -> io:: Result < ( ) > {
613- let server_dir = "../extensions/VSCode/server" ;
614- // Only clean the `server/` directory if it exists.
615- remove_dir_all_if_exists ( server_dir) ?;
647+ // Copy all the Client static files needed by the embedded Server to the
648+ // VSCode extension.
649+ let client_static_dir = "../extensions/VSCode/static" ;
650+ remove_dir_all_if_exists ( client_static_dir) ?;
651+ quick_copy_dir ( "../client/static/" , client_static_dir, None ) ?;
652+ copy_file ( "log4rs.yml" , "../extensions/VSCode/log4rs.yml" ) ?;
653+ copy_file (
654+ "hashLocations.json" ,
655+ "../extensions/VSCode/hashLocations.json" ,
656+ ) ?;
616657
617658 // Translate from the target triple to VSCE's target parameter.
618659 let vsce_target = match target {
@@ -622,13 +663,6 @@ fn run_postrelease(target: &str) -> io::Result<()> {
622663 "aarch64-apple-darwin" => "darwin-arm64" ,
623664 _ => panic ! ( "Unsupported platform {target}." ) ,
624665 } ;
625-
626- let src_name = format ! ( "codechat-editor-server-{target}" ) ;
627- quick_copy_dir (
628- format ! ( "../target/distrib/{src_name}/" ) . as_str ( ) ,
629- "../extensions/VSCode/server" ,
630- None ,
631- ) ?;
632666 run_script (
633667 "npx" ,
634668 & [
0 commit comments