Skip to content

Fix windows path issues #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/postgres_model_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ use zed_extension_api::{
const PACKAGE_NAME: &str = "@zeddotdev/postgres-context-server";
const SERVER_PATH: &str = "node_modules/@zeddotdev/postgres-context-server/index.mjs";

/// Extensions to the Zed extension API that have not yet stabilized.
mod zed_ext {
/// Sanitizes the given path to remove the leading `/` on Windows.
///
/// On macOS and Linux this is a no-op.
///
/// This is a workaround for https://github.com/bytecodealliance/wasmtime/issues/10415.
pub fn sanitize_windows_path(path: std::path::PathBuf) -> std::path::PathBuf {
use zed_extension_api::{current_platform, Os};

let (os, _arch) = current_platform();
match os {
Os::Mac | Os::Linux => path,
Os::Windows => path
.to_string_lossy()
.to_string()
.trim_start_matches('/')
.into(),
}
}
}

struct PostgresModelContextExtension;

#[derive(Debug, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -39,13 +61,16 @@ impl zed::Extension for PostgresModelContextExtension {
let settings: PostgresContextServerSettings =
serde_json::from_value(settings).map_err(|e| e.to_string())?;

// Sanitize paths for Windows compatibility
let node_path = zed_ext::sanitize_windows_path(zed::node_binary_path()?.into());
let server_path = zed_ext::sanitize_windows_path(env::current_dir().unwrap())
.join(SERVER_PATH)
.to_string_lossy()
.to_string();

Ok(Command {
command: zed::node_binary_path()?,
args: vec![env::current_dir()
.unwrap()
.join(SERVER_PATH)
.to_string_lossy()
.to_string()],
command: node_path.to_string_lossy().to_string(),
args: vec![server_path],
env: vec![("DATABASE_URL".into(), settings.database_url)],
})
}
Expand Down