Add client::zed_urls module for constructing zed.dev URLs (#19391)

This PR adds a new `zed_urls` module to the `client` crate.

This module contains functions for constructing URLs to Zed properties,
such as zed.dev.

The URLs produced by this module will respect the server URL set via
settings or the `ZED_SERVER_URL` environment variable. This allows them
to correctly reflect the current environment (such as when testing Zed
against a local collab/zed.dev).

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-10-17 16:18:35 -04:00 committed by GitHub
parent 3c32f01a8f
commit 2bcf9fc490
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 30 additions and 12 deletions

View file

@ -21,7 +21,7 @@ use crate::{
use anyhow::Result; use anyhow::Result;
use assistant_slash_command::{SlashCommand, SlashCommandOutputSection}; use assistant_slash_command::{SlashCommand, SlashCommandOutputSection};
use assistant_tool::ToolRegistry; use assistant_tool::ToolRegistry;
use client::{proto, Client, Status}; use client::{proto, zed_urls, Client, Status};
use collections::{BTreeSet, HashMap, HashSet}; use collections::{BTreeSet, HashMap, HashSet};
use editor::{ use editor::{
actions::{FoldAt, MoveToEndOfLine, Newline, ShowCompletions, UnfoldAt}, actions::{FoldAt, MoveToEndOfLine, Newline, ShowCompletions, UnfoldAt},
@ -3675,7 +3675,6 @@ impl ContextEditor {
fn render_payment_required_error(&self, cx: &mut ViewContext<Self>) -> AnyElement { fn render_payment_required_error(&self, cx: &mut ViewContext<Self>) -> AnyElement {
const ERROR_MESSAGE: &str = "Free tier exceeded. Subscribe and add payment to continue using Zed LLMs. You'll be billed at cost for tokens used."; const ERROR_MESSAGE: &str = "Free tier exceeded. Subscribe and add payment to continue using Zed LLMs. You'll be billed at cost for tokens used.";
const ACCOUNT_URL: &str = "https://zed.dev/account";
v_flex() v_flex()
.gap_0p5() .gap_0p5()
@ -3700,7 +3699,7 @@ impl ContextEditor {
.child(Button::new("subscribe", "Subscribe").on_click(cx.listener( .child(Button::new("subscribe", "Subscribe").on_click(cx.listener(
|this, _, cx| { |this, _, cx| {
this.last_error = None; this.last_error = None;
cx.open_url(ACCOUNT_URL); cx.open_url(&zed_urls::account_url(cx));
cx.notify(); cx.notify();
}, },
))) )))
@ -3716,7 +3715,6 @@ impl ContextEditor {
fn render_max_monthly_spend_reached_error(&self, cx: &mut ViewContext<Self>) -> AnyElement { fn render_max_monthly_spend_reached_error(&self, cx: &mut ViewContext<Self>) -> AnyElement {
const ERROR_MESSAGE: &str = "You have reached your maximum monthly spend. Increase your spend limit to continue using Zed LLMs."; const ERROR_MESSAGE: &str = "You have reached your maximum monthly spend. Increase your spend limit to continue using Zed LLMs.";
const ACCOUNT_URL: &str = "https://zed.dev/account";
v_flex() v_flex()
.gap_0p5() .gap_0p5()
@ -3742,7 +3740,7 @@ impl ContextEditor {
Button::new("subscribe", "Update Monthly Spend Limit").on_click( Button::new("subscribe", "Update Monthly Spend Limit").on_click(
cx.listener(|this, _, cx| { cx.listener(|this, _, cx| {
this.last_error = None; this.last_error = None;
cx.open_url(ACCOUNT_URL); cx.open_url(&zed_urls::account_url(cx));
cx.notify(); cx.notify();
}), }),
), ),

View file

@ -4,6 +4,7 @@ pub mod test;
mod socks; mod socks;
pub mod telemetry; pub mod telemetry;
pub mod user; pub mod user;
pub mod zed_urls;
use anyhow::{anyhow, bail, Context as _, Result}; use anyhow::{anyhow, bail, Context as _, Result};
use async_recursion::async_recursion; use async_recursion::async_recursion;

View file

@ -0,0 +1,19 @@
//! Contains helper functions for constructing URLs to various Zed-related pages.
//!
//! These URLs will adapt to the configured server URL in order to construct
//! links appropriate for the environment (e.g., by linking to a local copy of
//! zed.dev in development).
use gpui::AppContext;
use settings::Settings;
use crate::ClientSettings;
fn server_url(cx: &AppContext) -> &str {
&ClientSettings::get_global(cx).server_url
}
/// Returns the URL to the account page on zed.dev.
pub fn account_url(cx: &AppContext) -> String {
format!("{server_url}/account", server_url = server_url(cx))
}

View file

@ -8,7 +8,7 @@ use crate::{
use anthropic::AnthropicError; use anthropic::AnthropicError;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use client::{ use client::{
Client, PerformCompletionParams, UserStore, EXPIRED_LLM_TOKEN_HEADER_NAME, zed_urls, Client, PerformCompletionParams, UserStore, EXPIRED_LLM_TOKEN_HEADER_NAME,
MAX_LLM_MONTHLY_SPEND_REACHED_HEADER_NAME, MAX_LLM_MONTHLY_SPEND_REACHED_HEADER_NAME,
}; };
use collections::BTreeMap; use collections::BTreeMap;
@ -905,7 +905,6 @@ impl ConfigurationView {
impl Render for ConfigurationView { impl Render for ConfigurationView {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
const ZED_AI_URL: &str = "https://zed.dev/ai"; const ZED_AI_URL: &str = "https://zed.dev/ai";
const ACCOUNT_SETTINGS_URL: &str = "https://zed.dev/account";
let is_connected = !self.state.read(cx).is_signed_out(); let is_connected = !self.state.read(cx).is_signed_out();
let plan = self.state.read(cx).user_store.read(cx).current_plan(); let plan = self.state.read(cx).user_store.read(cx).current_plan();
@ -922,7 +921,7 @@ impl Render for ConfigurationView {
h_flex().child( h_flex().child(
Button::new("manage_settings", "Manage Subscription") Button::new("manage_settings", "Manage Subscription")
.style(ButtonStyle::Tinted(TintColor::Accent)) .style(ButtonStyle::Tinted(TintColor::Accent))
.on_click(cx.listener(|_, _, cx| cx.open_url(ACCOUNT_SETTINGS_URL))), .on_click(cx.listener(|_, _, cx| cx.open_url(&zed_urls::account_url(cx)))),
), ),
) )
} else if cx.has_flag::<ZedPro>() { } else if cx.has_flag::<ZedPro>() {
@ -938,7 +937,9 @@ impl Render for ConfigurationView {
Button::new("upgrade", "Upgrade") Button::new("upgrade", "Upgrade")
.style(ButtonStyle::Subtle) .style(ButtonStyle::Subtle)
.color(Color::Accent) .color(Color::Accent)
.on_click(cx.listener(|_, _, cx| cx.open_url(ACCOUNT_SETTINGS_URL))), .on_click(
cx.listener(|_, _, cx| cx.open_url(&zed_urls::account_url(cx))),
),
), ),
) )
} else { } else {

View file

@ -11,7 +11,7 @@ pub(crate) mod windows_only_instance;
pub use app_menus::*; pub use app_menus::*;
use assistant::PromptBuilder; use assistant::PromptBuilder;
use breadcrumbs::Breadcrumbs; use breadcrumbs::Breadcrumbs;
use client::ZED_URL_SCHEME; use client::{zed_urls, ZED_URL_SCHEME};
use collections::VecDeque; use collections::VecDeque;
use command_palette_hooks::CommandPaletteFilter; use command_palette_hooks::CommandPaletteFilter;
use editor::ProposedChangesEditorToolbar; use editor::ProposedChangesEditorToolbar;
@ -419,8 +419,7 @@ pub fn initialize_workspace(
) )
.register_action( .register_action(
|_: &mut Workspace, _: &OpenAccountSettings, cx: &mut ViewContext<Workspace>| { |_: &mut Workspace, _: &OpenAccountSettings, cx: &mut ViewContext<Workspace>| {
let server_url = &client::ClientSettings::get_global(cx).server_url; cx.open_url(&zed_urls::account_url(cx));
cx.open_url(&format!("{server_url}/account"));
}, },
) )
.register_action( .register_action(