Skip to content

Commit e9d74c8

Browse files
committed
Fix proxy and task download
- Restore fallback if the version check or download fails, use the existing local installation - Include the underlying fetch/download error in the final "not found" message instead of swallowing it - Resolve the proxy and task helper release from the extension's own version (CARGO_PKG_VERSION) via github_release_by_tag_name instead of querying latest_github_release
1 parent 9148b89 commit e9d74c8

3 files changed

Lines changed: 67 additions & 52 deletions

File tree

src/downloadable.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,25 @@ pub trait Downloadable {
3535
return Ok(path);
3636
}
3737

38-
let version = self.fetch_latest_version()?;
39-
self.download(&version, language_server_id)
38+
let downloaded = self
39+
.fetch_latest_version()
40+
.and_then(|version| self.download(&version, language_server_id));
41+
42+
match downloaded {
43+
Ok(path) => Ok(path),
44+
// The version check or download failed (e.g. GitHub API rate
45+
// limiting) — an existing local installation is better than none.
46+
Err(err) => match self.find_local() {
47+
Some(path) => {
48+
println!(
49+
"Failed to update {}, falling back to local installation: {err}",
50+
Self::INSTALL_PATH
51+
);
52+
Ok(path)
53+
}
54+
None => Err(err),
55+
},
56+
}
4057
}
4158

4259
fn user_configured_path(

src/proxy.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::{fs::metadata, path::PathBuf};
22

33
use zed_extension_api::{
4-
self as zed, DownloadedFileType, GithubReleaseOptions, LanguageServerId,
5-
LanguageServerInstallationStatus, Worktree, serde_json::Value,
6-
set_language_server_installation_status,
4+
self as zed, DownloadedFileType, LanguageServerId, LanguageServerInstallationStatus, Worktree,
5+
serde_json::Value, set_language_server_installation_status,
76
};
87

98
use crate::{
@@ -58,15 +57,9 @@ impl Downloadable for Proxy {
5857
}
5958

6059
fn fetch_latest_version(&self) -> zed::Result<String> {
61-
Ok(zed::latest_github_release(
62-
GITHUB_REPO,
63-
GithubReleaseOptions {
64-
require_assets: true,
65-
pre_release: false,
66-
},
67-
)
68-
.map_err(|err| format!("Failed to fetch latest proxy release from {GITHUB_REPO}: {err}"))?
69-
.version)
60+
// The proxy is built and released together with the extension, so the
61+
// matching release is the one tagged with the extension's own version.
62+
Ok(format!("v{}", env!("CARGO_PKG_VERSION")))
7063
}
7164

7265
fn download(
@@ -82,14 +75,8 @@ impl Downloadable for Proxy {
8275
return Ok(PathBuf::from(bin_path));
8376
}
8477

85-
let release = zed::latest_github_release(
86-
GITHUB_REPO,
87-
GithubReleaseOptions {
88-
require_assets: true,
89-
pre_release: false,
90-
},
91-
)
92-
.map_err(|err| format!("Failed to fetch proxy release: {err}"))?;
78+
let release = zed::github_release_by_tag_name(GITHUB_REPO, version)
79+
.map_err(|err| format!("Failed to fetch proxy release {version}: {err}"))?;
9380

9481
let asset = release
9582
.assets
@@ -139,17 +126,29 @@ impl Downloadable for Proxy {
139126
return Ok(path);
140127
}
141128

142-
if let Ok(version) = self.fetch_latest_version()
143-
&& let Ok(path) = self.download(&version, language_server_id)
144-
{
129+
let downloaded = self
130+
.fetch_latest_version()
131+
.and_then(|version| self.download(&version, language_server_id));
132+
133+
let download_err = match downloaded {
134+
Ok(path) => return Ok(path),
135+
Err(err) => err,
136+
};
137+
138+
// The version check or download failed (e.g. GitHub API rate
139+
// limiting) — an existing local installation is better than none.
140+
if let Some(path) = self.find_local() {
141+
println!("Failed to update proxy, falling back to local installation: {download_err}");
142+
let s = path.to_string_lossy().to_string();
143+
self.cached_path = Some(s);
145144
return Ok(path);
146145
}
147146

148147
if let Some(path) = worktree.which(proxy_exec().as_str()) {
149148
return Ok(PathBuf::from(path));
150149
}
151150

152-
Err(format!("'{}' not found", proxy_exec()))
151+
Err(format!("'{}' not found: {download_err}", proxy_exec()))
153152
}
154153

155154
fn user_configured_path(

src/task.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::{fs::metadata, path::PathBuf};
22

33
use zed_extension_api::{
4-
self as zed, DownloadedFileType, GithubReleaseOptions, LanguageServerId,
5-
LanguageServerInstallationStatus, Worktree, serde_json::Value,
6-
set_language_server_installation_status,
4+
self as zed, DownloadedFileType, LanguageServerId, LanguageServerInstallationStatus, Worktree,
5+
serde_json::Value, set_language_server_installation_status,
76
};
87

98
use crate::{
@@ -47,17 +46,9 @@ impl Downloadable for TaskHelper {
4746
}
4847

4948
fn fetch_latest_version(&self) -> zed::Result<String> {
50-
Ok(zed::latest_github_release(
51-
GITHUB_REPO,
52-
GithubReleaseOptions {
53-
require_assets: true,
54-
pre_release: false,
55-
},
56-
)
57-
.map_err(|err| {
58-
format!("Failed to fetch latest task helper release from {GITHUB_REPO}: {err}")
59-
})?
60-
.version)
49+
// The task helper is built and released together with the extension, so
50+
// the matching release is the one tagged with the extension's own version.
51+
Ok(format!("v{}", env!("CARGO_PKG_VERSION")))
6152
}
6253

6354
fn download(
@@ -76,14 +67,8 @@ impl Downloadable for TaskHelper {
7667
return Ok(PathBuf::from(bin_path));
7768
}
7869

79-
let release = zed::latest_github_release(
80-
GITHUB_REPO,
81-
GithubReleaseOptions {
82-
require_assets: true,
83-
pre_release: false,
84-
},
85-
)
86-
.map_err(|err| format!("Failed to fetch task helper release: {err}"))?;
70+
let release = zed::github_release_by_tag_name(GITHUB_REPO, version)
71+
.map_err(|err| format!("Failed to fetch task helper release {version}: {err}"))?;
8772

8873
let asset = release
8974
.assets
@@ -133,17 +118,31 @@ impl Downloadable for TaskHelper {
133118
return Ok(path);
134119
}
135120

136-
if let Ok(version) = self.fetch_latest_version()
137-
&& let Ok(path) = self.download(&version, language_server_id)
138-
{
121+
let downloaded = self
122+
.fetch_latest_version()
123+
.and_then(|version| self.download(&version, language_server_id));
124+
125+
let download_err = match downloaded {
126+
Ok(path) => return Ok(path),
127+
Err(err) => err,
128+
};
129+
130+
// The version check or download failed (e.g. GitHub API rate
131+
// limiting) — an existing local installation is better than none.
132+
if let Some(path) = self.find_local() {
133+
println!(
134+
"Failed to update task helper, falling back to local installation: {download_err}"
135+
);
136+
let s = path.to_string_lossy().to_string();
137+
self.cached_path = Some(s);
139138
return Ok(path);
140139
}
141140

142141
if let Some(path) = worktree.which(task_helper_exec().as_str()) {
143142
return Ok(PathBuf::from(path));
144143
}
145144

146-
Err(format!("'{}' not found", task_helper_exec()))
145+
Err(format!("'{}' not found: {download_err}", task_helper_exec()))
147146
}
148147
}
149148

0 commit comments

Comments
 (0)