Rename `SharedUrl` to `SharedUri` (#7084)

Marshall Bowers created

This PR renames `SharedUrl` to `SharedUri` to better reflect its intent.

I'm still not entirely happy with this naming, as the file paths that we
can store in here are not _really_ URIs, as they are lacking a protocol.

I want to explore changing `SharedUri` / `SharedUrl` back to alway
storing a URL and treat local filepaths differently, as it seems we're
conflating two different concerns under the same umbrella, at the
moment.

Release Notes:

- N/A

Change summary

crates/client/src/user.rs                                         |  6 
crates/collab/src/tests/integration_tests.rs                      |  6 
crates/collab_ui/src/chat_panel.rs                                |  4 
crates/collab_ui/src/chat_panel/message_editor.rs                 |  6 
crates/collab_ui/src/notifications/collab_notification.rs         |  6 
crates/collab_ui/src/notifications/stories/collab_notification.rs |  6 
crates/gpui/examples/image.rs                                     | 10 
crates/gpui/src/elements/img.rs                                   |  8 
crates/gpui/src/gpui.rs                                           |  4 
crates/gpui/src/image_cache.rs                                    | 10 
crates/gpui/src/shared_uri.rs                                     | 20 
crates/theme/src/styles/stories/players.rs                        | 10 
crates/ui/src/components/stories/avatar.rs                        | 18 
crates/ui/src/components/stories/list_item.rs                     | 18 
14 files changed, 66 insertions(+), 66 deletions(-)

Detailed changes

crates/client/src/user.rs 🔗

@@ -4,7 +4,7 @@ use collections::{hash_map::Entry, HashMap, HashSet};
 use feature_flags::FeatureFlagAppExt;
 use futures::{channel::mpsc, Future, StreamExt};
 use gpui::{
-    AppContext, AsyncAppContext, EventEmitter, Model, ModelContext, SharedString, SharedUrl, Task,
+    AppContext, AsyncAppContext, EventEmitter, Model, ModelContext, SharedString, SharedUri, Task,
     WeakModel,
 };
 use postage::{sink::Sink, watch};
@@ -22,7 +22,7 @@ pub struct ParticipantIndex(pub u32);
 pub struct User {
     pub id: UserId,
     pub github_login: String,
-    pub avatar_uri: SharedUrl,
+    pub avatar_uri: SharedUri,
 }
 
 #[derive(Clone, Debug, PartialEq, Eq)]
@@ -707,7 +707,7 @@ impl User {
         Arc::new(User {
             id: message.id,
             github_login: message.github_login,
-            avatar_uri: SharedUrl::network(message.avatar_url),
+            avatar_uri: SharedUri::network(message.avatar_url),
         })
     }
 }

crates/collab/src/tests/integration_tests.rs 🔗

@@ -9,7 +9,7 @@ use fs::{repository::GitFileStatus, FakeFs, Fs as _, RemoveOptions};
 use futures::StreamExt as _;
 use gpui::{
     px, size, AppContext, BackgroundExecutor, Model, Modifiers, MouseButton, MouseDownEvent,
-    SharedUrl, TestAppContext,
+    SharedUri, TestAppContext,
 };
 use language::{
     language_settings::{AllLanguageSettings, Formatter},
@@ -1828,7 +1828,7 @@ async fn test_active_call_events(
             owner: Arc::new(User {
                 id: client_a.user_id().unwrap(),
                 github_login: "user_a".to_string(),
-                avatar_uri: SharedUrl::network("avatar_a"),
+                avatar_uri: SharedUri::network("avatar_a"),
             }),
             project_id: project_a_id,
             worktree_root_names: vec!["a".to_string()],
@@ -1846,7 +1846,7 @@ async fn test_active_call_events(
             owner: Arc::new(User {
                 id: client_b.user_id().unwrap(),
                 github_login: "user_b".to_string(),
-                avatar_uri: SharedUrl::network("avatar_b"),
+                avatar_uri: SharedUri::network("avatar_b"),
             }),
             project_id: project_b_id,
             worktree_root_names: vec!["b".to_string()]

crates/collab_ui/src/chat_panel.rs 🔗

@@ -714,7 +714,7 @@ fn format_timestamp(
 #[cfg(test)]
 mod tests {
     use super::*;
-    use gpui::{HighlightStyle, SharedUrl};
+    use gpui::{HighlightStyle, SharedUri};
     use pretty_assertions::assert_eq;
     use rich_text::Highlight;
     use time::{Date, OffsetDateTime, Time, UtcOffset};
@@ -730,7 +730,7 @@ mod tests {
             timestamp: OffsetDateTime::now_utc(),
             sender: Arc::new(client::User {
                 github_login: "fgh".into(),
-                avatar_uri: SharedUrl::network("avatar_fgh"),
+                avatar_uri: SharedUri::network("avatar_fgh"),
                 id: 103,
             }),
             nonce: 5,

crates/collab_ui/src/chat_panel/message_editor.rs 🔗

@@ -365,7 +365,7 @@ impl Render for MessageEditor {
 mod tests {
     use super::*;
     use client::{Client, User, UserStore};
-    use gpui::{SharedUrl, TestAppContext};
+    use gpui::{SharedUri, TestAppContext};
     use language::{Language, LanguageConfig};
     use rpc::proto;
     use settings::SettingsStore;
@@ -392,7 +392,7 @@ mod tests {
                         user: Arc::new(User {
                             github_login: "a-b".into(),
                             id: 101,
-                            avatar_uri: SharedUrl::network("avatar_a-b"),
+                            avatar_uri: SharedUri::network("avatar_a-b"),
                         }),
                         kind: proto::channel_member::Kind::Member,
                         role: proto::ChannelRole::Member,
@@ -401,7 +401,7 @@ mod tests {
                         user: Arc::new(User {
                             github_login: "C_D".into(),
                             id: 102,
-                            avatar_uri: SharedUrl::network("avatar_C_D"),
+                            avatar_uri: SharedUri::network("avatar_C_D"),
                         }),
                         kind: proto::channel_member::Kind::Member,
                         role: proto::ChannelRole::Member,

crates/collab_ui/src/notifications/collab_notification.rs 🔗

@@ -1,10 +1,10 @@
-use gpui::{img, prelude::*, AnyElement, SharedUrl};
+use gpui::{img, prelude::*, AnyElement, SharedUri};
 use smallvec::SmallVec;
 use ui::prelude::*;
 
 #[derive(IntoElement)]
 pub struct CollabNotification {
-    avatar_uri: SharedUrl,
+    avatar_uri: SharedUri,
     accept_button: Button,
     dismiss_button: Button,
     children: SmallVec<[AnyElement; 2]>,
@@ -12,7 +12,7 @@ pub struct CollabNotification {
 
 impl CollabNotification {
     pub fn new(
-        avatar_uri: impl Into<SharedUrl>,
+        avatar_uri: impl Into<SharedUri>,
         accept_button: Button,
         dismiss_button: Button,
     ) -> Self {

crates/collab_ui/src/notifications/stories/collab_notification.rs 🔗

@@ -1,4 +1,4 @@
-use gpui::{prelude::*, SharedUrl};
+use gpui::{prelude::*, SharedUri};
 use story::{StoryContainer, StoryItem, StorySection};
 use ui::prelude::*;
 
@@ -19,7 +19,7 @@ impl Render for CollabNotificationStory {
                 "Incoming Call Notification",
                 window_container(400., 72.).child(
                     CollabNotification::new(
-                        SharedUrl::network("https://avatars.githubusercontent.com/u/1486634?v=4"),
+                        SharedUri::network("https://avatars.githubusercontent.com/u/1486634?v=4"),
                         Button::new("accept", "Accept"),
                         Button::new("decline", "Decline"),
                     )
@@ -36,7 +36,7 @@ impl Render for CollabNotificationStory {
                 "Project Shared Notification",
                 window_container(400., 72.).child(
                     CollabNotification::new(
-                        SharedUrl::network("https://avatars.githubusercontent.com/u/1714999?v=4"),
+                        SharedUri::network("https://avatars.githubusercontent.com/u/1714999?v=4"),
                         Button::new("open", "Open"),
                         Button::new("dismiss", "Dismiss"),
                     )

crates/gpui/examples/image.rs 🔗

@@ -3,7 +3,7 @@ use gpui::*;
 #[derive(IntoElement)]
 struct ImageFromResource {
     text: SharedString,
-    resource: SharedUrl,
+    resource: SharedUri,
 }
 
 impl RenderOnce for ImageFromResource {
@@ -20,8 +20,8 @@ impl RenderOnce for ImageFromResource {
 }
 
 struct ImageShowcase {
-    local_resource: SharedUrl,
-    remote_resource: SharedUrl,
+    local_resource: SharedUri,
+    remote_resource: SharedUri,
 }
 
 impl Render for ImageShowcase {
@@ -51,8 +51,8 @@ fn main() {
     App::new().run(|cx: &mut AppContext| {
         cx.open_window(WindowOptions::default(), |cx| {
             cx.new_view(|_cx| ImageShowcase {
-                local_resource: SharedUrl::file("../zed/resources/app-icon.png"),
-                remote_resource: SharedUrl::network("https://picsum.photos/512/512"),
+                local_resource: SharedUri::file("../zed/resources/app-icon.png"),
+                remote_resource: SharedUri::network("https://picsum.photos/512/512"),
             })
         });
     });

crates/gpui/src/elements/img.rs 🔗

@@ -2,7 +2,7 @@ use std::sync::Arc;
 
 use crate::{
     point, size, Bounds, DevicePixels, Element, ElementContext, ImageData, InteractiveElement,
-    InteractiveElementState, Interactivity, IntoElement, LayoutId, Pixels, SharedUrl, Size,
+    InteractiveElementState, Interactivity, IntoElement, LayoutId, Pixels, SharedUri, Size,
     StyleRefinement, Styled,
 };
 use futures::FutureExt;
@@ -13,7 +13,7 @@ use util::ResultExt;
 #[derive(Clone, Debug)]
 pub enum ImageSource {
     /// Image content will be loaded from provided URI at render time.
-    Uri(SharedUrl),
+    Uri(SharedUri),
     /// Cached image data
     Data(Arc<ImageData>),
     // TODO: move surface definitions into mac platform module
@@ -21,8 +21,8 @@ pub enum ImageSource {
     Surface(CVImageBuffer),
 }
 
-impl From<SharedUrl> for ImageSource {
-    fn from(value: SharedUrl) -> Self {
+impl From<SharedUri> for ImageSource {
+    fn from(value: SharedUri) -> Self {
         Self::Uri(value)
     }
 }

crates/gpui/src/gpui.rs 🔗

@@ -83,7 +83,7 @@ mod platform;
 pub mod prelude;
 mod scene;
 mod shared_string;
-mod shared_url;
+mod shared_uri;
 mod style;
 mod styled;
 mod subscription;
@@ -133,7 +133,7 @@ pub use refineable::*;
 pub use scene::*;
 use seal::Sealed;
 pub use shared_string::*;
-pub use shared_url::*;
+pub use shared_uri::*;
 pub use smol::Timer;
 pub use style::*;
 pub use styled::*;

crates/gpui/src/image_cache.rs 🔗

@@ -1,4 +1,4 @@
-use crate::{AppContext, ImageData, ImageId, SharedUrl, Task};
+use crate::{AppContext, ImageData, ImageId, SharedUri, Task};
 use collections::HashMap;
 use futures::{future::Shared, AsyncReadExt, FutureExt, TryFutureExt};
 use image::ImageError;
@@ -41,7 +41,7 @@ impl From<ImageError> for Error {
 
 pub(crate) struct ImageCache {
     client: Arc<dyn HttpClient>,
-    images: Arc<Mutex<HashMap<SharedUrl, FetchImageTask>>>,
+    images: Arc<Mutex<HashMap<SharedUri, FetchImageTask>>>,
 }
 
 type FetchImageTask = Shared<Task<Result<Arc<ImageData>, Error>>>;
@@ -54,7 +54,7 @@ impl ImageCache {
         }
     }
 
-    pub fn get(&self, uri: impl Into<SharedUrl>, cx: &AppContext) -> FetchImageTask {
+    pub fn get(&self, uri: impl Into<SharedUri>, cx: &AppContext) -> FetchImageTask {
         let uri = uri.into();
         let mut images = self.images.lock();
 
@@ -69,11 +69,11 @@ impl ImageCache {
                             let uri = uri.clone();
                             async move {
                                 match uri {
-                                    SharedUrl::File(uri) => {
+                                    SharedUri::File(uri) => {
                                         let image = image::open(uri.as_ref())?.into_bgra8();
                                         Ok(Arc::new(ImageData::new(image)))
                                     }
-                                    SharedUrl::Network(uri) => {
+                                    SharedUri::Network(uri) => {
                                         let mut response =
                                             client.get(uri.as_ref(), ().into(), true).await?;
                                         let mut body = Vec::new();

crates/gpui/src/shared_url.rs → crates/gpui/src/shared_uri.rs 🔗

@@ -2,34 +2,34 @@ use std::ops::{Deref, DerefMut};
 
 use crate::SharedString;
 
-/// A URL stored in a `SharedString` pointing to a file or a remote resource.
+/// A URI stored in a [`SharedString`].
 #[derive(PartialEq, Eq, Hash, Clone)]
-pub enum SharedUrl {
+pub enum SharedUri {
     /// A path to a local file.
     File(SharedString),
     /// A URL to a remote resource.
     Network(SharedString),
 }
 
-impl SharedUrl {
-    /// Create a URL pointing to a local file.
+impl SharedUri {
+    /// Creates a [`SharedUri`] pointing to a local file.
     pub fn file<S: Into<SharedString>>(s: S) -> Self {
         Self::File(s.into())
     }
 
-    /// Create a URL pointing to a remote resource.
+    /// Creates a [`SharedUri`] pointing to a remote resource.
     pub fn network<S: Into<SharedString>>(s: S) -> Self {
         Self::Network(s.into())
     }
 }
 
-impl Default for SharedUrl {
+impl Default for SharedUri {
     fn default() -> Self {
         Self::Network(SharedString::default())
     }
 }
 
-impl Deref for SharedUrl {
+impl Deref for SharedUri {
     type Target = SharedString;
 
     fn deref(&self) -> &Self::Target {
@@ -40,7 +40,7 @@ impl Deref for SharedUrl {
     }
 }
 
-impl DerefMut for SharedUrl {
+impl DerefMut for SharedUri {
     fn deref_mut(&mut self) -> &mut Self::Target {
         match self {
             Self::File(s) => s,
@@ -49,7 +49,7 @@ impl DerefMut for SharedUrl {
     }
 }
 
-impl std::fmt::Debug for SharedUrl {
+impl std::fmt::Debug for SharedUri {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         match self {
             Self::File(s) => write!(f, "File({:?})", s),
@@ -58,7 +58,7 @@ impl std::fmt::Debug for SharedUrl {
     }
 }
 
-impl std::fmt::Display for SharedUrl {
+impl std::fmt::Display for SharedUri {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         write!(f, "{}", self.as_ref())
     }

crates/theme/src/styles/stories/players.rs 🔗

@@ -1,4 +1,4 @@
-use gpui::{div, img, px, IntoElement, ParentElement, Render, SharedUrl, Styled, ViewContext};
+use gpui::{div, img, px, IntoElement, ParentElement, Render, SharedUri, Styled, ViewContext};
 use story::Story;
 
 use crate::{ActiveTheme, PlayerColors};
@@ -53,7 +53,7 @@ impl Render for PlayerStory {
                             .border_2()
                             .border_color(player.cursor)
                             .child(
-                                img(SharedUrl::network(
+                                img(SharedUri::network(
                                     "https://avatars.githubusercontent.com/u/1714999?v=4",
                                 ))
                                 .rounded_full()
@@ -84,7 +84,7 @@ impl Render for PlayerStory {
                                     .border_color(player.background)
                                     .size(px(28.))
                                     .child(
-                                        img(SharedUrl::network(
+                                        img(SharedUri::network(
                                             "https://avatars.githubusercontent.com/u/1714999?v=4",
                                         ))
                                         .rounded_full()
@@ -102,7 +102,7 @@ impl Render for PlayerStory {
                                     .border_color(player.background)
                                     .size(px(28.))
                                     .child(
-                                        img(SharedUrl::network(
+                                        img(SharedUri::network(
                                             "https://avatars.githubusercontent.com/u/1714999?v=4",
                                         ))
                                         .rounded_full()
@@ -120,7 +120,7 @@ impl Render for PlayerStory {
                                     .border_color(player.background)
                                     .size(px(28.))
                                     .child(
-                                        img(SharedUrl::network(
+                                        img(SharedUri::network(
                                             "https://avatars.githubusercontent.com/u/1714999?v=4",
                                         ))
                                         .rounded_full()

crates/ui/src/components/stories/avatar.rs 🔗

@@ -1,4 +1,4 @@
-use gpui::{Render, SharedUrl};
+use gpui::{Render, SharedUri};
 use story::{StoryContainer, StoryItem, StorySection};
 
 use crate::{prelude::*, AudioStatus, Availability, AvatarAvailabilityIndicator};
@@ -13,13 +13,13 @@ impl Render for AvatarStory {
                 StorySection::new()
                     .child(StoryItem::new(
                         "Default",
-                        Avatar::new(SharedUrl::network(
+                        Avatar::new(SharedUri::network(
                             "https://avatars.githubusercontent.com/u/1714999?v=4",
                         )),
                     ))
                     .child(StoryItem::new(
                         "Default",
-                        Avatar::new(SharedUrl::network(
+                        Avatar::new(SharedUri::network(
                             "https://avatars.githubusercontent.com/u/326587?v=4",
                         )),
                     )),
@@ -28,14 +28,14 @@ impl Render for AvatarStory {
                 StorySection::new()
                     .child(StoryItem::new(
                         "With free availability indicator",
-                        Avatar::new(SharedUrl::network(
+                        Avatar::new(SharedUri::network(
                             "https://avatars.githubusercontent.com/u/326587?v=4",
                         ))
                         .indicator(AvatarAvailabilityIndicator::new(Availability::Free)),
                     ))
                     .child(StoryItem::new(
                         "With busy availability indicator",
-                        Avatar::new(SharedUrl::network(
+                        Avatar::new(SharedUri::network(
                             "https://avatars.githubusercontent.com/u/326587?v=4",
                         ))
                         .indicator(AvatarAvailabilityIndicator::new(Availability::Busy)),
@@ -45,14 +45,14 @@ impl Render for AvatarStory {
                 StorySection::new()
                     .child(StoryItem::new(
                         "With info border",
-                        Avatar::new(SharedUrl::network(
+                        Avatar::new(SharedUri::network(
                             "https://avatars.githubusercontent.com/u/326587?v=4",
                         ))
                         .border_color(cx.theme().status().info_border),
                     ))
                     .child(StoryItem::new(
                         "With error border",
-                        Avatar::new(SharedUrl::network(
+                        Avatar::new(SharedUri::network(
                             "https://avatars.githubusercontent.com/u/326587?v=4",
                         ))
                         .border_color(cx.theme().status().error_border),
@@ -62,14 +62,14 @@ impl Render for AvatarStory {
                 StorySection::new()
                     .child(StoryItem::new(
                         "With muted audio indicator",
-                        Avatar::new(SharedUrl::network(
+                        Avatar::new(SharedUri::network(
                             "https://avatars.githubusercontent.com/u/326587?v=4",
                         ))
                         .indicator(AvatarAudioStatusIndicator::new(AudioStatus::Muted)),
                     ))
                     .child(StoryItem::new(
                         "With deafened audio indicator",
-                        Avatar::new(SharedUrl::network(
+                        Avatar::new(SharedUri::network(
                             "https://avatars.githubusercontent.com/u/326587?v=4",
                         ))
                         .indicator(AvatarAudioStatusIndicator::new(AudioStatus::Deafened)),

crates/ui/src/components/stories/list_item.rs 🔗

@@ -1,4 +1,4 @@
-use gpui::{Render, SharedUrl};
+use gpui::{Render, SharedUri};
 use story::Story;
 
 use crate::{prelude::*, Avatar};
@@ -45,7 +45,7 @@ impl Render for ListItemStory {
             .child(
                 ListItem::new("with_start slot avatar")
                     .child("Hello, world!")
-                    .start_slot(Avatar::new(SharedUrl::network(
+                    .start_slot(Avatar::new(SharedUri::network(
                         "https://avatars.githubusercontent.com/u/1714999?v=4",
                     ))),
             )
@@ -53,7 +53,7 @@ impl Render for ListItemStory {
             .child(
                 ListItem::new("with_left_avatar")
                     .child("Hello, world!")
-                    .end_slot(Avatar::new(SharedUrl::network(
+                    .end_slot(Avatar::new(SharedUri::network(
                         "https://avatars.githubusercontent.com/u/1714999?v=4",
                     ))),
             )
@@ -64,23 +64,23 @@ impl Render for ListItemStory {
                     .end_slot(
                         h_flex()
                             .gap_2()
-                            .child(Avatar::new(SharedUrl::network(
+                            .child(Avatar::new(SharedUri::network(
                                 "https://avatars.githubusercontent.com/u/1789?v=4",
                             )))
-                            .child(Avatar::new(SharedUrl::network(
+                            .child(Avatar::new(SharedUri::network(
                                 "https://avatars.githubusercontent.com/u/1789?v=4",
                             )))
-                            .child(Avatar::new(SharedUrl::network(
+                            .child(Avatar::new(SharedUri::network(
                                 "https://avatars.githubusercontent.com/u/1789?v=4",
                             )))
-                            .child(Avatar::new(SharedUrl::network(
+                            .child(Avatar::new(SharedUri::network(
                                 "https://avatars.githubusercontent.com/u/1789?v=4",
                             )))
-                            .child(Avatar::new(SharedUrl::network(
+                            .child(Avatar::new(SharedUri::network(
                                 "https://avatars.githubusercontent.com/u/1789?v=4",
                             ))),
                     )
-                    .end_hover_slot(Avatar::new(SharedUrl::network(
+                    .end_hover_slot(Avatar::new(SharedUri::network(
                         "https://avatars.githubusercontent.com/u/1714999?v=4",
                     ))),
             )