Compare commits
26 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5d49666ccf | ||
![]() |
f445be90c0 | ||
![]() |
512fa39ed2 | ||
![]() |
05681f26b7 | ||
![]() |
3d3f10d053 | ||
![]() |
fe8045dc79 | ||
![]() |
5be87abb4d | ||
![]() |
03e3166586 | ||
![]() |
0c8511c537 | ||
![]() |
8a5d979d12 | ||
![]() |
c9d1cc495c | ||
![]() |
a0597d255b | ||
![]() |
dd10d7245c | ||
![]() |
d58dd7eb8d | ||
![]() |
0296ca1364 | ||
![]() |
44bc931bd3 | ||
![]() |
a01915edca | ||
![]() |
95a8f76227 | ||
![]() |
4ac08a809b | ||
![]() |
0bb060233f | ||
![]() |
ef591a1abf | ||
![]() |
029a443f92 | ||
![]() |
afe1fb3d1c | ||
![]() |
897efd0dbe | ||
![]() |
692f25ab5a | ||
![]() |
4fda5f22c6 |
29 changed files with 356 additions and 219 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -9792,7 +9792,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zed"
|
||||
version = "0.105.0"
|
||||
version = "0.105.5"
|
||||
dependencies = [
|
||||
"activity_indicator",
|
||||
"ai",
|
||||
|
|
|
@ -303,7 +303,7 @@
|
|||
"replace_newest": false
|
||||
}
|
||||
],
|
||||
"cmd-shift-d": "editor::SelectAllMatches",
|
||||
"cmd-shift-l": "editor::SelectAllMatches",
|
||||
"ctrl-cmd-d": [
|
||||
"editor::SelectPrevious",
|
||||
{
|
||||
|
@ -463,7 +463,7 @@
|
|||
"context": "Editor",
|
||||
"bindings": {
|
||||
"ctrl-shift-k": "editor::DeleteLine",
|
||||
"cmd-shift-l": "editor::SplitSelectionIntoLines",
|
||||
"cmd-shift-d": "editor::DuplicateLine",
|
||||
"ctrl-j": "editor::JoinLines",
|
||||
"ctrl-cmd-up": "editor::MoveLineUp",
|
||||
"ctrl-cmd-down": "editor::MoveLineDown",
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"ctrl-shift-down": "editor::AddSelectionBelow",
|
||||
"cmd-shift-space": "editor::SelectAll",
|
||||
"ctrl-shift-m": "editor::SelectLargerSyntaxNode",
|
||||
"cmd-shift-l": "editor::SplitSelectionIntoLines",
|
||||
"cmd-shift-a": "editor::SelectLargerSyntaxNode",
|
||||
"shift-f12": "editor::FindAllReferences",
|
||||
"alt-cmd-down": "editor::GoToDefinition",
|
||||
|
|
|
@ -370,7 +370,7 @@
|
|||
},
|
||||
// Difference settings for semantic_index
|
||||
"semantic_index": {
|
||||
"enabled": false
|
||||
"enabled": true
|
||||
},
|
||||
// Different settings for specific languages.
|
||||
"languages": {
|
||||
|
|
|
@ -3,10 +3,7 @@ mod channel_index;
|
|||
use crate::{channel_buffer::ChannelBuffer, channel_chat::ChannelChat};
|
||||
use anyhow::{anyhow, Result};
|
||||
use client::{Client, Subscription, User, UserId, UserStore};
|
||||
use collections::{
|
||||
hash_map::{self, DefaultHasher},
|
||||
HashMap, HashSet,
|
||||
};
|
||||
use collections::{hash_map, HashMap, HashSet};
|
||||
use futures::{channel::mpsc, future::Shared, Future, FutureExt, StreamExt};
|
||||
use gpui::{AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, Task, WeakModelHandle};
|
||||
use rpc::{
|
||||
|
@ -14,14 +11,7 @@ use rpc::{
|
|||
TypedEnvelope,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
hash::{Hash, Hasher},
|
||||
mem,
|
||||
ops::Deref,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
use std::{borrow::Cow, hash::Hash, mem, ops::Deref, sync::Arc, time::Duration};
|
||||
use util::ResultExt;
|
||||
|
||||
use self::channel_index::ChannelIndex;
|
||||
|
@ -910,12 +900,6 @@ impl ChannelPath {
|
|||
pub fn channel_id(&self) -> ChannelId {
|
||||
self.0[self.0.len() - 1]
|
||||
}
|
||||
|
||||
pub fn unique_id(&self) -> u64 {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
self.0.deref().hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ChannelPath> for Cow<'static, ChannelPath> {
|
||||
|
|
|
@ -828,68 +828,53 @@ impl Database {
|
|||
) -> Result<ChannelGraph> {
|
||||
self.check_user_is_channel_admin(to, user, &*tx).await?;
|
||||
|
||||
let to_ancestors = self.get_channel_ancestors(to, &*tx).await?;
|
||||
let paths = channel_path::Entity::find()
|
||||
.filter(channel_path::Column::IdPath.like(&format!("%/{}/%", channel)))
|
||||
.all(tx)
|
||||
.await?;
|
||||
|
||||
let mut new_path_suffixes = HashSet::default();
|
||||
for path in paths {
|
||||
if let Some(start_offset) = path.id_path.find(&format!("/{}/", channel)) {
|
||||
new_path_suffixes.insert((
|
||||
path.channel_id,
|
||||
path.id_path[(start_offset + 1)..].to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let paths_to_new_parent = channel_path::Entity::find()
|
||||
.filter(channel_path::Column::ChannelId.eq(to))
|
||||
.all(tx)
|
||||
.await?;
|
||||
|
||||
let mut new_paths = Vec::new();
|
||||
for path in paths_to_new_parent {
|
||||
if path.id_path.contains(&format!("/{}/", channel)) {
|
||||
Err(anyhow!("cycle"))?;
|
||||
}
|
||||
|
||||
new_paths.extend(new_path_suffixes.iter().map(|(channel_id, path_suffix)| {
|
||||
channel_path::ActiveModel {
|
||||
channel_id: ActiveValue::Set(*channel_id),
|
||||
id_path: ActiveValue::Set(format!("{}{}", &path.id_path, path_suffix)),
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
channel_path::Entity::insert_many(new_paths)
|
||||
.exec(&*tx)
|
||||
.await?;
|
||||
|
||||
// remove any root edges for the channel we just linked
|
||||
{
|
||||
channel_path::Entity::delete_many()
|
||||
.filter(channel_path::Column::IdPath.like(&format!("/{}/%", channel)))
|
||||
.exec(&*tx)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let mut channel_descendants = self.get_channel_descendants([channel], &*tx).await?;
|
||||
for ancestor in to_ancestors {
|
||||
if channel_descendants.contains_key(&ancestor) {
|
||||
return Err(anyhow!("Cannot create a channel cycle").into());
|
||||
}
|
||||
}
|
||||
|
||||
// Now insert all of the new paths
|
||||
let sql = r#"
|
||||
INSERT INTO channel_paths
|
||||
(id_path, channel_id)
|
||||
SELECT
|
||||
id_path || $1 || '/', $2
|
||||
FROM
|
||||
channel_paths
|
||||
WHERE
|
||||
channel_id = $3
|
||||
ON CONFLICT (id_path) DO NOTHING;
|
||||
"#;
|
||||
let channel_paths_stmt = Statement::from_sql_and_values(
|
||||
self.pool.get_database_backend(),
|
||||
sql,
|
||||
[
|
||||
channel.to_proto().into(),
|
||||
channel.to_proto().into(),
|
||||
to.to_proto().into(),
|
||||
],
|
||||
);
|
||||
tx.execute(channel_paths_stmt).await?;
|
||||
for (descdenant_id, descendant_parent_ids) in
|
||||
channel_descendants.iter().filter(|(id, _)| id != &&channel)
|
||||
{
|
||||
for descendant_parent_id in descendant_parent_ids.iter() {
|
||||
let channel_paths_stmt = Statement::from_sql_and_values(
|
||||
self.pool.get_database_backend(),
|
||||
sql,
|
||||
[
|
||||
descdenant_id.to_proto().into(),
|
||||
descdenant_id.to_proto().into(),
|
||||
descendant_parent_id.to_proto().into(),
|
||||
],
|
||||
);
|
||||
tx.execute(channel_paths_stmt).await?;
|
||||
}
|
||||
}
|
||||
|
||||
// If we're linking a channel, remove any root edges for the channel
|
||||
{
|
||||
let sql = r#"
|
||||
DELETE FROM channel_paths
|
||||
WHERE
|
||||
id_path = '/' || $1 || '/'
|
||||
"#;
|
||||
let channel_paths_stmt = Statement::from_sql_and_values(
|
||||
self.pool.get_database_backend(),
|
||||
sql,
|
||||
[channel.to_proto().into()],
|
||||
);
|
||||
tx.execute(channel_paths_stmt).await?;
|
||||
}
|
||||
|
||||
if let Some(channel) = channel_descendants.get_mut(&channel) {
|
||||
// Remove the other parents
|
||||
channel.clear();
|
||||
|
@ -936,35 +921,43 @@ impl Database {
|
|||
self.check_user_is_channel_admin(from, user, &*tx).await?;
|
||||
|
||||
let sql = r#"
|
||||
DELETE FROM channel_paths
|
||||
WHERE
|
||||
id_path LIKE '%' || $1 || '/' || $2 || '%'
|
||||
"#;
|
||||
let channel_paths_stmt = Statement::from_sql_and_values(
|
||||
self.pool.get_database_backend(),
|
||||
sql,
|
||||
[from.to_proto().into(), channel.to_proto().into()],
|
||||
);
|
||||
tx.execute(channel_paths_stmt).await?;
|
||||
DELETE FROM channel_paths
|
||||
WHERE
|
||||
id_path LIKE '%/' || $1 || '/' || $2 || '/%'
|
||||
RETURNING id_path, channel_id
|
||||
"#;
|
||||
|
||||
let paths = channel_path::Entity::find()
|
||||
.from_raw_sql(Statement::from_sql_and_values(
|
||||
self.pool.get_database_backend(),
|
||||
sql,
|
||||
[from.to_proto().into(), channel.to_proto().into()],
|
||||
))
|
||||
.all(&*tx)
|
||||
.await?;
|
||||
|
||||
let is_stranded = channel_path::Entity::find()
|
||||
.filter(channel_path::Column::ChannelId.eq(channel))
|
||||
.count(&*tx)
|
||||
.await?
|
||||
== 0;
|
||||
|
||||
// Make sure that there is always at least one path to the channel
|
||||
let sql = r#"
|
||||
INSERT INTO channel_paths
|
||||
(id_path, channel_id)
|
||||
SELECT
|
||||
'/' || $1 || '/', $2
|
||||
WHERE NOT EXISTS
|
||||
(SELECT *
|
||||
FROM channel_paths
|
||||
WHERE channel_id = $2)
|
||||
"#;
|
||||
|
||||
let channel_paths_stmt = Statement::from_sql_and_values(
|
||||
self.pool.get_database_backend(),
|
||||
sql,
|
||||
[channel.to_proto().into(), channel.to_proto().into()],
|
||||
);
|
||||
tx.execute(channel_paths_stmt).await?;
|
||||
if is_stranded {
|
||||
let root_paths: Vec<_> = paths
|
||||
.iter()
|
||||
.map(|path| {
|
||||
let start_offset = path.id_path.find(&format!("/{}/", channel)).unwrap();
|
||||
channel_path::ActiveModel {
|
||||
channel_id: ActiveValue::Set(path.channel_id),
|
||||
id_path: ActiveValue::Set(path.id_path[start_offset..].to_string()),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
channel_path::Entity::insert_many(root_paths)
|
||||
.exec(&*tx)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -978,6 +971,13 @@ impl Database {
|
|||
from: ChannelId,
|
||||
to: ChannelId,
|
||||
) -> Result<ChannelGraph> {
|
||||
if from == to {
|
||||
return Ok(ChannelGraph {
|
||||
channels: vec![],
|
||||
edges: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
self.transaction(|tx| async move {
|
||||
self.check_user_is_channel_admin(channel, user, &*tx)
|
||||
.await?;
|
||||
|
|
|
@ -791,6 +791,64 @@ async fn test_db_channel_moving(db: &Arc<Database>) {
|
|||
assert!(result.channels.is_empty())
|
||||
}
|
||||
|
||||
test_both_dbs!(
|
||||
test_db_channel_moving_bugs,
|
||||
test_db_channel_moving_bugs_postgres,
|
||||
test_db_channel_moving_bugs_sqlite
|
||||
);
|
||||
|
||||
async fn test_db_channel_moving_bugs(db: &Arc<Database>) {
|
||||
let user_id = db
|
||||
.create_user(
|
||||
"user1@example.com",
|
||||
false,
|
||||
NewUserParams {
|
||||
github_login: "user1".into(),
|
||||
github_user_id: 5,
|
||||
invite_count: 0,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.user_id;
|
||||
|
||||
let zed_id = db.create_root_channel("zed", "1", user_id).await.unwrap();
|
||||
|
||||
let projects_id = db
|
||||
.create_channel("projects", Some(zed_id), "2", user_id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let livestreaming_id = db
|
||||
.create_channel("livestreaming", Some(projects_id), "3", user_id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Dag is: zed - projects - livestreaming
|
||||
|
||||
// Move to same parent should be a no-op
|
||||
assert!(db
|
||||
.move_channel(user_id, projects_id, zed_id, zed_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
|
||||
// Stranding a channel should retain it's sub channels
|
||||
db.unlink_channel(user_id, projects_id, zed_id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = db.get_channels_for_user(user_id).await.unwrap();
|
||||
assert_dag(
|
||||
result.channels,
|
||||
&[
|
||||
(zed_id, None),
|
||||
(projects_id, None),
|
||||
(livestreaming_id, Some(projects_id)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn assert_dag(actual: ChannelGraph, expected: &[(ChannelId, Option<ChannelId>)]) {
|
||||
let mut actual_map: HashMap<ChannelId, HashSet<ChannelId>> = HashMap::default();
|
||||
|
|
|
@ -2474,6 +2474,11 @@ async fn move_channel(
|
|||
.move_channel(session.user_id, channel_id, from_parent, to)
|
||||
.await?;
|
||||
|
||||
if channels_to_send.is_empty() {
|
||||
response.send(Ack {})?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let members_from = db.get_channel_members(from_parent).await?;
|
||||
let members_to = db.get_channel_members(to).await?;
|
||||
|
||||
|
|
|
@ -145,8 +145,6 @@ async fn test_core_channels(
|
|||
],
|
||||
);
|
||||
|
||||
println!("STARTING CREATE CHANNEL C");
|
||||
|
||||
let channel_c_id = client_a
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, cx| {
|
||||
|
@ -1028,10 +1026,6 @@ async fn test_channel_moving(
|
|||
// - ep
|
||||
assert_channels_list_shape(client_c.channel_store(), cx_c, &[(channel_ep_id, 0)]);
|
||||
|
||||
println!("*******************************************");
|
||||
println!("********** STARTING LINK CHANNEL **********");
|
||||
println!("*******************************************");
|
||||
dbg!(client_b.user_id());
|
||||
client_b
|
||||
.channel_store()
|
||||
.update(cx_b, |channel_store, cx| {
|
||||
|
@ -1199,5 +1193,5 @@ fn assert_channels_list_shape(
|
|||
.map(|(depth, channel)| (channel.id, depth))
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
pretty_assertions::assert_eq!(dbg!(actual), expected_channels);
|
||||
pretty_assertions::assert_eq!(actual, expected_channels);
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ struct ManageMembers {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct OpenChannelNotes {
|
||||
pub channel_id: u64,
|
||||
pub channel_id: ChannelId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
|
@ -95,11 +95,6 @@ pub struct JoinChannelCall {
|
|||
pub channel_id: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
struct OpenChannelBuffer {
|
||||
channel_id: ChannelId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
struct StartMoveChannelFor {
|
||||
channel_id: ChannelId,
|
||||
|
@ -155,7 +150,6 @@ impl_actions!(
|
|||
ToggleCollapse,
|
||||
OpenChannelNotes,
|
||||
JoinChannelCall,
|
||||
OpenChannelBuffer,
|
||||
LinkChannel,
|
||||
StartMoveChannelFor,
|
||||
StartLinkChannelFor,
|
||||
|
@ -1793,7 +1787,7 @@ impl CollabPanel {
|
|||
is_dragged_over = true;
|
||||
}
|
||||
|
||||
MouseEventHandler::new::<Channel, _>(path.unique_id() as usize, cx, |state, cx| {
|
||||
MouseEventHandler::new::<Channel, _>(ix, cx, |state, cx| {
|
||||
let row_hovered = state.hovered();
|
||||
|
||||
let mut select_state = |interactive: &Interactive<ContainerStyle>| {
|
||||
|
@ -1828,47 +1822,43 @@ impl CollabPanel {
|
|||
.flex(1., true),
|
||||
)
|
||||
.with_child(
|
||||
MouseEventHandler::new::<ChannelCall, _>(
|
||||
channel.id as usize,
|
||||
cx,
|
||||
move |_, cx| {
|
||||
let participants =
|
||||
self.channel_store.read(cx).channel_participants(channel_id);
|
||||
if !participants.is_empty() {
|
||||
let extra_count = participants.len().saturating_sub(FACEPILE_LIMIT);
|
||||
MouseEventHandler::new::<ChannelCall, _>(ix, cx, move |_, cx| {
|
||||
let participants =
|
||||
self.channel_store.read(cx).channel_participants(channel_id);
|
||||
if !participants.is_empty() {
|
||||
let extra_count = participants.len().saturating_sub(FACEPILE_LIMIT);
|
||||
|
||||
FacePile::new(theme.face_overlap)
|
||||
.with_children(
|
||||
participants
|
||||
.iter()
|
||||
.filter_map(|user| {
|
||||
Some(
|
||||
Image::from_data(user.avatar.clone()?)
|
||||
.with_style(theme.channel_avatar),
|
||||
)
|
||||
})
|
||||
.take(FACEPILE_LIMIT),
|
||||
FacePile::new(theme.face_overlap)
|
||||
.with_children(
|
||||
participants
|
||||
.iter()
|
||||
.filter_map(|user| {
|
||||
Some(
|
||||
Image::from_data(user.avatar.clone()?)
|
||||
.with_style(theme.channel_avatar),
|
||||
)
|
||||
})
|
||||
.take(FACEPILE_LIMIT),
|
||||
)
|
||||
.with_children((extra_count > 0).then(|| {
|
||||
Label::new(
|
||||
format!("+{}", extra_count),
|
||||
theme.extra_participant_label.text.clone(),
|
||||
)
|
||||
.with_children((extra_count > 0).then(|| {
|
||||
Label::new(
|
||||
format!("+{}", extra_count),
|
||||
theme.extra_participant_label.text.clone(),
|
||||
)
|
||||
.contained()
|
||||
.with_style(theme.extra_participant_label.container)
|
||||
}))
|
||||
.into_any()
|
||||
} else if row_hovered {
|
||||
Svg::new("icons/speaker-loud.svg")
|
||||
.with_color(theme.channel_hash.color)
|
||||
.constrained()
|
||||
.with_width(theme.channel_hash.width)
|
||||
.into_any()
|
||||
} else {
|
||||
Empty::new().into_any()
|
||||
}
|
||||
},
|
||||
)
|
||||
.contained()
|
||||
.with_style(theme.extra_participant_label.container)
|
||||
}))
|
||||
.into_any()
|
||||
} else if row_hovered {
|
||||
Svg::new("icons/speaker-loud.svg")
|
||||
.with_color(theme.channel_hash.color)
|
||||
.constrained()
|
||||
.with_width(theme.channel_hash.width)
|
||||
.into_any()
|
||||
} else {
|
||||
Empty::new().into_any()
|
||||
}
|
||||
})
|
||||
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||
this.join_channel_call(channel_id, cx);
|
||||
}),
|
||||
|
@ -1881,7 +1871,7 @@ impl CollabPanel {
|
|||
location: path.clone(),
|
||||
}),
|
||||
)
|
||||
.with_id(path.unique_id() as usize)
|
||||
.with_id(ix)
|
||||
.with_style(theme.disclosure.clone())
|
||||
.element()
|
||||
.constrained()
|
||||
|
@ -1961,11 +1951,11 @@ impl CollabPanel {
|
|||
})
|
||||
.as_draggable(
|
||||
(channel.clone(), path.parent_id()),
|
||||
move |e, (channel, _), cx: &mut ViewContext<Workspace>| {
|
||||
move |modifiers, (channel, _), cx: &mut ViewContext<Workspace>| {
|
||||
let theme = &theme::current(cx).collab_panel;
|
||||
|
||||
Flex::<Workspace>::row()
|
||||
.with_children(e.alt.then(|| {
|
||||
.with_children(modifiers.alt.then(|| {
|
||||
Svg::new("icons/plus.svg")
|
||||
.with_color(theme.channel_hash.color)
|
||||
.constrained()
|
||||
|
@ -2318,7 +2308,7 @@ impl CollabPanel {
|
|||
|
||||
items.push(ContextMenuItem::action(
|
||||
"Open Notes",
|
||||
OpenChannelBuffer {
|
||||
OpenChannelNotes {
|
||||
channel_id: path.channel_id(),
|
||||
},
|
||||
));
|
||||
|
|
|
@ -364,9 +364,15 @@ impl<V: 'static> Draggable<V> for MouseEventHandler<V> {
|
|||
DragAndDrop::<D>::drag_started(e, cx);
|
||||
})
|
||||
.on_drag(MouseButton::Left, move |e, _, cx| {
|
||||
let payload = payload.clone();
|
||||
let render = render.clone();
|
||||
DragAndDrop::<D>::dragging(e, payload, cx, render)
|
||||
if e.end {
|
||||
cx.update_global::<DragAndDrop<D>, _, _>(|drag_and_drop, cx| {
|
||||
drag_and_drop.finish_dragging(cx)
|
||||
})
|
||||
} else {
|
||||
let payload = payload.clone();
|
||||
let render = render.clone();
|
||||
DragAndDrop::<D>::dragging(e, payload, cx, render)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1131,12 +1131,14 @@ struct CodeActionsMenu {
|
|||
impl CodeActionsMenu {
|
||||
fn select_first(&mut self, cx: &mut ViewContext<Editor>) {
|
||||
self.selected_item = 0;
|
||||
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
||||
cx.notify()
|
||||
}
|
||||
|
||||
fn select_prev(&mut self, cx: &mut ViewContext<Editor>) {
|
||||
if self.selected_item > 0 {
|
||||
self.selected_item -= 1;
|
||||
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
||||
cx.notify()
|
||||
}
|
||||
}
|
||||
|
@ -1144,12 +1146,14 @@ impl CodeActionsMenu {
|
|||
fn select_next(&mut self, cx: &mut ViewContext<Editor>) {
|
||||
if self.selected_item + 1 < self.actions.len() {
|
||||
self.selected_item += 1;
|
||||
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
||||
cx.notify()
|
||||
}
|
||||
}
|
||||
|
||||
fn select_last(&mut self, cx: &mut ViewContext<Editor>) {
|
||||
self.selected_item = self.actions.len() - 1;
|
||||
self.list.scroll_to(ScrollTarget::Show(self.selected_item));
|
||||
cx.notify()
|
||||
}
|
||||
|
||||
|
@ -1202,7 +1206,9 @@ impl CodeActionsMenu {
|
|||
workspace.update(cx, |workspace, cx| {
|
||||
if let Some(task) = Editor::confirm_code_action(
|
||||
workspace,
|
||||
&Default::default(),
|
||||
&ConfirmCodeAction {
|
||||
item_ix: Some(item_ix),
|
||||
},
|
||||
cx,
|
||||
) {
|
||||
task.detach_and_log_err(cx);
|
||||
|
@ -6048,10 +6054,12 @@ impl Editor {
|
|||
let query = buffer
|
||||
.text_for_range(selection.start..selection.end)
|
||||
.collect::<String>();
|
||||
|
||||
let is_empty = query.is_empty();
|
||||
let select_state = SelectNextState {
|
||||
query: AhoCorasick::new(&[query])?,
|
||||
wordwise: true,
|
||||
done: false,
|
||||
done: is_empty,
|
||||
};
|
||||
select_next_match_ranges(
|
||||
self,
|
||||
|
|
|
@ -941,7 +941,7 @@ async fn fetch_and_update_hints(
|
|||
})
|
||||
.await;
|
||||
if let Some(new_update) = new_update {
|
||||
log::info!(
|
||||
log::debug!(
|
||||
"Applying update for range {fetch_range_to_log:?}: remove from editor: {}, remove from cache: {}, add to cache: {}",
|
||||
new_update.remove_from_visible.len(),
|
||||
new_update.remove_from_cache.len(),
|
||||
|
|
|
@ -611,9 +611,10 @@ impl<'a> WindowContext<'a> {
|
|||
}
|
||||
|
||||
Event::MouseUp(e) => {
|
||||
// NOTE: The order of event pushes is important! MouseUp events MUST be fired
|
||||
// before click events, and so the MouseUp events need to be pushed before
|
||||
// MouseClick events.
|
||||
mouse_events.push(MouseEvent::Up(MouseUp {
|
||||
region: Default::default(),
|
||||
platform_event: e.clone(),
|
||||
}));
|
||||
|
||||
// Synthesize one last drag event to end the drag
|
||||
mouse_events.push(MouseEvent::Drag(MouseDrag {
|
||||
|
@ -626,10 +627,7 @@ impl<'a> WindowContext<'a> {
|
|||
},
|
||||
end: true,
|
||||
}));
|
||||
mouse_events.push(MouseEvent::Up(MouseUp {
|
||||
region: Default::default(),
|
||||
platform_event: e.clone(),
|
||||
}));
|
||||
|
||||
mouse_events.push(MouseEvent::UpOut(MouseUpOut {
|
||||
region: Default::default(),
|
||||
platform_event: e.clone(),
|
||||
|
|
|
@ -181,6 +181,13 @@ impl LogStore {
|
|||
});
|
||||
|
||||
let server = project.read(cx).language_server_for_id(id);
|
||||
if let Some(server) = server.as_deref() {
|
||||
if server.has_notification_handler::<lsp::notification::LogMessage>() {
|
||||
// Another event wants to re-add the server that was already added and subscribed to, avoid doing it again.
|
||||
return Some(server_state.log_buffer.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let weak_project = project.downgrade();
|
||||
let io_tx = self.io_tx.clone();
|
||||
server_state._io_logs_subscription = server.as_ref().map(|server| {
|
||||
|
@ -647,6 +654,7 @@ impl View for LspLogToolbarItemView {
|
|||
Overlay::new(
|
||||
MouseEventHandler::new::<Menu, _>(0, cx, move |_, cx| {
|
||||
Flex::column()
|
||||
.scrollable::<Self>(0, None, cx)
|
||||
.with_children(menu_rows.into_iter().map(|row| {
|
||||
Self::render_language_server_menu_item(
|
||||
row.server_id,
|
||||
|
|
|
@ -605,6 +605,10 @@ impl LanguageServer {
|
|||
self.notification_handlers.lock().remove(T::METHOD);
|
||||
}
|
||||
|
||||
pub fn has_notification_handler<T: notification::Notification>(&self) -> bool {
|
||||
self.notification_handlers.lock().contains_key(T::METHOD)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn on_custom_notification<Params, F>(&self, method: &'static str, mut f: F) -> Subscription
|
||||
where
|
||||
|
|
|
@ -7968,7 +7968,7 @@ impl Project {
|
|||
}
|
||||
|
||||
pub fn language_server_for_id(&self, id: LanguageServerId) -> Option<Arc<LanguageServer>> {
|
||||
if let LanguageServerState::Running { server, .. } = self.language_servers.get(&id)? {
|
||||
if let Some(LanguageServerState::Running { server, .. }) = self.language_servers.get(&id) {
|
||||
Some(server.clone())
|
||||
} else if let Some((_, server)) = self.supplementary_language_servers.get(&id) {
|
||||
Some(Arc::clone(server))
|
||||
|
@ -8039,29 +8039,31 @@ fn subscribe_for_copilot_events(
|
|||
copilot,
|
||||
|project, copilot, copilot_event, cx| match copilot_event {
|
||||
copilot::Event::CopilotLanguageServerStarted => {
|
||||
if let Some((name, copilot_server)) = copilot.read(cx).language_server() {
|
||||
let new_server_id = copilot_server.server_id();
|
||||
if let hash_map::Entry::Vacant(v) =
|
||||
project.supplementary_language_servers.entry(new_server_id)
|
||||
{
|
||||
let weak_project = cx.weak_handle();
|
||||
let copilot_log_subscription = copilot_server
|
||||
.on_notification::<copilot::request::LogMessage, _>(
|
||||
move |params, mut cx| {
|
||||
if let Some(project) = weak_project.upgrade(&mut cx) {
|
||||
project.update(&mut cx, |_, cx| {
|
||||
cx.emit(Event::LanguageServerLog(
|
||||
new_server_id,
|
||||
params.message,
|
||||
));
|
||||
})
|
||||
}
|
||||
},
|
||||
);
|
||||
project.copilot_log_subscription = Some(copilot_log_subscription);
|
||||
v.insert((name.clone(), Arc::clone(copilot_server)));
|
||||
cx.emit(Event::LanguageServerAdded(new_server_id));
|
||||
match copilot.read(cx).language_server() {
|
||||
Some((name, copilot_server)) => {
|
||||
// Another event wants to re-add the server that was already added and subscribed to, avoid doing it again.
|
||||
if !copilot_server.has_notification_handler::<copilot::request::LogMessage>() {
|
||||
let new_server_id = copilot_server.server_id();
|
||||
let weak_project = cx.weak_handle();
|
||||
let copilot_log_subscription = copilot_server
|
||||
.on_notification::<copilot::request::LogMessage, _>(
|
||||
move |params, mut cx| {
|
||||
if let Some(project) = weak_project.upgrade(&mut cx) {
|
||||
project.update(&mut cx, |_, cx| {
|
||||
cx.emit(Event::LanguageServerLog(
|
||||
new_server_id,
|
||||
params.message,
|
||||
));
|
||||
})
|
||||
}
|
||||
},
|
||||
);
|
||||
project.supplementary_language_servers.insert(new_server_id, (name.clone(), Arc::clone(copilot_server)));
|
||||
project.copilot_log_subscription = Some(copilot_log_subscription);
|
||||
cx.emit(Event::LanguageServerAdded(new_server_id));
|
||||
}
|
||||
}
|
||||
None => debug_panic!("Received Copilot language server started event, but no language server is running"),
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -322,7 +322,7 @@ impl View for ProjectSearchView {
|
|||
// If Text -> Major: "Text search all files and folders", Minor: {...}
|
||||
|
||||
let current_mode = self.current_mode;
|
||||
let major_text = if model.pending_search.is_some() {
|
||||
let mut major_text = if model.pending_search.is_some() {
|
||||
Cow::Borrowed("Searching...")
|
||||
} else if model.no_results.is_some_and(|v| v) {
|
||||
Cow::Borrowed("No Results")
|
||||
|
@ -336,9 +336,18 @@ impl View for ProjectSearchView {
|
|||
}
|
||||
};
|
||||
|
||||
let mut show_minor_text = true;
|
||||
let semantic_status = self.semantic_state.as_ref().and_then(|semantic| {
|
||||
let status = semantic.index_status;
|
||||
match status {
|
||||
SemanticIndexStatus::NotAuthenticated => {
|
||||
major_text = Cow::Borrowed("Not Authenticated");
|
||||
show_minor_text = false;
|
||||
Some(
|
||||
"API Key Missing: Please set 'OPENAI_API_KEY' in Environment Variables"
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
SemanticIndexStatus::Indexed => Some("Indexing complete".to_string()),
|
||||
SemanticIndexStatus::Indexing {
|
||||
remaining_files,
|
||||
|
@ -380,10 +389,13 @@ impl View for ProjectSearchView {
|
|||
let mut minor_text = Vec::new();
|
||||
minor_text.push("".into());
|
||||
minor_text.extend(semantic_status);
|
||||
minor_text.push("Simply explain the code you are looking to find.".into());
|
||||
minor_text.push(
|
||||
"ex. 'prompt user for permissions to index their project'".into(),
|
||||
);
|
||||
if show_minor_text {
|
||||
minor_text
|
||||
.push("Simply explain the code you are looking to find.".into());
|
||||
minor_text.push(
|
||||
"ex. 'prompt user for permissions to index their project'".into(),
|
||||
);
|
||||
}
|
||||
minor_text
|
||||
}
|
||||
_ => vec![
|
||||
|
|
|
@ -117,6 +117,7 @@ struct OpenAIEmbeddingUsage {
|
|||
|
||||
#[async_trait]
|
||||
pub trait EmbeddingProvider: Sync + Send {
|
||||
fn is_authenticated(&self) -> bool;
|
||||
async fn embed_batch(&self, spans: Vec<String>) -> Result<Vec<Embedding>>;
|
||||
fn max_tokens_per_batch(&self) -> usize;
|
||||
fn truncate(&self, span: &str) -> (String, usize);
|
||||
|
@ -127,6 +128,9 @@ pub struct DummyEmbeddings {}
|
|||
|
||||
#[async_trait]
|
||||
impl EmbeddingProvider for DummyEmbeddings {
|
||||
fn is_authenticated(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn rate_limit_expiration(&self) -> Option<Instant> {
|
||||
None
|
||||
}
|
||||
|
@ -229,6 +233,9 @@ impl OpenAIEmbeddings {
|
|||
|
||||
#[async_trait]
|
||||
impl EmbeddingProvider for OpenAIEmbeddings {
|
||||
fn is_authenticated(&self) -> bool {
|
||||
OPENAI_API_KEY.as_ref().is_some()
|
||||
}
|
||||
fn max_tokens_per_batch(&self) -> usize {
|
||||
50000
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ use embedding_queue::{EmbeddingQueue, FileToEmbed};
|
|||
use futures::{future, FutureExt, StreamExt};
|
||||
use gpui::{AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, Task, WeakModelHandle};
|
||||
use language::{Anchor, Bias, Buffer, Language, LanguageRegistry};
|
||||
use lazy_static::lazy_static;
|
||||
use ordered_float::OrderedFloat;
|
||||
use parking_lot::Mutex;
|
||||
use parsing::{CodeContextRetriever, Span, SpanDigest, PARSEABLE_ENTIRE_FILE_TYPES};
|
||||
|
@ -24,6 +25,7 @@ use project::{search::PathMatcher, Fs, PathChange, Project, ProjectEntryId, Work
|
|||
use smol::channel;
|
||||
use std::{
|
||||
cmp::Reverse,
|
||||
env,
|
||||
future::Future,
|
||||
mem,
|
||||
ops::Range,
|
||||
|
@ -38,6 +40,10 @@ const SEMANTIC_INDEX_VERSION: usize = 11;
|
|||
const BACKGROUND_INDEXING_DELAY: Duration = Duration::from_secs(5 * 60);
|
||||
const EMBEDDING_QUEUE_FLUSH_TIMEOUT: Duration = Duration::from_millis(250);
|
||||
|
||||
lazy_static! {
|
||||
static ref OPENAI_API_KEY: Option<String> = env::var("OPENAI_API_KEY").ok();
|
||||
}
|
||||
|
||||
pub fn init(
|
||||
fs: Arc<dyn Fs>,
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
|
@ -100,6 +106,7 @@ pub fn init(
|
|||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum SemanticIndexStatus {
|
||||
NotAuthenticated,
|
||||
NotIndexed,
|
||||
Indexed,
|
||||
Indexing {
|
||||
|
@ -275,6 +282,10 @@ impl SemanticIndex {
|
|||
}
|
||||
|
||||
pub fn status(&self, project: &ModelHandle<Project>) -> SemanticIndexStatus {
|
||||
if !self.embedding_provider.is_authenticated() {
|
||||
return SemanticIndexStatus::NotAuthenticated;
|
||||
}
|
||||
|
||||
if let Some(project_state) = self.projects.get(&project.downgrade()) {
|
||||
if project_state
|
||||
.worktrees
|
||||
|
@ -694,12 +705,12 @@ impl SemanticIndex {
|
|||
let embedding_provider = self.embedding_provider.clone();
|
||||
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
index.await?;
|
||||
let query = embedding_provider
|
||||
.embed_batch(vec![query])
|
||||
.await?
|
||||
.pop()
|
||||
.ok_or_else(|| anyhow!("could not embed query"))?;
|
||||
index.await?;
|
||||
|
||||
let search_start = Instant::now();
|
||||
let modified_buffer_results = this.update(&mut cx, |this, cx| {
|
||||
|
@ -775,14 +786,23 @@ impl SemanticIndex {
|
|||
.retrieve_included_file_ids(&worktree_db_ids, &includes, &excludes)
|
||||
.await?;
|
||||
|
||||
if file_ids.len() == 0 {
|
||||
return Err(anyhow!("vector database is empty!"));
|
||||
}
|
||||
|
||||
let batch_n = cx.background().num_cpus();
|
||||
let ids_len = file_ids.clone().len();
|
||||
|
||||
let batch_size = if ids_len <= batch_n {
|
||||
ids_len
|
||||
} else {
|
||||
ids_len / batch_n
|
||||
};
|
||||
|
||||
if batch_size == 0 {
|
||||
return Err(anyhow!("vector database is empty!"));
|
||||
}
|
||||
|
||||
let mut batch_results = Vec::new();
|
||||
for batch in file_ids.chunks(batch_size) {
|
||||
let batch = batch.into_iter().map(|v| *v).collect::<Vec<i64>>();
|
||||
|
@ -965,6 +985,10 @@ impl SemanticIndex {
|
|||
project: ModelHandle<Project>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
if !self.embedding_provider.is_authenticated() {
|
||||
return Task::ready(Err(anyhow!("user is not authenticated")));
|
||||
}
|
||||
|
||||
if !self.projects.contains_key(&project.downgrade()) {
|
||||
let subscription = cx.subscribe(&project, |this, project, event, cx| match event {
|
||||
project::Event::WorktreeAdded | project::Event::WorktreeRemoved(_) => {
|
||||
|
|
|
@ -1267,6 +1267,9 @@ impl FakeEmbeddingProvider {
|
|||
|
||||
#[async_trait]
|
||||
impl EmbeddingProvider for FakeEmbeddingProvider {
|
||||
fn is_authenticated(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn truncate(&self, span: &str) -> (String, usize) {
|
||||
(span.to_string(), 1)
|
||||
}
|
||||
|
|
|
@ -533,7 +533,7 @@ fn down(
|
|||
|
||||
let new_row = cmp::min(
|
||||
start.row() + times as u32,
|
||||
map.buffer_snapshot.max_point().row,
|
||||
map.fold_snapshot.max_point().row(),
|
||||
);
|
||||
let new_col = cmp::min(goal_column, map.fold_snapshot.line_len(new_row));
|
||||
let point = map.fold_point_to_display_point(
|
||||
|
|
|
@ -575,6 +575,26 @@ async fn test_folds(cx: &mut gpui::TestAppContext) {
|
|||
.await;
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_folds_panic(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||
cx.set_neovim_option("foldmethod=manual").await;
|
||||
|
||||
cx.set_shared_state(indoc! { "
|
||||
fn boop() {
|
||||
ˇbarp()
|
||||
bazp()
|
||||
}
|
||||
"})
|
||||
.await;
|
||||
cx.simulate_shared_keystrokes(["shift-v", "j", "z", "f"])
|
||||
.await;
|
||||
cx.simulate_shared_keystrokes(["escape"]).await;
|
||||
cx.simulate_shared_keystrokes(["g", "g"]).await;
|
||||
cx.simulate_shared_keystrokes(["5", "d", "j"]).await;
|
||||
cx.assert_shared_state(indoc! { "ˇ"}).await;
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_clear_counts(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||
|
|
13
crates/vim/test_data/test_folds_panic.json
Normal file
13
crates/vim/test_data/test_folds_panic.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{"SetOption":{"value":"foldmethod=manual"}}
|
||||
{"Put":{"state":"fn boop() {\n ˇbarp()\n bazp()\n}\n"}}
|
||||
{"Key":"shift-v"}
|
||||
{"Key":"j"}
|
||||
{"Key":"z"}
|
||||
{"Key":"f"}
|
||||
{"Key":"escape"}
|
||||
{"Key":"g"}
|
||||
{"Key":"g"}
|
||||
{"Key":"5"}
|
||||
{"Key":"d"}
|
||||
{"Key":"j"}
|
||||
{"Get":{"state":"ˇ","mode":"Normal"}}
|
|
@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
|
|||
description = "The fast, collaborative code editor."
|
||||
edition = "2021"
|
||||
name = "zed"
|
||||
version = "0.105.0"
|
||||
version = "0.105.5"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
|
|
|
@ -1 +1 @@
|
|||
dev
|
||||
stable
|
|
@ -1,4 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "1.72"
|
||||
channel = "1.72.1"
|
||||
components = [ "rustfmt" ]
|
||||
targets = [ "x86_64-apple-darwin", "aarch64-apple-darwin", "wasm32-wasi" ]
|
||||
|
|
|
@ -91,7 +91,7 @@ export default function editor(): any {
|
|||
vertical_scale: 0.55,
|
||||
},
|
||||
folds: {
|
||||
icon_margin_scale: 2.5,
|
||||
icon_margin_scale: 4,
|
||||
folded_icon: "icons/chevron_right.svg",
|
||||
foldable_icon: "icons/chevron_down.svg",
|
||||
indicator: toggleable({
|
||||
|
|
|
@ -26,10 +26,10 @@ export default function update_notification(): any {
|
|||
dismiss_button: interactive({
|
||||
base: {
|
||||
color: foreground(theme.middle),
|
||||
icon_width: 8,
|
||||
icon_height: 8,
|
||||
button_width: 8,
|
||||
button_height: 8,
|
||||
icon_width: 14,
|
||||
icon_height: 14,
|
||||
button_width: 14,
|
||||
button_height: 14,
|
||||
},
|
||||
state: {
|
||||
hovered: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue