@@ -9,6 +9,28 @@ use zed_extension_api::{
9
9
const PACKAGE_NAME : & str = "@zeddotdev/postgres-context-server" ;
10
10
const SERVER_PATH : & str = "node_modules/@zeddotdev/postgres-context-server/index.mjs" ;
11
11
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
+
12
34
struct PostgresModelContextExtension ;
13
35
14
36
#[ derive( Debug , Deserialize , JsonSchema ) ]
@@ -39,13 +61,16 @@ impl zed::Extension for PostgresModelContextExtension {
39
61
let settings: PostgresContextServerSettings =
40
62
serde_json:: from_value ( settings) . map_err ( |e| e. to_string ( ) ) ?;
41
63
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
+
42
71
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] ,
49
74
env : vec ! [ ( "DATABASE_URL" . into( ) , settings. database_url) ] ,
50
75
} )
51
76
}
0 commit comments