mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
Format let-else statements
This commit is contained in:
parent
732af201dc
commit
404f76739c
@ -1128,7 +1128,9 @@ impl Conversation {
|
|||||||
stream: true,
|
stream: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(api_key) = self.api_key.borrow().clone() else { continue };
|
let Some(api_key) = self.api_key.borrow().clone() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
let stream = stream_completion(api_key, cx.background().clone(), request);
|
let stream = stream_completion(api_key, cx.background().clone(), request);
|
||||||
let assistant_message = self
|
let assistant_message = self
|
||||||
.insert_message_after(
|
.insert_message_after(
|
||||||
@ -1484,7 +1486,9 @@ impl Conversation {
|
|||||||
}) {
|
}) {
|
||||||
current_message = messages.next();
|
current_message = messages.next();
|
||||||
}
|
}
|
||||||
let Some(message) = current_message.as_ref() else { break };
|
let Some(message) = current_message.as_ref() else {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
// Skip offsets that are in the same message.
|
// Skip offsets that are in the same message.
|
||||||
while offsets.peek().map_or(false, |offset| {
|
while offsets.peek().map_or(false, |offset| {
|
||||||
@ -1921,7 +1925,10 @@ impl ConversationEditor {
|
|||||||
let Some(panel) = workspace.panel::<AssistantPanel>(cx) else {
|
let Some(panel) = workspace.panel::<AssistantPanel>(cx) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let Some(editor) = workspace.active_item(cx).and_then(|item| item.act_as::<Editor>(cx)) else {
|
let Some(editor) = workspace
|
||||||
|
.active_item(cx)
|
||||||
|
.and_then(|item| item.act_as::<Editor>(cx))
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -644,7 +644,9 @@ impl Room {
|
|||||||
|
|
||||||
if let Some(participants) = remote_participants.log_err() {
|
if let Some(participants) = remote_participants.log_err() {
|
||||||
for (participant, user) in room.participants.into_iter().zip(participants) {
|
for (participant, user) in room.participants.into_iter().zip(participants) {
|
||||||
let Some(peer_id) = participant.peer_id else { continue };
|
let Some(peer_id) = participant.peer_id else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
this.participant_user_ids.insert(participant.user_id);
|
this.participant_user_ids.insert(participant.user_id);
|
||||||
|
|
||||||
let old_projects = this
|
let old_projects = this
|
||||||
|
@ -249,7 +249,9 @@ impl Database {
|
|||||||
let mut tx = Arc::new(Some(tx));
|
let mut tx = Arc::new(Some(tx));
|
||||||
let result = f(TransactionHandle(tx.clone())).await;
|
let result = f(TransactionHandle(tx.clone())).await;
|
||||||
let Some(tx) = Arc::get_mut(&mut tx).and_then(|tx| tx.take()) else {
|
let Some(tx) = Arc::get_mut(&mut tx).and_then(|tx| tx.take()) else {
|
||||||
return Err(anyhow!("couldn't complete transaction because it's still in use"))?;
|
return Err(anyhow!(
|
||||||
|
"couldn't complete transaction because it's still in use"
|
||||||
|
))?;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((tx, result))
|
Ok((tx, result))
|
||||||
|
@ -465,9 +465,9 @@ impl Database {
|
|||||||
let mut rejoined_projects = Vec::new();
|
let mut rejoined_projects = Vec::new();
|
||||||
for rejoined_project in &rejoin_room.rejoined_projects {
|
for rejoined_project in &rejoin_room.rejoined_projects {
|
||||||
let project_id = ProjectId::from_proto(rejoined_project.id);
|
let project_id = ProjectId::from_proto(rejoined_project.id);
|
||||||
let Some(project) = project::Entity::find_by_id(project_id)
|
let Some(project) = project::Entity::find_by_id(project_id).one(&*tx).await? else {
|
||||||
.one(&*tx)
|
continue;
|
||||||
.await? else { continue };
|
};
|
||||||
|
|
||||||
let mut worktrees = Vec::new();
|
let mut worktrees = Vec::new();
|
||||||
let db_worktrees = project.find_related(worktree::Entity).all(&*tx).await?;
|
let db_worktrees = project.find_related(worktree::Entity).all(&*tx).await?;
|
||||||
|
@ -121,7 +121,9 @@ async fn test_random_collaboration(
|
|||||||
let mut operation_channels = Vec::new();
|
let mut operation_channels = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let Some((next_operation, applied)) = plan.lock().next_server_operation(&clients) else { break };
|
let Some((next_operation, applied)) = plan.lock().next_server_operation(&clients) else {
|
||||||
|
break;
|
||||||
|
};
|
||||||
applied.store(true, SeqCst);
|
applied.store(true, SeqCst);
|
||||||
let did_apply = apply_server_operation(
|
let did_apply = apply_server_operation(
|
||||||
deterministic.clone(),
|
deterministic.clone(),
|
||||||
@ -224,7 +226,9 @@ async fn apply_server_operation(
|
|||||||
let client_ix = clients
|
let client_ix = clients
|
||||||
.iter()
|
.iter()
|
||||||
.position(|(client, cx)| client.current_user_id(cx) == removed_user_id);
|
.position(|(client, cx)| client.current_user_id(cx) == removed_user_id);
|
||||||
let Some(client_ix) = client_ix else { return false };
|
let Some(client_ix) = client_ix else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
let user_connection_ids = server
|
let user_connection_ids = server
|
||||||
.connection_pool
|
.connection_pool
|
||||||
.lock()
|
.lock()
|
||||||
@ -1591,10 +1595,11 @@ impl TestPlan {
|
|||||||
81.. => match self.rng.gen_range(0..100_u32) {
|
81.. => match self.rng.gen_range(0..100_u32) {
|
||||||
// Add a worktree to a local project
|
// Add a worktree to a local project
|
||||||
0..=50 => {
|
0..=50 => {
|
||||||
let Some(project) = client
|
let Some(project) =
|
||||||
.local_projects()
|
client.local_projects().choose(&mut self.rng).cloned()
|
||||||
.choose(&mut self.rng)
|
else {
|
||||||
.cloned() else { continue };
|
continue;
|
||||||
|
};
|
||||||
let project_root_name = root_name_for_project(&project, cx);
|
let project_root_name = root_name_for_project(&project, cx);
|
||||||
let mut paths = client.fs().paths(false);
|
let mut paths = client.fs().paths(false);
|
||||||
paths.remove(0);
|
paths.remove(0);
|
||||||
@ -1611,7 +1616,9 @@ impl TestPlan {
|
|||||||
|
|
||||||
// Add an entry to a worktree
|
// Add an entry to a worktree
|
||||||
_ => {
|
_ => {
|
||||||
let Some(project) = choose_random_project(client, &mut self.rng) else { continue };
|
let Some(project) = choose_random_project(client, &mut self.rng) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
let project_root_name = root_name_for_project(&project, cx);
|
let project_root_name = root_name_for_project(&project, cx);
|
||||||
let is_local = project.read_with(cx, |project, _| project.is_local());
|
let is_local = project.read_with(cx, |project, _| project.is_local());
|
||||||
let worktree = project.read_with(cx, |project, cx| {
|
let worktree = project.read_with(cx, |project, cx| {
|
||||||
@ -1645,7 +1652,9 @@ impl TestPlan {
|
|||||||
|
|
||||||
// Query and mutate buffers
|
// Query and mutate buffers
|
||||||
60..=90 => {
|
60..=90 => {
|
||||||
let Some(project) = choose_random_project(client, &mut self.rng) else { continue };
|
let Some(project) = choose_random_project(client, &mut self.rng) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
let project_root_name = root_name_for_project(&project, cx);
|
let project_root_name = root_name_for_project(&project, cx);
|
||||||
let is_local = project.read_with(cx, |project, _| project.is_local());
|
let is_local = project.read_with(cx, |project, _| project.is_local());
|
||||||
|
|
||||||
@ -1656,7 +1665,10 @@ impl TestPlan {
|
|||||||
.buffers_for_project(&project)
|
.buffers_for_project(&project)
|
||||||
.iter()
|
.iter()
|
||||||
.choose(&mut self.rng)
|
.choose(&mut self.rng)
|
||||||
.cloned() else { continue };
|
.cloned()
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
let full_path = buffer
|
let full_path = buffer
|
||||||
.read_with(cx, |buffer, cx| buffer.file().unwrap().full_path(cx));
|
.read_with(cx, |buffer, cx| buffer.file().unwrap().full_path(cx));
|
||||||
@ -2026,7 +2038,10 @@ async fn simulate_client(
|
|||||||
client.app_state.languages.add(Arc::new(language));
|
client.app_state.languages.add(Arc::new(language));
|
||||||
|
|
||||||
while let Some(batch_id) = operation_rx.next().await {
|
while let Some(batch_id) = operation_rx.next().await {
|
||||||
let Some((operation, applied)) = plan.lock().next_client_operation(&client, batch_id, &cx) else { break };
|
let Some((operation, applied)) = plan.lock().next_client_operation(&client, batch_id, &cx)
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
};
|
||||||
applied.store(true, SeqCst);
|
applied.store(true, SeqCst);
|
||||||
match apply_client_operation(&client, operation, &mut cx).await {
|
match apply_client_operation(&client, operation, &mut cx).await {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
|
@ -272,8 +272,12 @@ impl FollowableItem for ChannelView {
|
|||||||
state: &mut Option<proto::view::Variant>,
|
state: &mut Option<proto::view::Variant>,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) -> Option<gpui::Task<anyhow::Result<ViewHandle<Self>>>> {
|
) -> Option<gpui::Task<anyhow::Result<ViewHandle<Self>>>> {
|
||||||
let Some(proto::view::Variant::ChannelView(_)) = state else { return None };
|
let Some(proto::view::Variant::ChannelView(_)) = state else {
|
||||||
let Some(proto::view::Variant::ChannelView(state)) = state.take() else { unreachable!() };
|
return None;
|
||||||
|
};
|
||||||
|
let Some(proto::view::Variant::ChannelView(state)) = state.take() else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
|
||||||
let open = ChannelView::open(state.channel_id, pane, workspace, cx);
|
let open = ChannelView::open(state.channel_id, pane, workspace, cx);
|
||||||
|
|
||||||
|
@ -152,12 +152,9 @@ impl View for ChannelModal {
|
|||||||
let theme = &theme::current(cx).collab_panel.tabbed_modal;
|
let theme = &theme::current(cx).collab_panel.tabbed_modal;
|
||||||
|
|
||||||
let mode = self.picker.read(cx).delegate().mode;
|
let mode = self.picker.read(cx).delegate().mode;
|
||||||
let Some(channel) = self
|
let Some(channel) = self.channel_store.read(cx).channel_for_id(self.channel_id) else {
|
||||||
.channel_store
|
return Empty::new().into_any();
|
||||||
.read(cx)
|
};
|
||||||
.channel_for_id(self.channel_id) else {
|
|
||||||
return Empty::new().into_any()
|
|
||||||
};
|
|
||||||
|
|
||||||
enum InviteMembers {}
|
enum InviteMembers {}
|
||||||
enum ManageMembers {}
|
enum ManageMembers {}
|
||||||
|
@ -6243,7 +6243,9 @@ impl Editor {
|
|||||||
) {
|
) {
|
||||||
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
s.move_offsets_with(|snapshot, selection| {
|
s.move_offsets_with(|snapshot, selection| {
|
||||||
let Some(enclosing_bracket_ranges) = snapshot.enclosing_bracket_ranges(selection.start..selection.end) else {
|
let Some(enclosing_bracket_ranges) =
|
||||||
|
snapshot.enclosing_bracket_ranges(selection.start..selection.end)
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -6255,7 +6257,8 @@ impl Editor {
|
|||||||
let close = close.to_inclusive();
|
let close = close.to_inclusive();
|
||||||
let length = close.end() - open.start;
|
let length = close.end() - open.start;
|
||||||
let inside = selection.start >= open.end && selection.end <= *close.start();
|
let inside = selection.start >= open.end && selection.end <= *close.start();
|
||||||
let in_bracket_range = open.to_inclusive().contains(&selection.head()) || close.contains(&selection.head());
|
let in_bracket_range = open.to_inclusive().contains(&selection.head())
|
||||||
|
|| close.contains(&selection.head());
|
||||||
|
|
||||||
// If best is next to a bracket and current isn't, skip
|
// If best is next to a bracket and current isn't, skip
|
||||||
if !in_bracket_range && best_in_bracket_range {
|
if !in_bracket_range && best_in_bracket_range {
|
||||||
@ -6270,19 +6273,21 @@ impl Editor {
|
|||||||
best_length = length;
|
best_length = length;
|
||||||
best_inside = inside;
|
best_inside = inside;
|
||||||
best_in_bracket_range = in_bracket_range;
|
best_in_bracket_range = in_bracket_range;
|
||||||
best_destination = Some(if close.contains(&selection.start) && close.contains(&selection.end) {
|
best_destination = Some(
|
||||||
if inside {
|
if close.contains(&selection.start) && close.contains(&selection.end) {
|
||||||
open.end
|
if inside {
|
||||||
|
open.end
|
||||||
|
} else {
|
||||||
|
open.start
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
open.start
|
if inside {
|
||||||
}
|
*close.start()
|
||||||
} else {
|
} else {
|
||||||
if inside {
|
*close.end()
|
||||||
*close.start()
|
}
|
||||||
} else {
|
},
|
||||||
*close.end()
|
);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(destination) = best_destination {
|
if let Some(destination) = best_destination {
|
||||||
@ -6526,7 +6531,9 @@ impl Editor {
|
|||||||
split: bool,
|
split: bool,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let Some(workspace) = self.workspace(cx) else { return };
|
let Some(workspace) = self.workspace(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
let buffer = self.buffer.read(cx);
|
let buffer = self.buffer.read(cx);
|
||||||
let head = self.selections.newest::<usize>(cx).head();
|
let head = self.selections.newest::<usize>(cx).head();
|
||||||
let (buffer, head) = if let Some(text_anchor) = buffer.text_anchor_for_position(head, cx) {
|
let (buffer, head) = if let Some(text_anchor) = buffer.text_anchor_for_position(head, cx) {
|
||||||
@ -6557,7 +6564,9 @@ impl Editor {
|
|||||||
split: bool,
|
split: bool,
|
||||||
cx: &mut ViewContext<Editor>,
|
cx: &mut ViewContext<Editor>,
|
||||||
) {
|
) {
|
||||||
let Some(workspace) = self.workspace(cx) else { return };
|
let Some(workspace) = self.workspace(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
let pane = workspace.read(cx).active_pane().clone();
|
let pane = workspace.read(cx).active_pane().clone();
|
||||||
// If there is one definition, just open it directly
|
// If there is one definition, just open it directly
|
||||||
if definitions.len() == 1 {
|
if definitions.len() == 1 {
|
||||||
@ -7639,10 +7648,9 @@ impl Editor {
|
|||||||
let search_range = display_snapshot.anchor_to_inlay_offset(search_range.start)
|
let search_range = display_snapshot.anchor_to_inlay_offset(search_range.start)
|
||||||
..display_snapshot.anchor_to_inlay_offset(search_range.end);
|
..display_snapshot.anchor_to_inlay_offset(search_range.end);
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
let Some((_, ranges)) = self.background_highlights
|
let Some((_, ranges)) = self.background_highlights.get(&TypeId::of::<T>()) else {
|
||||||
.get(&TypeId::of::<T>()) else {
|
return vec![];
|
||||||
return vec![];
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let start_ix = match ranges.binary_search_by(|probe| {
|
let start_ix = match ranges.binary_search_by(|probe| {
|
||||||
let cmp = document_to_inlay_range(probe, display_snapshot)
|
let cmp = document_to_inlay_range(probe, display_snapshot)
|
||||||
@ -7993,9 +8001,7 @@ impl Editor {
|
|||||||
suggestion_accepted: bool,
|
suggestion_accepted: bool,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) {
|
) {
|
||||||
let Some(project) = &self.project else {
|
let Some(project) = &self.project else { return };
|
||||||
return
|
|
||||||
};
|
|
||||||
|
|
||||||
// If None, we are either getting suggestions in a new, unsaved file, or in a file without an extension
|
// If None, we are either getting suggestions in a new, unsaved file, or in a file without an extension
|
||||||
let file_extension = self
|
let file_extension = self
|
||||||
@ -8024,9 +8030,7 @@ impl Editor {
|
|||||||
file_extension: Option<String>,
|
file_extension: Option<String>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) {
|
) {
|
||||||
let Some(project) = &self.project else {
|
let Some(project) = &self.project else { return };
|
||||||
return
|
|
||||||
};
|
|
||||||
|
|
||||||
// If None, we are in a file without an extension
|
// If None, we are in a file without an extension
|
||||||
let file = self
|
let file = self
|
||||||
@ -8127,7 +8131,9 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(lines) = serde_json::to_string_pretty(&lines).log_err() else { return; };
|
let Some(lines) = serde_json::to_string_pretty(&lines).log_err() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
cx.write_to_clipboard(ClipboardItem::new(lines));
|
cx.write_to_clipboard(ClipboardItem::new(lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +341,10 @@ impl InlayHintCache {
|
|||||||
shown_excerpt_hints_to_remove.retain(|(shown_anchor, shown_hint_id)| {
|
shown_excerpt_hints_to_remove.retain(|(shown_anchor, shown_hint_id)| {
|
||||||
let Some(buffer) = shown_anchor
|
let Some(buffer) = shown_anchor
|
||||||
.buffer_id
|
.buffer_id
|
||||||
.and_then(|buffer_id| multi_buffer.buffer(buffer_id)) else { return false };
|
.and_then(|buffer_id| multi_buffer.buffer(buffer_id))
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
let buffer_snapshot = buffer.read(cx).snapshot();
|
let buffer_snapshot = buffer.read(cx).snapshot();
|
||||||
loop {
|
loop {
|
||||||
match excerpt_cache.peek() {
|
match excerpt_cache.peek() {
|
||||||
@ -554,7 +557,10 @@ fn spawn_new_update_tasks(
|
|||||||
cx,
|
cx,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}) else { return; };
|
})
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
let query = ExcerptQuery {
|
let query = ExcerptQuery {
|
||||||
buffer_id,
|
buffer_id,
|
||||||
excerpt_id,
|
excerpt_id,
|
||||||
|
@ -55,8 +55,12 @@ impl FollowableItem for Editor {
|
|||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) -> Option<Task<Result<ViewHandle<Self>>>> {
|
) -> Option<Task<Result<ViewHandle<Self>>>> {
|
||||||
let project = workspace.read(cx).project().to_owned();
|
let project = workspace.read(cx).project().to_owned();
|
||||||
let Some(proto::view::Variant::Editor(_)) = state else { return None };
|
let Some(proto::view::Variant::Editor(_)) = state else {
|
||||||
let Some(proto::view::Variant::Editor(state)) = state.take() else { unreachable!() };
|
return None;
|
||||||
|
};
|
||||||
|
let Some(proto::view::Variant::Editor(state)) = state.take() else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
|
||||||
let client = project.read(cx).client();
|
let client = project.read(cx).client();
|
||||||
let replica_id = project.read(cx).replica_id();
|
let replica_id = project.read(cx).replica_id();
|
||||||
@ -341,10 +345,16 @@ async fn update_editor_from_message(
|
|||||||
|
|
||||||
let mut insertions = message.inserted_excerpts.into_iter().peekable();
|
let mut insertions = message.inserted_excerpts.into_iter().peekable();
|
||||||
while let Some(insertion) = insertions.next() {
|
while let Some(insertion) = insertions.next() {
|
||||||
let Some(excerpt) = insertion.excerpt else { continue };
|
let Some(excerpt) = insertion.excerpt else {
|
||||||
let Some(previous_excerpt_id) = insertion.previous_excerpt_id else { continue };
|
continue;
|
||||||
|
};
|
||||||
|
let Some(previous_excerpt_id) = insertion.previous_excerpt_id else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
let buffer_id = excerpt.buffer_id;
|
let buffer_id = excerpt.buffer_id;
|
||||||
let Some(buffer) = project.read(cx).buffer_for_id(buffer_id, cx) else { continue };
|
let Some(buffer) = project.read(cx).buffer_for_id(buffer_id, cx) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
let adjacent_excerpts = iter::from_fn(|| {
|
let adjacent_excerpts = iter::from_fn(|| {
|
||||||
let insertion = insertions.peek()?;
|
let insertion = insertions.peek()?;
|
||||||
|
@ -2756,7 +2756,9 @@ impl MultiBufferSnapshot {
|
|||||||
// Get the ranges of the innermost pair of brackets.
|
// Get the ranges of the innermost pair of brackets.
|
||||||
let mut result: Option<(Range<usize>, Range<usize>)> = None;
|
let mut result: Option<(Range<usize>, Range<usize>)> = None;
|
||||||
|
|
||||||
let Some(enclosing_bracket_ranges) = self.enclosing_bracket_ranges(range.clone()) else { return None; };
|
let Some(enclosing_bracket_ranges) = self.enclosing_bracket_ranges(range.clone()) else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
|
||||||
for (open, close) in enclosing_bracket_ranges {
|
for (open, close) in enclosing_bracket_ranges {
|
||||||
let len = close.end - open.start;
|
let len = close.end - open.start;
|
||||||
|
@ -67,7 +67,9 @@ impl KeymapContextPredicate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn eval(&self, contexts: &[KeymapContext]) -> bool {
|
pub fn eval(&self, contexts: &[KeymapContext]) -> bool {
|
||||||
let Some(context) = contexts.first() else { return false };
|
let Some(context) = contexts.first() else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
match self {
|
match self {
|
||||||
Self::Identifier(name) => (&context.set).contains(name.as_str()),
|
Self::Identifier(name) => (&context.set).contains(name.as_str()),
|
||||||
Self::Equal(left, right) => context
|
Self::Equal(left, right) => context
|
||||||
|
@ -2484,7 +2484,9 @@ impl BufferSnapshot {
|
|||||||
|
|
||||||
matches.advance();
|
matches.advance();
|
||||||
|
|
||||||
let Some((open, close)) = open.zip(close) else { continue };
|
let Some((open, close)) = open.zip(close) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
let bracket_range = open.start..=close.end;
|
let bracket_range = open.start..=close.end;
|
||||||
if !bracket_range.overlaps(&range) {
|
if !bracket_range.overlaps(&range) {
|
||||||
|
@ -310,7 +310,9 @@ impl SyntaxSnapshot {
|
|||||||
// Ignore edits that end before the start of this layer, and don't consider them
|
// Ignore edits that end before the start of this layer, and don't consider them
|
||||||
// for any subsequent layers at this same depth.
|
// for any subsequent layers at this same depth.
|
||||||
loop {
|
loop {
|
||||||
let Some((_, edit_range)) = edits.get(first_edit_ix_for_depth) else { continue 'outer };
|
let Some((_, edit_range)) = edits.get(first_edit_ix_for_depth) else {
|
||||||
|
continue 'outer;
|
||||||
|
};
|
||||||
if edit_range.end.cmp(&layer.range.start, text).is_le() {
|
if edit_range.end.cmp(&layer.range.start, text).is_le() {
|
||||||
first_edit_ix_for_depth += 1;
|
first_edit_ix_for_depth += 1;
|
||||||
} else {
|
} else {
|
||||||
@ -391,7 +393,9 @@ impl SyntaxSnapshot {
|
|||||||
.filter::<_, ()>(|summary| summary.contains_unknown_injections);
|
.filter::<_, ()>(|summary| summary.contains_unknown_injections);
|
||||||
cursor.next(text);
|
cursor.next(text);
|
||||||
while let Some(layer) = cursor.item() {
|
while let Some(layer) = cursor.item() {
|
||||||
let SyntaxLayerContent::Pending { language_name } = &layer.content else { unreachable!() };
|
let SyntaxLayerContent::Pending { language_name } = &layer.content else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
if registry
|
if registry
|
||||||
.language_for_name_or_extension(language_name)
|
.language_for_name_or_extension(language_name)
|
||||||
.now_or_never()
|
.now_or_never()
|
||||||
@ -533,7 +537,9 @@ impl SyntaxSnapshot {
|
|||||||
|
|
||||||
let content = match step.language {
|
let content = match step.language {
|
||||||
ParseStepLanguage::Loaded { language } => {
|
ParseStepLanguage::Loaded { language } => {
|
||||||
let Some(grammar) = language.grammar() else { continue };
|
let Some(grammar) = language.grammar() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
let tree;
|
let tree;
|
||||||
let changed_ranges;
|
let changed_ranges;
|
||||||
|
|
||||||
|
@ -932,8 +932,12 @@ fn check_interpolation(
|
|||||||
.zip(new_syntax_map.layers.iter())
|
.zip(new_syntax_map.layers.iter())
|
||||||
{
|
{
|
||||||
assert_eq!(old_layer.range, new_layer.range);
|
assert_eq!(old_layer.range, new_layer.range);
|
||||||
let Some(old_tree) = old_layer.content.tree() else { continue };
|
let Some(old_tree) = old_layer.content.tree() else {
|
||||||
let Some(new_tree) = new_layer.content.tree() else { continue };
|
continue;
|
||||||
|
};
|
||||||
|
let Some(new_tree) = new_layer.content.tree() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
let old_start_byte = old_layer.range.start.to_offset(old_buffer);
|
let old_start_byte = old_layer.range.start.to_offset(old_buffer);
|
||||||
let new_start_byte = new_layer.range.start.to_offset(new_buffer);
|
let new_start_byte = new_layer.range.start.to_offset(new_buffer);
|
||||||
let old_start_point = old_layer.range.start.to_point(old_buffer).to_ts_point();
|
let old_start_point = old_layer.range.start.to_point(old_buffer).to_ts_point();
|
||||||
|
@ -549,7 +549,9 @@ impl View for LspLogToolbarItemView {
|
|||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||||
let theme = theme::current(cx).clone();
|
let theme = theme::current(cx).clone();
|
||||||
let Some(log_view) = self.log_view.as_ref() else { return Empty::new().into_any() };
|
let Some(log_view) = self.log_view.as_ref() else {
|
||||||
|
return Empty::new().into_any();
|
||||||
|
};
|
||||||
let log_view = log_view.read(cx);
|
let log_view = log_view.read(cx);
|
||||||
let menu_rows = log_view.menu_items(cx).unwrap_or_default();
|
let menu_rows = log_view.menu_items(cx).unwrap_or_default();
|
||||||
|
|
||||||
|
@ -1655,7 +1655,11 @@ impl LspCommand for OnTypeFormatting {
|
|||||||
type ProtoRequest = proto::OnTypeFormatting;
|
type ProtoRequest = proto::OnTypeFormatting;
|
||||||
|
|
||||||
fn check_capabilities(&self, server_capabilities: &lsp::ServerCapabilities) -> bool {
|
fn check_capabilities(&self, server_capabilities: &lsp::ServerCapabilities) -> bool {
|
||||||
let Some(on_type_formatting_options) = &server_capabilities.document_on_type_formatting_provider else { return false };
|
let Some(on_type_formatting_options) =
|
||||||
|
&server_capabilities.document_on_type_formatting_provider
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
on_type_formatting_options
|
on_type_formatting_options
|
||||||
.first_trigger_character
|
.first_trigger_character
|
||||||
.contains(&self.trigger)
|
.contains(&self.trigger)
|
||||||
@ -1769,7 +1773,9 @@ impl LspCommand for OnTypeFormatting {
|
|||||||
_: ModelHandle<Buffer>,
|
_: ModelHandle<Buffer>,
|
||||||
_: AsyncAppContext,
|
_: AsyncAppContext,
|
||||||
) -> Result<Option<Transaction>> {
|
) -> Result<Option<Transaction>> {
|
||||||
let Some(transaction) = message.transaction else { return Ok(None) };
|
let Some(transaction) = message.transaction else {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
Ok(Some(language::proto::deserialize_transaction(transaction)?))
|
Ok(Some(language::proto::deserialize_transaction(transaction)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2238,7 +2244,9 @@ impl LspCommand for InlayHints {
|
|||||||
type ProtoRequest = proto::InlayHints;
|
type ProtoRequest = proto::InlayHints;
|
||||||
|
|
||||||
fn check_capabilities(&self, server_capabilities: &lsp::ServerCapabilities) -> bool {
|
fn check_capabilities(&self, server_capabilities: &lsp::ServerCapabilities) -> bool {
|
||||||
let Some(inlay_hint_provider) = &server_capabilities.inlay_hint_provider else { return false };
|
let Some(inlay_hint_provider) = &server_capabilities.inlay_hint_provider else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
match inlay_hint_provider {
|
match inlay_hint_provider {
|
||||||
lsp::OneOf::Left(enabled) => *enabled,
|
lsp::OneOf::Left(enabled) => *enabled,
|
||||||
lsp::OneOf::Right(inlay_hint_capabilities) => match inlay_hint_capabilities {
|
lsp::OneOf::Right(inlay_hint_capabilities) => match inlay_hint_capabilities {
|
||||||
|
@ -2317,9 +2317,10 @@ impl BackgroundScannerState {
|
|||||||
for changed_path in changed_paths {
|
for changed_path in changed_paths {
|
||||||
let Some(dot_git_dir) = changed_path
|
let Some(dot_git_dir) = changed_path
|
||||||
.ancestors()
|
.ancestors()
|
||||||
.find(|ancestor| ancestor.file_name() == Some(&*DOT_GIT)) else {
|
.find(|ancestor| ancestor.file_name() == Some(&*DOT_GIT))
|
||||||
continue;
|
else {
|
||||||
};
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
// Avoid processing the same repository multiple times, if multiple paths
|
// Avoid processing the same repository multiple times, if multiple paths
|
||||||
// within it have changed.
|
// within it have changed.
|
||||||
@ -2348,7 +2349,10 @@ impl BackgroundScannerState {
|
|||||||
let Some(work_dir) = self
|
let Some(work_dir) = self
|
||||||
.snapshot
|
.snapshot
|
||||||
.entry_for_id(entry_id)
|
.entry_for_id(entry_id)
|
||||||
.map(|entry| RepositoryWorkDirectory(entry.path.clone())) else { continue };
|
.map(|entry| RepositoryWorkDirectory(entry.path.clone()))
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
log::info!("reload git repository {:?}", dot_git_dir);
|
log::info!("reload git repository {:?}", dot_git_dir);
|
||||||
let repository = repository.repo_ptr.lock();
|
let repository = repository.repo_ptr.lock();
|
||||||
|
@ -40,7 +40,9 @@ impl View for QuickActionBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut gpui::ViewContext<'_, '_, Self>) -> gpui::AnyElement<Self> {
|
fn render(&mut self, cx: &mut gpui::ViewContext<'_, '_, Self>) -> gpui::AnyElement<Self> {
|
||||||
let Some(editor) = self.active_editor() else { return Empty::new().into_any(); };
|
let Some(editor) = self.active_editor() else {
|
||||||
|
return Empty::new().into_any();
|
||||||
|
};
|
||||||
|
|
||||||
let inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
|
let inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
|
||||||
let mut bar = Flex::row().with_child(render_quick_action_bar_button(
|
let mut bar = Flex::row().with_child(render_quick_action_bar_button(
|
||||||
|
@ -885,7 +885,9 @@ impl ProjectSearchView {
|
|||||||
if !dir_entry.is_dir() {
|
if !dir_entry.is_dir() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Some(filter_str) = dir_entry.path.to_str() else { return; };
|
let Some(filter_str) = dir_entry.path.to_str() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let model = cx.add_model(|cx| ProjectSearch::new(workspace.project().clone(), cx));
|
let model = cx.add_model(|cx| ProjectSearch::new(workspace.project().clone(), cx));
|
||||||
let search = cx.add_view(|cx| ProjectSearchView::new(model, cx));
|
let search = cx.add_view(|cx| ProjectSearchView::new(model, cx));
|
||||||
|
@ -57,7 +57,9 @@ pub fn init(
|
|||||||
|
|
||||||
cx.subscribe_global::<WorkspaceCreated, _>({
|
cx.subscribe_global::<WorkspaceCreated, _>({
|
||||||
move |event, cx| {
|
move |event, cx| {
|
||||||
let Some(semantic_index) = SemanticIndex::global(cx) else { return; };
|
let Some(semantic_index) = SemanticIndex::global(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
let workspace = &event.0;
|
let workspace = &event.0;
|
||||||
if let Some(workspace) = workspace.upgrade(cx) {
|
if let Some(workspace) = workspace.upgrade(cx) {
|
||||||
let project = workspace.read(cx).project().clone();
|
let project = workspace.read(cx).project().clone();
|
||||||
|
@ -63,20 +63,23 @@ impl KeymapFile {
|
|||||||
// string. But `RawValue` currently does not work inside of an untagged enum.
|
// string. But `RawValue` currently does not work inside of an untagged enum.
|
||||||
match action {
|
match action {
|
||||||
Value::Array(items) => {
|
Value::Array(items) => {
|
||||||
let Ok([name, data]): Result<[serde_json::Value; 2], _> = items.try_into() else {
|
let Ok([name, data]): Result<[serde_json::Value; 2], _> =
|
||||||
|
items.try_into()
|
||||||
|
else {
|
||||||
return Some(Err(anyhow!("Expected array of length 2")));
|
return Some(Err(anyhow!("Expected array of length 2")));
|
||||||
};
|
};
|
||||||
let serde_json::Value::String(name) = name else {
|
let serde_json::Value::String(name) = name else {
|
||||||
return Some(Err(anyhow!("Expected first item in array to be a string.")))
|
return Some(Err(anyhow!(
|
||||||
|
"Expected first item in array to be a string."
|
||||||
|
)));
|
||||||
};
|
};
|
||||||
cx.deserialize_action(
|
cx.deserialize_action(&name, Some(data))
|
||||||
&name,
|
}
|
||||||
Some(data),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
Value::String(name) => cx.deserialize_action(&name, None),
|
Value::String(name) => cx.deserialize_action(&name, None),
|
||||||
Value::Null => Ok(no_action()),
|
Value::Null => Ok(no_action()),
|
||||||
_ => return Some(Err(anyhow!("Expected two-element array, got {action:?}"))),
|
_ => {
|
||||||
|
return Some(Err(anyhow!("Expected two-element array, got {action:?}")))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
|
@ -107,20 +107,15 @@ impl PickerDelegate for BranchListDelegate {
|
|||||||
let delegate = view.delegate();
|
let delegate = view.delegate();
|
||||||
let project = delegate.workspace.read(cx).project().read(&cx);
|
let project = delegate.workspace.read(cx).project().read(&cx);
|
||||||
|
|
||||||
let Some(worktree) = project
|
let Some(worktree) = project.visible_worktrees(cx).next() else {
|
||||||
.visible_worktrees(cx)
|
|
||||||
.next()
|
|
||||||
else {
|
|
||||||
bail!("Cannot update branch list as there are no visible worktrees")
|
bail!("Cannot update branch list as there are no visible worktrees")
|
||||||
};
|
};
|
||||||
let mut cwd = worktree .read(cx)
|
let mut cwd = worktree.read(cx).abs_path().to_path_buf();
|
||||||
.abs_path()
|
|
||||||
.to_path_buf();
|
|
||||||
cwd.push(".git");
|
cwd.push(".git");
|
||||||
let Some(repo) = project.fs().open_repo(&cwd) else {bail!("Project does not have associated git repository.")};
|
let Some(repo) = project.fs().open_repo(&cwd) else {
|
||||||
let mut branches = repo
|
bail!("Project does not have associated git repository.")
|
||||||
.lock()
|
};
|
||||||
.branches()?;
|
let mut branches = repo.lock().branches()?;
|
||||||
const RECENT_BRANCHES_COUNT: usize = 10;
|
const RECENT_BRANCHES_COUNT: usize = 10;
|
||||||
if query.is_empty() && branches.len() > RECENT_BRANCHES_COUNT {
|
if query.is_empty() && branches.len() > RECENT_BRANCHES_COUNT {
|
||||||
// Truncate list of recent branches
|
// Truncate list of recent branches
|
||||||
@ -142,8 +137,13 @@ impl PickerDelegate for BranchListDelegate {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>())
|
.collect::<Vec<_>>())
|
||||||
})
|
})
|
||||||
.log_err() else { return; };
|
.log_err()
|
||||||
let Some(candidates) = candidates.log_err() else {return;};
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Some(candidates) = candidates.log_err() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
let matches = if query.is_empty() {
|
let matches = if query.is_empty() {
|
||||||
candidates
|
candidates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -184,7 +184,11 @@ impl PickerDelegate for BranchListDelegate {
|
|||||||
|
|
||||||
fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) {
|
fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) {
|
||||||
let current_pick = self.selected_index();
|
let current_pick = self.selected_index();
|
||||||
let Some(current_pick) = self.matches.get(current_pick).map(|pick| pick.string.clone()) else {
|
let Some(current_pick) = self
|
||||||
|
.matches
|
||||||
|
.get(current_pick)
|
||||||
|
.map(|pick| pick.string.clone())
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
cx.spawn(|picker, mut cx| async move {
|
cx.spawn(|picker, mut cx| async move {
|
||||||
|
@ -33,7 +33,7 @@ fn paste(_: &mut Workspace, action: &Paste, cx: &mut ViewContext<Workspace>) {
|
|||||||
editor.set_clip_at_line_ends(false, cx);
|
editor.set_clip_at_line_ends(false, cx);
|
||||||
|
|
||||||
let Some(item) = cx.read_from_clipboard() else {
|
let Some(item) = cx.read_from_clipboard() else {
|
||||||
return
|
return;
|
||||||
};
|
};
|
||||||
let clipboard_text = Cow::Borrowed(item.text());
|
let clipboard_text = Cow::Borrowed(item.text());
|
||||||
if clipboard_text.is_empty() {
|
if clipboard_text.is_empty() {
|
||||||
|
@ -77,7 +77,10 @@ pub fn visual_motion(motion: Motion, times: Option<usize>, cx: &mut WindowContex
|
|||||||
}
|
}
|
||||||
|
|
||||||
let Some((new_head, goal)) =
|
let Some((new_head, goal)) =
|
||||||
motion.move_point(map, current_head, selection.goal, times) else { return };
|
motion.move_point(map, current_head, selection.goal, times)
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
selection.set_head(new_head, goal);
|
selection.set_head(new_head, goal);
|
||||||
|
|
||||||
@ -132,7 +135,7 @@ pub fn visual_block_motion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let Some((new_head, _)) = move_selection(&map, head, goal) else {
|
let Some((new_head, _)) = move_selection(&map, head, goal) else {
|
||||||
return
|
return;
|
||||||
};
|
};
|
||||||
head = new_head;
|
head = new_head;
|
||||||
|
|
||||||
|
@ -742,8 +742,8 @@ mod element {
|
|||||||
|
|
||||||
while proposed_current_pixel_change.abs() > 0. {
|
while proposed_current_pixel_change.abs() > 0. {
|
||||||
let Some(current_ix) = successors.next() else {
|
let Some(current_ix) = successors.next() else {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
let next_target_size = f32::max(
|
let next_target_size = f32::max(
|
||||||
size(current_ix + 1, flexes.as_slice()) - proposed_current_pixel_change,
|
size(current_ix + 1, flexes.as_slice()) - proposed_current_pixel_change,
|
||||||
|
@ -2314,8 +2314,12 @@ impl Workspace {
|
|||||||
item_id_to_move: usize,
|
item_id_to_move: usize,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let Some(pane_to_split) = pane_to_split.upgrade(cx) else { return; };
|
let Some(pane_to_split) = pane_to_split.upgrade(cx) else {
|
||||||
let Some(from) = from.upgrade(cx) else { return; };
|
return;
|
||||||
|
};
|
||||||
|
let Some(from) = from.upgrade(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let new_pane = self.add_pane(cx);
|
let new_pane = self.add_pane(cx);
|
||||||
self.move_item(from.clone(), new_pane.clone(), item_id_to_move, 0, cx);
|
self.move_item(from.clone(), new_pane.clone(), item_id_to_move, 0, cx);
|
||||||
|
@ -89,7 +89,9 @@ impl LspAdapter for PythonLspAdapter {
|
|||||||
// to allow our own fuzzy score to be used to break ties.
|
// to allow our own fuzzy score to be used to break ties.
|
||||||
//
|
//
|
||||||
// see https://github.com/microsoft/pyright/blob/95ef4e103b9b2f129c9320427e51b73ea7cf78bd/packages/pyright-internal/src/languageService/completionProvider.ts#LL2873
|
// see https://github.com/microsoft/pyright/blob/95ef4e103b9b2f129c9320427e51b73ea7cf78bd/packages/pyright-internal/src/languageService/completionProvider.ts#LL2873
|
||||||
let Some(sort_text) = &mut item.sort_text else { return };
|
let Some(sort_text) = &mut item.sort_text else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
let mut parts = sort_text.split('.');
|
let mut parts = sort_text.split('.');
|
||||||
let Some(first) = parts.next() else { return };
|
let Some(first) = parts.next() else { return };
|
||||||
let Some(second) = parts.next() else { return };
|
let Some(second) = parts.next() else { return };
|
||||||
|
Loading…
Reference in New Issue
Block a user