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.

Add a function to produce docs scoped to release channel (#56917)

Joseph T. Lyonsa6a49afc2883
diff --git a/crates/release_channel/src/lib.rs b/crates/release_channel/src/lib.rs
index 357369b2caa..ca3aff66e1c 100644
--- a/crates/release_channel/src/lib.rs
+++ b/crates/release_channel/src/lib.rs
@@ -7,6 +7,8 @@ use std::{env, str::FromStr, sync::LazyLock};
use gpui::{App, Global};
use semver::Version;
+const ZED_DOCS_URL: &str = "https://zed.dev/docs";
+
/// stable | dev | nightly | preview
pub static RELEASE_CHANNEL_NAME: LazyLock<String> = LazyLock::new(|| {
if cfg!(debug_assertions) {
@@ -153,6 +155,14 @@ pub fn init_test(app_version: Version, release_channel: ReleaseChannel, cx: &mut
cx.set_global(GlobalReleaseChannel(release_channel))
}
+/// Returns the Zed docs URL for the current release channel for the given
+/// `slug`.
+pub fn docs_url(slug: &str, cx: &App) -> String {
+ ReleaseChannel::try_global(cx)
+ .unwrap_or(*RELEASE_CHANNEL)
+ .docs_url(slug)
+}
+
impl ReleaseChannel {
/// All release channels.
pub const ALL: [ReleaseChannel; 4] = [
@@ -219,6 +229,23 @@ impl ReleaseChannel {
Self::Stable => None,
}
}
+
+ /// Returns the Zed docs URL for this [`ReleaseChannel`] for the given
+ /// `slug`.
+ pub fn docs_url(&self, slug: &str) -> String {
+ let channel_path_segment = match self {
+ Self::Dev | Self::Nightly => Some("nightly"),
+ Self::Preview => Some("preview"),
+ Self::Stable => None,
+ };
+
+ match channel_path_segment {
+ Some(channel) if slug.is_empty() => format!("{ZED_DOCS_URL}/{channel}"),
+ Some(channel) => format!("{ZED_DOCS_URL}/{channel}/{slug}"),
+ None if slug.is_empty() => ZED_DOCS_URL.to_string(),
+ None => format!("{ZED_DOCS_URL}/{slug}"),
+ }
+ }
}
/// Error indicating that release channel string does not match any known release channel names.
@@ -238,3 +265,28 @@ impl FromStr for ReleaseChannel {
})
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::ReleaseChannel;
+
+ #[test]
+ fn test_docs_url_for_release_channel() {
+ assert_eq!(
+ ReleaseChannel::Dev.docs_url("settings"),
+ "https://zed.dev/docs/nightly/settings"
+ );
+ assert_eq!(
+ ReleaseChannel::Nightly.docs_url("settings"),
+ "https://zed.dev/docs/nightly/settings"
+ );
+ assert_eq!(
+ ReleaseChannel::Preview.docs_url("settings"),
+ "https://zed.dev/docs/preview/settings"
+ );
+ assert_eq!(
+ ReleaseChannel::Stable.docs_url("settings"),
+ "https://zed.dev/docs/settings"
+ );
+ }
+}