Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Respect proxy settings when fetching JSON schemas (#53954)

Hamza Parachaf722e2fb2f71
diff --git a/crates/languages/src/json.rs b/crates/languages/src/json.rs
index de30d958d00..b1bcd0043e5 100644
--- a/crates/languages/src/json.rs
+++ b/crates/languages/src/json.rs
@@ -296,6 +296,13 @@ impl LspAdapter for JsonLspAdapter {
}
})
});
+
+ if let Some(proxy_settings) = cx.update(|cx| {
+ json_schema_proxy_settings(cx.http_client().proxy().map(ToString::to_string))
+ }) {
+ merge_json_value_into(proxy_settings, &mut config);
+ }
+
let project_options = cx.update(|cx| {
language_server_settings(delegate.as_ref(), &self.name(), cx)
.and_then(|s| worktree_root(delegate, s.settings.clone()))
@@ -356,6 +363,16 @@ fn worktree_root(delegate: &Arc<dyn LspAdapterDelegate>, settings: Option<Value>
Some(Value::Object(settings_map))
}
+fn json_schema_proxy_settings(proxy: Option<String>) -> Option<Value> {
+ proxy.map(|proxy| {
+ json!({
+ "http": {
+ "proxy": proxy,
+ }
+ })
+ })
+}
+
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
@@ -376,6 +393,30 @@ async fn get_cached_server_binary(
.log_err()
}
+#[cfg(test)]
+mod tests {
+ use serde_json::json;
+
+ use super::json_schema_proxy_settings;
+
+ #[test]
+ fn test_json_schema_proxy_settings_includes_proxy() {
+ assert_eq!(
+ json_schema_proxy_settings(Some("http://proxy.example:8080".to_string())),
+ Some(json!({
+ "http": {
+ "proxy": "http://proxy.example:8080",
+ }
+ }))
+ );
+ }
+
+ #[test]
+ fn test_json_schema_proxy_settings_ignores_missing_proxy() {
+ assert_eq!(json_schema_proxy_settings(None), None);
+ }
+}
+
pub struct NodeVersionAdapter;
impl NodeVersionAdapter {