@@ -9,6 +9,28 @@ use zed_extension_api::{
99const PACKAGE_NAME : & str = "@zeddotdev/postgres-context-server" ;
1010const SERVER_PATH : & str = "node_modules/@zeddotdev/postgres-context-server/index.mjs" ;
1111
12+ /// Extensions to the Zed extension API that have not yet stabilized.
13+ mod zed_ext {
14+ /// Sanitizes the given path to remove the leading `/` on Windows.
15+ ///
16+ /// On macOS and Linux this is a no-op.
17+ ///
18+ /// This is a workaround for https://github.com/bytecodealliance/wasmtime/issues/10415.
19+ pub fn sanitize_windows_path ( path : std:: path:: PathBuf ) -> std:: path:: PathBuf {
20+ use zed_extension_api:: { current_platform, Os } ;
21+
22+ let ( os, _arch) = current_platform ( ) ;
23+ match os {
24+ Os :: Mac | Os :: Linux => path,
25+ Os :: Windows => path
26+ . to_string_lossy ( )
27+ . to_string ( )
28+ . trim_start_matches ( '/' )
29+ . into ( ) ,
30+ }
31+ }
32+ }
33+
1234struct PostgresModelContextExtension ;
1335
1436#[ derive( Debug , Deserialize , JsonSchema ) ]
@@ -39,13 +61,16 @@ impl zed::Extension for PostgresModelContextExtension {
3961 let settings: PostgresContextServerSettings =
4062 serde_json:: from_value ( settings) . map_err ( |e| e. to_string ( ) ) ?;
4163
64+ // Sanitize paths for Windows compatibility
65+ let node_path = zed_ext:: sanitize_windows_path ( zed:: node_binary_path ( ) ?. into ( ) ) ;
66+ let server_path = zed_ext:: sanitize_windows_path ( env:: current_dir ( ) . unwrap ( ) )
67+ . join ( SERVER_PATH )
68+ . to_string_lossy ( )
69+ . to_string ( ) ;
70+
4271 Ok ( Command {
43- command : zed:: node_binary_path ( ) ?,
44- args : vec ! [ env:: current_dir( )
45- . unwrap( )
46- . join( SERVER_PATH )
47- . to_string_lossy( )
48- . to_string( ) ] ,
72+ command : node_path. to_string_lossy ( ) . to_string ( ) ,
73+ args : vec ! [ server_path] ,
4974 env : vec ! [ ( "DATABASE_URL" . into( ) , settings. database_url) ] ,
5075 } )
5176 }
0 commit comments