Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'main' into links
Conrad Irwind4ef76430578
diff --cc crates/call/src/room.rsindex 32b8232b4f7,43354fd5a23..4e52f57f60b--- a/crates/call/src/room.rs+++ b/crates/call/src/room.rs@@@ -605,10 -599,8 +605,8 @@@ impl Room}/// Returns the most 'active' projects, defined as most people in the project- pub fn most_active_project(&self) -> Option<(u64, u64)> {+ pub fn most_active_project(&self, cx: &AppContext) -> Option<(u64, u64)> {- let mut projects = HashMap::default();- let mut hosts = HashMap::default();-+ let mut project_hosts_and_guest_counts = HashMap::<u64, (Option<u64>, u32)>::default();for participant in self.remote_participants.values() {match participant.location {ParticipantLocation::SharedProject { project_id } => {@@@ -622,19 -619,11 +625,20 @@@}}+ if let Some(user) = self.user_store.read(cx).current_user() {+ for project in &self.local_participant.projects {- *projects.entry(project.id).or_insert(0) += 1;- hosts.insert(project.id, user.id);++ project_hosts_and_guest_counts++ .entry(project.id)++ .or_default()++ .0 = Some(user.id);+ }+ }+- let mut pairs: Vec<(u64, usize)> = projects.into_iter().collect();- pairs.sort_by_key(|(_, count)| *count as i32);-- pairs- .iter()- .find_map(|(project_id, _)| hosts.get(project_id).map(|host| (*project_id, *host)))+ project_hosts_and_guest_counts+ .into_iter()+ .filter_map(|(id, (host, guest_count))| Some((id, host?, guest_count)))+ .max_by_key(|(_, _, guest_count)| *guest_count)+ .map(|(id, host, _)| (id, host))}async fn handle_room_updated(diff --cc crates/channel/src/channel_store.rsindex cd2153ad5c5,8cdd11b4ec2..2a2fa454f2b--- a/crates/channel/src/channel_store.rs+++ b/crates/channel/src/channel_store.rs@@@ -2,9 -2,9 +2,10 @@@ mod channel_indexuse crate::{channel_buffer::ChannelBuffer, channel_chat::ChannelChat};use anyhow::{anyhow, Result};+ use channel_index::ChannelIndex;use client::{Client, Subscription, User, UserId, UserStore};use collections::{hash_map, HashMap, HashSet};+use db::RELEASE_CHANNEL;use futures::{channel::mpsc, future::Shared, Future, FutureExt, StreamExt};use gpui::{AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, Task, WeakModelHandle};use rpc::{diff --cc crates/workspace/src/workspace.rsindex c021384d910,bf96558f5cc..c3c6f9a4b6f--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@@ -12,10 -12,9 +12,9 @@@ mod workspace_settingsuse anyhow::{anyhow, Context, Result};use call::ActiveCall;- use channel::ChannelStore;use client::{proto::{self, PeerId},- Client, TypedEnvelope, UserStore,+ Client, Status, TypedEnvelope, UserStore,};use collections::{hash_map, HashMap, HashSet};use drag_and_drop::DragAndDrop;diff --cc crates/zed/src/open_listener.rsindex e3c08ff2c8e,00000000000..9b416e14be4mode 100644,000000..100644--- a/crates/zed/src/open_listener.rs+++ b/crates/zed/src/open_listener.rs@@@ -1,100 -1,0 +1,98 @@@+use anyhow::anyhow;+use cli::{ipc::IpcSender, CliRequest, CliResponse};+use futures::channel::mpsc;+use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};+use std::ffi::OsStr;- use std::fs::OpenOptions;- use std::io::Write;+use std::os::unix::prelude::OsStrExt;+use std::sync::atomic::Ordering;+use std::{path::PathBuf, sync::atomic::AtomicBool};+use util::channel::parse_zed_link;+use util::ResultExt;++use crate::connect_to_cli;++pub enum OpenRequest {+ Paths {+ paths: Vec<PathBuf>,+ },+ CliConnection {+ connection: (mpsc::Receiver<CliRequest>, IpcSender<CliResponse>),+ },+ JoinChannel {+ channel_id: u64,+ },+}++pub struct OpenListener {+ tx: UnboundedSender<OpenRequest>,+ pub triggered: AtomicBool,+}++impl OpenListener {+ pub fn new() -> (Self, UnboundedReceiver<OpenRequest>) {+ let (tx, rx) = mpsc::unbounded();+ (+ OpenListener {+ tx,+ triggered: AtomicBool::new(false),+ },+ rx,+ )+ }++ pub fn open_urls(&self, urls: Vec<String>) {+ self.triggered.store(true, Ordering::Release);+ let request = if let Some(server_name) =+ urls.first().and_then(|url| url.strip_prefix("zed-cli://"))+ {+ self.handle_cli_connection(server_name)+ } else if let Some(request_path) = urls.first().and_then(|url| parse_zed_link(url)) {+ self.handle_zed_url_scheme(request_path)+ } else {+ self.handle_file_urls(urls)+ };++ if let Some(request) = request {+ self.tx+ .unbounded_send(request)+ .map_err(|_| anyhow!("no listener for open requests"))+ .log_err();+ }+ }++ fn handle_cli_connection(&self, server_name: &str) -> Option<OpenRequest> {+ if let Some(connection) = connect_to_cli(server_name).log_err() {+ return Some(OpenRequest::CliConnection { connection });+ }++ None+ }++ fn handle_zed_url_scheme(&self, request_path: &str) -> Option<OpenRequest> {+ let mut parts = request_path.split("/");+ if parts.next() == Some("channel") {+ if let Some(slug) = parts.next() {+ if let Some(id_str) = slug.split("-").last() {+ if let Ok(channel_id) = id_str.parse::<u64>() {+ return Some(OpenRequest::JoinChannel { channel_id });+ }+ }+ }+ }+ log::error!("invalid zed url: {}", request_path);+ None+ }++ fn handle_file_urls(&self, urls: Vec<String>) -> Option<OpenRequest> {+ let paths: Vec<_> = urls+ .iter()+ .flat_map(|url| url.strip_prefix("file://"))+ .map(|url| {+ let decoded = urlencoding::decode_binary(url.as_bytes());+ PathBuf::from(OsStr::from_bytes(decoded.as_ref()))+ })+ .collect();++ Some(OpenRequest::Paths { paths })+ }+}