Fix a bunch of other low-hanging style lints (#36498)

- **Fix a bunch of low hanging style lints like unnecessary-return**
- **Fix single worktree violation**
- **And the rest**

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-08-19 21:26:17 +02:00 committed by GitHub
parent df9c2aefb1
commit 05fc0c432c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
239 changed files with 854 additions and 1015 deletions

View file

@ -821,6 +821,7 @@ single_range_in_vec_init = "allow"
style = { level = "allow", priority = -1 }
# Temporary list of style lints that we've fixed so far.
comparison_to_empty = "warn"
iter_cloned_collect = "warn"
iter_next_slice = "warn"
iter_nth = "warn"
@ -831,8 +832,13 @@ question_mark = { level = "deny" }
redundant_closure = { level = "deny" }
declare_interior_mutable_const = { level = "deny" }
collapsible_if = { level = "warn"}
collapsible_else_if = { level = "warn" }
needless_borrow = { level = "warn"}
needless_return = { level = "warn" }
unnecessary_mut_passed = {level = "warn"}
unnecessary_map_or = { level = "warn" }
unused_unit = "warn"
# Individual rules that have violations in the codebase:
type_complexity = "allow"
# We often return trait objects from `new` functions.

View file

@ -49,7 +49,7 @@ impl UserMessage {
if self
.checkpoint
.as_ref()
.map_or(false, |checkpoint| checkpoint.show)
.is_some_and(|checkpoint| checkpoint.show)
{
writeln!(markdown, "## User (checkpoint)").unwrap();
} else {

View file

@ -79,12 +79,10 @@ impl MentionUri {
} else {
Ok(Self::Selection { path, line_range })
}
} else if input.ends_with("/") {
Ok(Self::Directory { abs_path: path })
} else {
if input.ends_with("/") {
Ok(Self::Directory { abs_path: path })
} else {
Ok(Self::File { abs_path: path })
}
Ok(Self::File { abs_path: path })
}
}
"zed" => {

View file

@ -116,7 +116,7 @@ impl ActionLog {
} else if buffer
.read(cx)
.file()
.map_or(false, |file| file.disk_state().exists())
.is_some_and(|file| file.disk_state().exists())
{
TrackedBufferStatus::Created {
existing_file_content: Some(buffer.read(cx).as_rope().clone()),
@ -215,7 +215,7 @@ impl ActionLog {
if buffer
.read(cx)
.file()
.map_or(false, |file| file.disk_state() == DiskState::Deleted)
.is_some_and(|file| file.disk_state() == DiskState::Deleted)
{
// If the buffer had been edited by a tool, but it got
// deleted externally, we want to stop tracking it.
@ -227,7 +227,7 @@ impl ActionLog {
if buffer
.read(cx)
.file()
.map_or(false, |file| file.disk_state() != DiskState::Deleted)
.is_some_and(|file| file.disk_state() != DiskState::Deleted)
{
// If the buffer had been deleted by a tool, but it got
// resurrected externally, we want to clear the edits we
@ -811,7 +811,7 @@ impl ActionLog {
tracked.version != buffer.version
&& buffer
.file()
.map_or(false, |file| file.disk_state() != DiskState::Deleted)
.is_some_and(|file| file.disk_state() != DiskState::Deleted)
})
.map(|(buffer, _)| buffer)
}
@ -847,7 +847,7 @@ fn apply_non_conflicting_edits(
conflict = true;
if new_edits
.peek()
.map_or(false, |next_edit| next_edit.old.overlaps(&old_edit.new))
.is_some_and(|next_edit| next_edit.old.overlaps(&old_edit.new))
{
new_edit = new_edits.next().unwrap();
} else {

View file

@ -90,7 +90,7 @@ impl AgentProfile {
return false;
};
return Self::is_enabled(settings, source, tool_name);
Self::is_enabled(settings, source, tool_name)
}
fn is_enabled(settings: &AgentProfileSettings, source: ToolSource, name: String) -> bool {

View file

@ -42,7 +42,7 @@ use std::{
use util::ResultExt as _;
pub static ZED_STATELESS: std::sync::LazyLock<bool> =
std::sync::LazyLock::new(|| std::env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty()));
std::sync::LazyLock::new(|| std::env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty()));
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum DataType {

View file

@ -275,7 +275,7 @@ impl ToolUseState {
pub fn message_has_tool_results(&self, assistant_message_id: MessageId) -> bool {
self.tool_uses_by_assistant_message
.get(&assistant_message_id)
.map_or(false, |results| !results.is_empty())
.is_some_and(|results| !results.is_empty())
}
pub fn tool_result(

View file

@ -184,7 +184,7 @@ impl DbThread {
}
pub static ZED_STATELESS: std::sync::LazyLock<bool> =
std::sync::LazyLock::new(|| std::env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty()));
std::sync::LazyLock::new(|| std::env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty()));
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum DataType {

View file

@ -742,7 +742,7 @@ async fn expect_tool_call(events: &mut UnboundedReceiver<Result<ThreadEvent>>) -
.expect("no tool call authorization event received")
.unwrap();
match event {
ThreadEvent::ToolCall(tool_call) => return tool_call,
ThreadEvent::ToolCall(tool_call) => tool_call,
event => {
panic!("Unexpected event {event:?}");
}
@ -758,9 +758,7 @@ async fn expect_tool_call_update_fields(
.expect("no tool call authorization event received")
.unwrap();
match event {
ThreadEvent::ToolCallUpdate(acp_thread::ToolCallUpdate::UpdateFields(update)) => {
return update;
}
ThreadEvent::ToolCallUpdate(acp_thread::ToolCallUpdate::UpdateFields(update)) => update,
event => {
panic!("Unexpected event {event:?}");
}

View file

@ -1356,7 +1356,7 @@ impl Thread {
// Ensure the last message ends in the current tool use
let last_message = self.pending_message();
let push_new_tool_use = last_message.content.last_mut().map_or(true, |content| {
let push_new_tool_use = last_message.content.last_mut().is_none_or(|content| {
if let AgentMessageContent::ToolUse(last_tool_use) = content {
if last_tool_use.id == tool_use.id {
*last_tool_use = tool_use.clone();
@ -1408,7 +1408,7 @@ impl Thread {
status: Some(acp::ToolCallStatus::InProgress),
..Default::default()
});
let supports_images = self.model().map_or(false, |model| model.supports_images());
let supports_images = self.model().is_some_and(|model| model.supports_images());
let tool_result = tool.run(tool_use.input, tool_event_stream, cx);
log::info!("Running tool {}", tool_use.name);
Some(cx.foreground_executor().spawn(async move {

View file

@ -175,7 +175,7 @@ impl AgentTool for ReadFileTool {
buffer
.file()
.as_ref()
.map_or(true, |file| !file.disk_state().exists())
.is_none_or(|file| !file.disk_state().exists())
})? {
anyhow::bail!("{file_path} not found");
}

View file

@ -271,7 +271,7 @@ fn working_dir(
let project = project.read(cx);
let cd = &input.cd;
if cd == "." || cd == "" {
if cd == "." || cd.is_empty() {
// Accept "." or "" as meaning "the one worktree" if we only have one worktree.
let mut worktrees = project.worktrees(cx);
@ -296,10 +296,8 @@ fn working_dir(
{
return Ok(Some(input_path.into()));
}
} else {
if let Some(worktree) = project.worktree_for_root_name(cd, cx) {
return Ok(Some(worktree.read(cx).abs_path().to_path_buf()));
}
} else if let Some(worktree) = project.worktree_for_root_name(cd, cx) {
return Ok(Some(worktree.read(cx).abs_path().to_path_buf()));
}
anyhow::bail!("`cd` directory {cd:?} was not in any of the project's worktrees.");

View file

@ -104,7 +104,7 @@ impl AgentServerCommand {
cx: &mut AsyncApp,
) -> Option<Self> {
if let Some(agent_settings) = settings {
return Some(Self {
Some(Self {
path: agent_settings.command.path,
args: agent_settings
.command
@ -113,7 +113,7 @@ impl AgentServerCommand {
.chain(extra_args.iter().map(|arg| arg.to_string()))
.collect(),
env: agent_settings.command.env,
});
})
} else {
match find_bin_in_path(path_bin_name, project, cx).await {
Some(path) => Some(Self {

View file

@ -471,7 +471,7 @@ pub fn get_zed_path() -> PathBuf {
while zed_path
.file_name()
.map_or(true, |name| name.to_string_lossy() != "debug")
.is_none_or(|name| name.to_string_lossy() != "debug")
{
if !zed_path.pop() {
panic!("Could not find target directory");

View file

@ -58,7 +58,7 @@ impl AgentProfileSettings {
|| self
.context_servers
.get(server_id)
.map_or(false, |preset| preset.tools.get(tool_name) == Some(&true))
.is_some_and(|preset| preset.tools.get(tool_name) == Some(&true))
}
}

View file

@ -797,7 +797,7 @@ impl MentionCompletion {
&& line
.chars()
.nth(last_mention_start - 1)
.map_or(false, |c| !c.is_whitespace())
.is_some_and(|c| !c.is_whitespace())
{
return None;
}

View file

@ -1552,14 +1552,14 @@ impl SemanticsProvider for SlashCommandSemanticsProvider {
return None;
}
let range = snapshot.anchor_after(start)..snapshot.anchor_after(end);
return Some(Task::ready(vec![project::Hover {
Some(Task::ready(vec![project::Hover {
contents: vec![project::HoverBlock {
text: "Slash commands are not supported".into(),
kind: project::HoverBlockKind::PlainText,
}],
range: Some(range),
language: None,
}]));
}]))
}
fn inline_values(

View file

@ -102,7 +102,7 @@ impl ProfileProvider for Entity<agent2::Thread> {
fn profiles_supported(&self, cx: &App) -> bool {
self.read(cx)
.model()
.map_or(false, |model| model.supports_tools())
.is_some_and(|model| model.supports_tools())
}
}
@ -2843,7 +2843,7 @@ impl AcpThreadView {
if thread
.model()
.map_or(true, |model| !model.supports_burn_mode())
.is_none_or(|model| !model.supports_burn_mode())
{
return None;
}
@ -2875,9 +2875,9 @@ impl AcpThreadView {
fn render_send_button(&self, cx: &mut Context<Self>) -> AnyElement {
let is_editor_empty = self.message_editor.read(cx).is_empty(cx);
let is_generating = self.thread().map_or(false, |thread| {
thread.read(cx).status() != ThreadStatus::Idle
});
let is_generating = self
.thread()
.is_some_and(|thread| thread.read(cx).status() != ThreadStatus::Idle);
if is_generating && is_editor_empty {
IconButton::new("stop-generation", IconName::Stop)
@ -3455,18 +3455,16 @@ impl AcpThreadView {
} else {
format!("Retrying. Next attempt in {next_attempt_in_secs} seconds.")
}
} else if next_attempt_in_secs == 1 {
format!(
"Retrying. Next attempt in 1 second (Attempt {} of {}).",
state.attempt, state.max_attempts,
)
} else {
if next_attempt_in_secs == 1 {
format!(
"Retrying. Next attempt in 1 second (Attempt {} of {}).",
state.attempt, state.max_attempts,
)
} else {
format!(
"Retrying. Next attempt in {next_attempt_in_secs} seconds (Attempt {} of {}).",
state.attempt, state.max_attempts,
)
}
format!(
"Retrying. Next attempt in {next_attempt_in_secs} seconds (Attempt {} of {}).",
state.attempt, state.max_attempts,
)
};
Some(
@ -3552,7 +3550,7 @@ impl AcpThreadView {
let supports_burn_mode = thread
.read(cx)
.model()
.map_or(false, |model| model.supports_burn_mode());
.is_some_and(|model| model.supports_burn_mode());
let focus_handle = self.focus_handle(cx);

View file

@ -2246,9 +2246,7 @@ impl ActiveThread {
let after_editing_message = self
.editing_message
.as_ref()
.map_or(false, |(editing_message_id, _)| {
message_id > *editing_message_id
});
.is_some_and(|(editing_message_id, _)| message_id > *editing_message_id);
let backdrop = div()
.id(("backdrop", ix))

View file

@ -96,7 +96,7 @@ impl AgentConfiguration {
let mut expanded_provider_configurations = HashMap::default();
if LanguageModelRegistry::read_global(cx)
.provider(&ZED_CLOUD_PROVIDER_ID)
.map_or(false, |cloud_provider| cloud_provider.must_accept_terms(cx))
.is_some_and(|cloud_provider| cloud_provider.must_accept_terms(cx))
{
expanded_provider_configurations.insert(ZED_CLOUD_PROVIDER_ID, true);
}

View file

@ -285,7 +285,7 @@ impl AgentDiffPane {
&& buffer
.read(cx)
.file()
.map_or(false, |file| file.disk_state() == DiskState::Deleted)
.is_some_and(|file| file.disk_state() == DiskState::Deleted)
{
editor.fold_buffer(snapshot.text.remote_id(), cx)
}
@ -1063,7 +1063,7 @@ impl ToolbarItemView for AgentDiffToolbar {
}
self.active_item = None;
return self.location(cx);
self.location(cx)
}
fn pane_focus_update(
@ -1509,7 +1509,7 @@ impl AgentDiff {
.read(cx)
.entries()
.last()
.map_or(false, |entry| entry.diffs().next().is_some())
.is_some_and(|entry| entry.diffs().next().is_some())
{
self.update_reviewing_editors(workspace, window, cx);
}
@ -1519,7 +1519,7 @@ impl AgentDiff {
.read(cx)
.entries()
.get(*ix)
.map_or(false, |entry| entry.diffs().next().is_some())
.is_some_and(|entry| entry.diffs().next().is_some())
{
self.update_reviewing_editors(workspace, window, cx);
}
@ -1709,7 +1709,7 @@ impl AgentDiff {
.read_with(cx, |editor, _cx| editor.workspace())
.ok()
.flatten()
.map_or(false, |editor_workspace| {
.is_some_and(|editor_workspace| {
editor_workspace.entity_id() == workspace.entity_id()
});
@ -1868,7 +1868,7 @@ impl AgentDiff {
}
}
return Some(Task::ready(Ok(())));
Some(Task::ready(Ok(())))
}
}

View file

@ -1463,7 +1463,7 @@ impl AgentPanel {
AssistantConfigurationEvent::NewThread(provider) => {
if LanguageModelRegistry::read_global(cx)
.default_model()
.map_or(true, |model| model.provider.id() != provider.id())
.is_none_or(|model| model.provider.id() != provider.id())
&& let Some(model) = provider.default_model(cx)
{
update_settings_file::<AgentSettings>(
@ -2708,9 +2708,7 @@ impl AgentPanel {
}
ActiveView::ExternalAgentThread { .. }
| ActiveView::History
| ActiveView::Configuration => {
return None;
}
| ActiveView::Configuration => None,
}
}
@ -2726,7 +2724,7 @@ impl AgentPanel {
.thread()
.read(cx)
.configured_model()
.map_or(false, |model| {
.is_some_and(|model| {
model.provider.id() != language_model::ZED_CLOUD_PROVIDER_ID
})
{
@ -2737,7 +2735,7 @@ impl AgentPanel {
if LanguageModelRegistry::global(cx)
.read(cx)
.default_model()
.map_or(false, |model| {
.is_some_and(|model| {
model.provider.id() != language_model::ZED_CLOUD_PROVIDER_ID
})
{
@ -3051,9 +3049,7 @@ impl AgentPanel {
let zed_provider_configured = AgentSettings::get_global(cx)
.default_model
.as_ref()
.map_or(false, |selection| {
selection.provider.0.as_str() == "zed.dev"
});
.is_some_and(|selection| selection.provider.0.as_str() == "zed.dev");
let callout = if zed_provider_configured {
Callout::new()

View file

@ -610,9 +610,7 @@ pub(crate) fn available_context_picker_entries(
.read(cx)
.active_item(cx)
.and_then(|item| item.downcast::<Editor>())
.map_or(false, |editor| {
editor.update(cx, |editor, cx| editor.has_non_empty_selection(cx))
});
.is_some_and(|editor| editor.update(cx, |editor, cx| editor.has_non_empty_selection(cx)));
if has_selection {
entries.push(ContextPickerEntry::Action(
ContextPickerAction::AddSelections,
@ -680,7 +678,7 @@ pub(crate) fn recent_context_picker_entries(
.filter(|(_, abs_path)| {
abs_path
.as_ref()
.map_or(true, |path| !exclude_paths.contains(path.as_path()))
.is_none_or(|path| !exclude_paths.contains(path.as_path()))
})
.take(4)
.filter_map(|(project_path, _)| {

View file

@ -1020,7 +1020,7 @@ impl MentionCompletion {
&& line
.chars()
.nth(last_mention_start - 1)
.map_or(false, |c| !c.is_whitespace())
.is_some_and(|c| !c.is_whitespace())
{
return None;
}

View file

@ -226,9 +226,10 @@ impl PickerDelegate for FetchContextPickerDelegate {
_window: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> Option<Self::ListItem> {
let added = self.context_store.upgrade().map_or(false, |context_store| {
context_store.read(cx).includes_url(&self.url)
});
let added = self
.context_store
.upgrade()
.is_some_and(|context_store| context_store.read(cx).includes_url(&self.url));
Some(
ListItem::new(ix)

View file

@ -239,9 +239,7 @@ pub(crate) fn search_files(
PathMatchCandidateSet {
snapshot: worktree.snapshot(),
include_ignored: worktree
.root_entry()
.map_or(false, |entry| entry.is_ignored),
include_ignored: worktree.root_entry().is_some_and(|entry| entry.is_ignored),
include_root_name: true,
candidates: project::Candidates::Entries,
}

View file

@ -159,7 +159,7 @@ pub fn render_thread_context_entry(
context_store: WeakEntity<ContextStore>,
cx: &mut App,
) -> Div {
let added = context_store.upgrade().map_or(false, |context_store| {
let added = context_store.upgrade().is_some_and(|context_store| {
context_store
.read(cx)
.includes_user_rules(user_rules.prompt_id)

View file

@ -294,7 +294,7 @@ pub(crate) fn search_symbols(
.partition(|candidate| {
project
.entry_for_path(&symbols[candidate.id].path, cx)
.map_or(false, |e| !e.is_ignored)
.is_some_and(|e| !e.is_ignored)
})
})
.log_err()

View file

@ -236,12 +236,10 @@ pub fn render_thread_context_entry(
let is_added = match entry {
ThreadContextEntry::Thread { id, .. } => context_store
.upgrade()
.map_or(false, |ctx_store| ctx_store.read(cx).includes_thread(id)),
ThreadContextEntry::Context { path, .. } => {
context_store.upgrade().map_or(false, |ctx_store| {
ctx_store.read(cx).includes_text_thread(path)
})
}
.is_some_and(|ctx_store| ctx_store.read(cx).includes_thread(id)),
ThreadContextEntry::Context { path, .. } => context_store
.upgrade()
.is_some_and(|ctx_store| ctx_store.read(cx).includes_text_thread(path)),
};
h_flex()

View file

@ -1120,7 +1120,7 @@ impl InlineAssistant {
if editor_assists
.scroll_lock
.as_ref()
.map_or(false, |lock| lock.assist_id == assist_id)
.is_some_and(|lock| lock.assist_id == assist_id)
{
editor_assists.scroll_lock = None;
}

View file

@ -345,7 +345,7 @@ impl<T: 'static> PromptEditor<T> {
let prompt = self.editor.read(cx).text(cx);
if self
.prompt_history_ix
.map_or(true, |ix| self.prompt_history[ix] != prompt)
.is_none_or(|ix| self.prompt_history[ix] != prompt)
{
self.prompt_history_ix.take();
self.pending_prompt = prompt;

View file

@ -156,7 +156,7 @@ impl ProfileProvider for Entity<Thread> {
fn profiles_supported(&self, cx: &App) -> bool {
self.read(cx)
.configured_model()
.map_or(false, |model| model.model.supports_tools())
.is_some_and(|model| model.model.supports_tools())
}
fn profile_id(&self, cx: &App) -> AgentProfileId {
@ -1289,7 +1289,7 @@ impl MessageEditor {
self.thread
.read(cx)
.configured_model()
.map_or(false, |model| model.provider.id() == ZED_CLOUD_PROVIDER_ID)
.is_some_and(|model| model.provider.id() == ZED_CLOUD_PROVIDER_ID)
}
fn render_usage_callout(&self, line_height: Pixels, cx: &mut Context<Self>) -> Option<Div> {
@ -1442,7 +1442,7 @@ impl MessageEditor {
let message_text = editor.read(cx).text(cx);
if message_text.is_empty()
&& loaded_context.map_or(true, |loaded_context| loaded_context.is_empty())
&& loaded_context.is_none_or(|loaded_context| loaded_context.is_empty())
{
return None;
}

View file

@ -140,12 +140,10 @@ impl PickerDelegate for SlashCommandDelegate {
);
ret.push(index - 1);
}
} else {
if let SlashCommandEntry::Advert { .. } = command {
previous_is_advert = true;
if index != 0 {
ret.push(index - 1);
}
} else if let SlashCommandEntry::Advert { .. } = command {
previous_is_advert = true;
if index != 0 {
ret.push(index - 1);
}
}
}

View file

@ -373,7 +373,7 @@ impl TextThreadEditor {
.map(|default| default.provider);
if provider
.as_ref()
.map_or(false, |provider| provider.must_accept_terms(cx))
.is_some_and(|provider| provider.must_accept_terms(cx))
{
self.show_accept_terms = true;
cx.notify();
@ -457,7 +457,7 @@ impl TextThreadEditor {
|| snapshot
.chars_at(newest_cursor)
.next()
.map_or(false, |ch| ch != '\n')
.is_some_and(|ch| ch != '\n')
{
editor.move_to_end_of_line(
&MoveToEndOfLine {

View file

@ -177,11 +177,11 @@ impl AskPassSession {
_ = askpass_opened_rx.fuse() => {
// Note: this await can only resolve after we are dropped.
askpass_kill_master_rx.await.ok();
return AskPassResult::CancelledByUser
AskPassResult::CancelledByUser
}
_ = futures::FutureExt::fuse(smol::Timer::after(connection_timeout)) => {
return AskPassResult::Timedout
AskPassResult::Timedout
}
}
}
@ -215,7 +215,7 @@ pub fn main(socket: &str) {
}
#[cfg(target_os = "windows")]
while buffer.last().map_or(false, |&b| b == b'\n' || b == b'\r') {
while buffer.last().is_some_and(|&b| b == b'\n' || b == b'\r') {
buffer.pop();
}
if buffer.last() != Some(&b'\0') {

View file

@ -1023,9 +1023,11 @@ impl AssistantContext {
summary: new_summary,
..
} => {
if self.summary.timestamp().map_or(true, |current_timestamp| {
new_summary.timestamp > current_timestamp
}) {
if self
.summary
.timestamp()
.is_none_or(|current_timestamp| new_summary.timestamp > current_timestamp)
{
self.summary = ContextSummary::Content(new_summary);
summary_generated = true;
}
@ -1339,7 +1341,7 @@ impl AssistantContext {
let is_invalid = self
.messages_metadata
.get(&message_id)
.map_or(true, |metadata| {
.is_none_or(|metadata| {
!metadata.is_cache_valid(&buffer, &message.offset_range)
|| *encountered_invalid
});
@ -1860,7 +1862,7 @@ impl AssistantContext {
{
let newline_offset = insert_position.saturating_sub(1);
if buffer.contains_str_at(newline_offset, "\n")
&& last_section_range.map_or(true, |last_section_range| {
&& last_section_range.is_none_or(|last_section_range| {
!last_section_range
.to_offset(buffer)
.contains(&newline_offset)
@ -2313,10 +2315,7 @@ impl AssistantContext {
let mut request_message = LanguageModelRequestMessage {
role: message.role,
content: Vec::new(),
cache: message
.cache
.as_ref()
.map_or(false, |cache| cache.is_anchor),
cache: message.cache.as_ref().is_some_and(|cache| cache.is_anchor),
};
while let Some(content) = contents.peek() {
@ -2797,7 +2796,7 @@ impl AssistantContext {
let mut current_message = messages.next();
while let Some(offset) = offsets.next() {
// Locate the message that contains the offset.
while current_message.as_ref().map_or(false, |message| {
while current_message.as_ref().is_some_and(|message| {
!message.offset_range.contains(&offset) && messages.peek().is_some()
}) {
current_message = messages.next();
@ -2807,7 +2806,7 @@ impl AssistantContext {
};
// Skip offsets that are in the same message.
while offsets.peek().map_or(false, |offset| {
while offsets.peek().is_some_and(|offset| {
message.offset_range.contains(offset) || messages.peek().is_none()
}) {
offsets.next();

View file

@ -1055,7 +1055,7 @@ fn test_mark_cache_anchors(cx: &mut App) {
assert_eq!(
messages_cache(&context, cx)
.iter()
.filter(|(_, cache)| cache.as_ref().map_or(false, |cache| cache.is_anchor))
.filter(|(_, cache)| cache.as_ref().is_some_and(|cache| cache.is_anchor))
.count(),
0,
"Empty messages should not have any cache anchors."
@ -1083,7 +1083,7 @@ fn test_mark_cache_anchors(cx: &mut App) {
assert_eq!(
messages_cache(&context, cx)
.iter()
.filter(|(_, cache)| cache.as_ref().map_or(false, |cache| cache.is_anchor))
.filter(|(_, cache)| cache.as_ref().is_some_and(|cache| cache.is_anchor))
.count(),
0,
"Messages should not be marked for cache before going over the token minimum."
@ -1098,7 +1098,7 @@ fn test_mark_cache_anchors(cx: &mut App) {
assert_eq!(
messages_cache(&context, cx)
.iter()
.map(|(_, cache)| cache.as_ref().map_or(false, |cache| cache.is_anchor))
.map(|(_, cache)| cache.as_ref().is_some_and(|cache| cache.is_anchor))
.collect::<Vec<bool>>(),
vec![true, true, false],
"Last message should not be an anchor on speculative request."
@ -1116,7 +1116,7 @@ fn test_mark_cache_anchors(cx: &mut App) {
assert_eq!(
messages_cache(&context, cx)
.iter()
.map(|(_, cache)| cache.as_ref().map_or(false, |cache| cache.is_anchor))
.map(|(_, cache)| cache.as_ref().is_some_and(|cache| cache.is_anchor))
.collect::<Vec<bool>>(),
vec![false, true, true, false],
"Most recent message should also be cached if not a speculative request."

View file

@ -789,7 +789,7 @@ impl ContextStore {
let fs = self.fs.clone();
cx.spawn(async move |this, cx| {
pub static ZED_STATELESS: LazyLock<bool> =
LazyLock::new(|| std::env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty()));
LazyLock::new(|| std::env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty()));
if *ZED_STATELESS {
return Ok(());
}

View file

@ -62,9 +62,10 @@ impl SlashCommand for ContextServerSlashCommand {
}
fn requires_argument(&self) -> bool {
self.prompt.arguments.as_ref().map_or(false, |args| {
args.iter().any(|arg| arg.required == Some(true))
})
self.prompt
.arguments
.as_ref()
.is_some_and(|args| args.iter().any(|arg| arg.required == Some(true)))
}
fn complete_argument(

View file

@ -61,7 +61,7 @@ impl DiagnosticsSlashCommand {
snapshot: worktree.snapshot(),
include_ignored: worktree
.root_entry()
.map_or(false, |entry| entry.is_ignored),
.is_some_and(|entry| entry.is_ignored),
include_root_name: true,
candidates: project::Candidates::Entries,
}

View file

@ -92,7 +92,7 @@ impl FileSlashCommand {
snapshot: worktree.snapshot(),
include_ignored: worktree
.root_entry()
.map_or(false, |entry| entry.is_ignored),
.is_some_and(|entry| entry.is_ignored),
include_root_name: true,
candidates: project::Candidates::Entries,
}
@ -536,7 +536,7 @@ mod custom_path_matcher {
let path_str = path.to_string_lossy();
let separator = std::path::MAIN_SEPARATOR_STR;
if path_str.ends_with(separator) {
return false;
false
} else {
self.glob.is_match(path_str.to_string() + separator)
}

View file

@ -86,7 +86,7 @@ fn register_web_search_tool(registry: &Entity<LanguageModelRegistry>, cx: &mut A
let using_zed_provider = registry
.read(cx)
.default_model()
.map_or(false, |default| default.is_provided_by_zed());
.is_some_and(|default| default.is_provided_by_zed());
if using_zed_provider {
ToolRegistry::global(cx).register_tool(WebSearchTool);
} else {

View file

@ -1586,7 +1586,7 @@ impl EditAgentTest {
let has_system_prompt = eval
.conversation
.first()
.map_or(false, |msg| msg.role == Role::System);
.is_some_and(|msg| msg.role == Role::System);
let messages = if has_system_prompt {
eval.conversation
} else {

View file

@ -201,7 +201,7 @@ impl Tool for ReadFileTool {
buffer
.file()
.as_ref()
.map_or(true, |file| !file.disk_state().exists())
.is_none_or(|file| !file.disk_state().exists())
})? {
anyhow::bail!("{file_path} not found");
}

View file

@ -387,7 +387,7 @@ fn working_dir(
let project = project.read(cx);
let cd = &input.cd;
if cd == "." || cd == "" {
if cd == "." || cd.is_empty() {
// Accept "." or "" as meaning "the one worktree" if we only have one worktree.
let mut worktrees = project.worktrees(cx);
@ -412,10 +412,8 @@ fn working_dir(
{
return Ok(Some(input_path.into()));
}
} else {
if let Some(worktree) = project.worktree_for_root_name(cd, cx) {
return Ok(Some(worktree.read(cx).abs_path().to_path_buf()));
}
} else if let Some(worktree) = project.worktree_for_root_name(cd, cx) {
return Ok(Some(worktree.read(cx).abs_path().to_path_buf()));
}
anyhow::bail!("`cd` directory {cd:?} was not in any of the project's worktrees.");

View file

@ -54,11 +54,7 @@ pub async fn stream_completion(
)])));
}
if request
.tools
.as_ref()
.map_or(false, |t| !t.tools.is_empty())
{
if request.tools.as_ref().is_some_and(|t| !t.tools.is_empty()) {
response = response.set_tool_config(request.tools);
}

View file

@ -147,7 +147,7 @@ impl ActiveCall {
let mut incoming_call = this.incoming_call.0.borrow_mut();
if incoming_call
.as_ref()
.map_or(false, |call| call.room_id == envelope.payload.room_id)
.is_some_and(|call| call.room_id == envelope.payload.room_id)
{
incoming_call.take();
}

View file

@ -64,7 +64,7 @@ pub struct RemoteParticipant {
impl RemoteParticipant {
pub fn has_video_tracks(&self) -> bool {
return !self.video_tracks.is_empty();
!self.video_tracks.is_empty()
}
pub fn can_write(&self) -> bool {

View file

@ -939,8 +939,7 @@ impl Room {
self.client.user_id()
)
})?;
if self.live_kit.as_ref().map_or(true, |kit| kit.deafened) && publication.is_audio()
{
if self.live_kit.as_ref().is_none_or(|kit| kit.deafened) && publication.is_audio() {
publication.set_enabled(false, cx);
}
match track {
@ -1174,7 +1173,7 @@ impl Room {
this.update(cx, |this, cx| {
this.shared_projects.insert(project.downgrade());
let active_project = this.local_participant.active_project.as_ref();
if active_project.map_or(false, |location| *location == project) {
if active_project.is_some_and(|location| *location == project) {
this.set_location(Some(&project), cx)
} else {
Task::ready(Ok(()))
@ -1247,9 +1246,9 @@ impl Room {
}
pub fn is_sharing_screen(&self) -> bool {
self.live_kit.as_ref().map_or(false, |live_kit| {
!matches!(live_kit.screen_track, LocalTrack::None)
})
self.live_kit
.as_ref()
.is_some_and(|live_kit| !matches!(live_kit.screen_track, LocalTrack::None))
}
pub fn shared_screen_id(&self) -> Option<u64> {
@ -1262,13 +1261,13 @@ impl Room {
}
pub fn is_sharing_mic(&self) -> bool {
self.live_kit.as_ref().map_or(false, |live_kit| {
!matches!(live_kit.microphone_track, LocalTrack::None)
})
self.live_kit
.as_ref()
.is_some_and(|live_kit| !matches!(live_kit.microphone_track, LocalTrack::None))
}
pub fn is_muted(&self) -> bool {
self.live_kit.as_ref().map_or(false, |live_kit| {
self.live_kit.as_ref().is_some_and(|live_kit| {
matches!(live_kit.microphone_track, LocalTrack::None)
|| live_kit.muted_by_user
|| live_kit.deafened
@ -1278,13 +1277,13 @@ impl Room {
pub fn muted_by_user(&self) -> bool {
self.live_kit
.as_ref()
.map_or(false, |live_kit| live_kit.muted_by_user)
.is_some_and(|live_kit| live_kit.muted_by_user)
}
pub fn is_speaking(&self) -> bool {
self.live_kit
.as_ref()
.map_or(false, |live_kit| live_kit.speaking)
.is_some_and(|live_kit| live_kit.speaking)
}
pub fn is_deafened(&self) -> Option<bool> {

View file

@ -340,7 +340,7 @@ impl ChannelChat {
return ControlFlow::Break(
if cursor
.item()
.map_or(false, |message| message.id == message_id)
.is_some_and(|message| message.id == message_id)
{
Some(cursor.start().1.0)
} else {
@ -362,7 +362,7 @@ impl ChannelChat {
if let ChannelMessageId::Saved(latest_message_id) = self.messages.summary().max_id
&& self
.last_acknowledged_id
.map_or(true, |acknowledged_id| acknowledged_id < latest_message_id)
.is_none_or(|acknowledged_id| acknowledged_id < latest_message_id)
{
self.rpc
.send(proto::AckChannelMessage {
@ -612,7 +612,7 @@ impl ChannelChat {
while let Some(message) = old_cursor.item() {
let message_ix = old_cursor.start().1.0;
if nonces.contains(&message.nonce) {
if ranges.last().map_or(false, |r| r.end == message_ix) {
if ranges.last().is_some_and(|r| r.end == message_ix) {
ranges.last_mut().unwrap().end += 1;
} else {
ranges.push(message_ix..message_ix + 1);

View file

@ -568,16 +568,14 @@ impl ChannelStore {
self.channel_index
.by_id()
.get(&channel_id)
.map_or(false, |channel| channel.is_root_channel())
.is_some_and(|channel| channel.is_root_channel())
}
pub fn is_public_channel(&self, channel_id: ChannelId) -> bool {
self.channel_index
.by_id()
.get(&channel_id)
.map_or(false, |channel| {
channel.visibility == ChannelVisibility::Public
})
.is_some_and(|channel| channel.visibility == ChannelVisibility::Public)
}
pub fn channel_capability(&self, channel_id: ChannelId) -> Capability {

View file

@ -363,7 +363,7 @@ fn anonymous_fd(path: &str) -> Option<fs::File> {
let fd: fd::RawFd = fd_str.parse().ok()?;
let file = unsafe { fs::File::from_raw_fd(fd) };
return Some(file);
Some(file)
}
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
{
@ -381,13 +381,13 @@ fn anonymous_fd(path: &str) -> Option<fs::File> {
}
let fd: fd::RawFd = fd_str.parse().ok()?;
let file = unsafe { fs::File::from_raw_fd(fd) };
return Some(file);
Some(file)
}
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "freebsd")))]
{
_ = path;
// not implemented for bsd, windows. Could be, but isn't yet
return None;
None
}
}
@ -586,7 +586,7 @@ mod flatpak {
pub fn set_bin_if_no_escape(mut args: super::Args) -> super::Args {
if env::var(NO_ESCAPE_ENV_NAME).is_ok()
&& env::var("FLATPAK_ID").map_or(false, |id| id.starts_with("dev.zed.Zed"))
&& env::var("FLATPAK_ID").is_ok_and(|id| id.starts_with("dev.zed.Zed"))
&& args.zed.is_none()
{
args.zed = Some("/app/libexec/zed-editor".into());

View file

@ -76,7 +76,7 @@ pub static ZED_APP_PATH: LazyLock<Option<PathBuf>> =
LazyLock::new(|| std::env::var("ZED_APP_PATH").ok().map(PathBuf::from));
pub static ZED_ALWAYS_ACTIVE: LazyLock<bool> =
LazyLock::new(|| std::env::var("ZED_ALWAYS_ACTIVE").map_or(false, |e| !e.is_empty()));
LazyLock::new(|| std::env::var("ZED_ALWAYS_ACTIVE").is_ok_and(|e| !e.is_empty()));
pub const INITIAL_RECONNECTION_DELAY: Duration = Duration::from_millis(500);
pub const MAX_RECONNECTION_DELAY: Duration = Duration::from_secs(30);

View file

@ -848,7 +848,7 @@ impl UserStore {
pub fn has_accepted_terms_of_service(&self) -> bool {
self.accepted_tos_at
.map_or(false, |accepted_tos_at| accepted_tos_at.is_some())
.is_some_and(|accepted_tos_at| accepted_tos_at.is_some())
}
pub fn accept_terms_of_service(&self, cx: &Context<Self>) -> Task<Result<()>> {

View file

@ -205,12 +205,12 @@ impl CloudApiClient {
let mut body = String::new();
response.body_mut().read_to_string(&mut body).await?;
if response.status() == StatusCode::UNAUTHORIZED {
return Ok(false);
Ok(false)
} else {
return Err(anyhow!(
Err(anyhow!(
"Failed to get authenticated user.\nStatus: {:?}\nBody: {body}",
response.status()
));
))
}
}
}

View file

@ -304,7 +304,7 @@ impl RandomizedTest for ProjectCollaborationTest {
let worktree = worktree.read(cx);
worktree.is_visible()
&& worktree.entries(false, 0).any(|e| e.is_file())
&& worktree.root_entry().map_or(false, |e| e.is_dir())
&& worktree.root_entry().is_some_and(|e| e.is_dir())
})
.choose(rng)
});

View file

@ -890,7 +890,7 @@ impl ChatPanel {
this.highlighted_message = Some((highlight_message_id, task));
}
if this.active_chat.as_ref().map_or(false, |(c, _)| *c == chat) {
if this.active_chat.as_ref().is_some_and(|(c, _)| *c == chat) {
this.message_list.scroll_to(ListOffset {
item_ix,
offset_in_item: px(0.0),
@ -1186,7 +1186,7 @@ impl Panel for ChatPanel {
let is_in_call = ActiveCall::global(cx)
.read(cx)
.room()
.map_or(false, |room| room.read(cx).contains_guests());
.is_some_and(|room| room.read(cx).contains_guests());
self.active || is_in_call
}

View file

@ -664,9 +664,7 @@ impl CollabPanel {
let has_children = channel_store
.channel_at_index(mat.candidate_id + 1)
.map_or(false, |next_channel| {
next_channel.parent_path.ends_with(&[channel.id])
});
.is_some_and(|next_channel| next_channel.parent_path.ends_with(&[channel.id]));
match &self.channel_editing_state {
Some(ChannelEditingState::Create {
@ -1125,7 +1123,7 @@ impl CollabPanel {
}
fn has_subchannels(&self, ix: usize) -> bool {
self.entries.get(ix).map_or(false, |entry| {
self.entries.get(ix).is_some_and(|entry| {
if let ListEntry::Channel { has_children, .. } = entry {
*has_children
} else {

View file

@ -497,7 +497,7 @@ impl NotificationPanel {
panel.is_scrolled_to_bottom()
&& panel
.active_chat()
.map_or(false, |chat| chat.read(cx).channel_id.0 == *channel_id)
.is_some_and(|chat| chat.read(cx).channel_id.0 == *channel_id)
} else {
false
};

View file

@ -19,7 +19,7 @@ use release_channel::ReleaseChannel;
/// Only works in development. Setting this environment variable in other
/// release channels is a no-op.
static ZED_DEVELOPMENT_USE_KEYCHAIN: LazyLock<bool> = LazyLock::new(|| {
std::env::var("ZED_DEVELOPMENT_USE_KEYCHAIN").map_or(false, |value| !value.is_empty())
std::env::var("ZED_DEVELOPMENT_USE_KEYCHAIN").is_ok_and(|value| !value.is_empty())
});
/// A provider for credentials.

View file

@ -385,7 +385,7 @@ impl DebugAdapter for CodeLldbDebugAdapter {
&& let Some(source_languages) = config.get("sourceLanguages").filter(|value| {
value
.as_array()
.map_or(false, |array| array.iter().all(Value::is_string))
.is_some_and(|array| array.iter().all(Value::is_string))
})
{
let ret = vec![

View file

@ -37,7 +37,7 @@ const FALLBACK_DB_NAME: &str = "FALLBACK_MEMORY_DB";
const DB_FILE_NAME: &str = "db.sqlite";
pub static ZED_STATELESS: LazyLock<bool> =
LazyLock::new(|| env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty()));
LazyLock::new(|| env::var("ZED_STATELESS").is_ok_and(|v| !v.is_empty()));
pub static ALL_FILE_DB_FAILED: LazyLock<AtomicBool> = LazyLock::new(|| AtomicBool::new(false));

View file

@ -20,7 +20,7 @@ pub trait Dismissable {
KEY_VALUE_STORE
.read_kvp(Self::KEY)
.log_err()
.map_or(false, |s| s.is_some())
.is_some_and(|s| s.is_some())
}
fn set_dismissed(is_dismissed: bool, cx: &mut App) {

View file

@ -392,7 +392,7 @@ impl LogStore {
session.label(),
session
.adapter_client()
.map_or(false, |client| client.has_adapter_logs()),
.is_some_and(|client| client.has_adapter_logs()),
)
});

View file

@ -414,7 +414,7 @@ pub(crate) fn new_debugger_pane(
.and_then(|item| item.downcast::<SubView>());
let is_hovered = as_subview
.as_ref()
.map_or(false, |item| item.read(cx).hovered);
.is_some_and(|item| item.read(cx).hovered);
h_flex()
.track_focus(&focus_handle)
@ -427,7 +427,6 @@ pub(crate) fn new_debugger_pane(
.bg(cx.theme().colors().tab_bar_background)
.on_action(|_: &menu::Cancel, window, cx| {
if cx.stop_active_drag(window) {
return;
} else {
cx.propagate();
}
@ -449,7 +448,7 @@ pub(crate) fn new_debugger_pane(
.children(pane.items().enumerate().map(|(ix, item)| {
let selected = active_pane_item
.as_ref()
.map_or(false, |active| active.item_id() == item.item_id());
.is_some_and(|active| active.item_id() == item.item_id());
let deemphasized = !pane.has_focus(window, cx);
let item_ = item.boxed_clone();
div()

View file

@ -528,7 +528,7 @@ impl BreakpointList {
cx.background_executor()
.spawn(async move { KEY_VALUE_STORE.write_kvp(key, value?).await })
} else {
return Task::ready(Result::Ok(()));
Task::ready(Result::Ok(()))
}
}

View file

@ -287,15 +287,13 @@ impl DiagnosticBlock {
}
}
}
} else {
if let Some(diagnostic) = editor
.snapshot(window, cx)
.buffer_snapshot
.diagnostic_group(buffer_id, group_id)
.nth(ix)
{
Self::jump_to(editor, diagnostic.range, window, cx)
}
} else if let Some(diagnostic) = editor
.snapshot(window, cx)
.buffer_snapshot
.diagnostic_group(buffer_id, group_id)
.nth(ix)
{
Self::jump_to(editor, diagnostic.range, window, cx)
};
}

View file

@ -383,12 +383,10 @@ impl ProjectDiagnosticsEditor {
} else {
self.update_all_diagnostics(false, window, cx);
}
} else if self.update_excerpts_task.is_some() {
self.update_excerpts_task = None;
} else {
if self.update_excerpts_task.is_some() {
self.update_excerpts_task = None;
} else {
self.update_all_diagnostics(false, window, cx);
}
self.update_all_diagnostics(false, window, cx);
}
cx.notify();
}
@ -542,7 +540,7 @@ impl ProjectDiagnosticsEditor {
return true;
}
this.diagnostics.insert(buffer_id, diagnostics.clone());
return false;
false
})?;
if unchanged {
return Ok(());

View file

@ -295,7 +295,7 @@ fn dump_all_gpui_actions() -> Vec<ActionDef> {
actions.sort_by_key(|a| a.name);
return actions;
actions
}
fn handle_postprocessing() -> Result<()> {

View file

@ -185,7 +185,7 @@ impl Render for EditPredictionButton {
let this = cx.entity();
let fs = self.fs.clone();
return div().child(
div().child(
PopoverMenu::new("supermaven")
.menu(move |window, cx| match &status {
SupermavenButtonStatus::NeedsActivation(activate_url) => {
@ -230,7 +230,7 @@ impl Render for EditPredictionButton {
},
)
.with_handle(self.popover_menu_handle.clone()),
);
)
}
EditPredictionProvider::Zed => {
@ -343,7 +343,7 @@ impl Render for EditPredictionButton {
let is_refreshing = self
.edit_prediction_provider
.as_ref()
.map_or(false, |provider| provider.is_refreshing(cx));
.is_some_and(|provider| provider.is_refreshing(cx));
if is_refreshing {
popover_menu = popover_menu.trigger(

View file

@ -13,7 +13,7 @@ use crate::{Editor, SwitchSourceHeader, element::register_action};
use project::lsp_store::clangd_ext::CLANGD_SERVER_NAME;
fn is_c_language(language: &Language) -> bool {
return language.name() == "C++".into() || language.name() == "C".into();
language.name() == "C++".into() || language.name() == "C".into()
}
pub fn switch_source_header(

View file

@ -1111,10 +1111,8 @@ impl CompletionsMenu {
let query_start_doesnt_match_split_words = query_start_lower
.map(|query_char| {
!split_words(&string_match.string).any(|word| {
word.chars()
.next()
.and_then(|c| c.to_lowercase().next())
.map_or(false, |word_char| word_char == query_char)
word.chars().next().and_then(|c| c.to_lowercase().next())
== Some(query_char)
})
})
.unwrap_or(false);

View file

@ -991,7 +991,7 @@ impl DisplaySnapshot {
if let Some(severity) = chunk.diagnostic_severity.filter(|severity| {
self.diagnostics_max_severity
.into_lsp()
.map_or(false, |max_severity| severity <= &max_severity)
.is_some_and(|max_severity| severity <= &max_severity)
}) {
if chunk.is_unnecessary {
diagnostic_highlight.fade_out = Some(editor_style.unnecessary_code_fade);

View file

@ -528,10 +528,7 @@ impl BlockMap {
if let Some(transform) = cursor.item()
&& transform.summary.input_rows > 0
&& cursor.end() == old_start
&& transform
.block
.as_ref()
.map_or(true, |b| !b.is_replacement())
&& transform.block.as_ref().is_none_or(|b| !b.is_replacement())
{
// Preserve the transform (push and next)
new_transforms.push(transform.clone(), &());
@ -539,7 +536,7 @@ impl BlockMap {
// Preserve below blocks at end of edit
while let Some(transform) = cursor.item() {
if transform.block.as_ref().map_or(false, |b| b.place_below()) {
if transform.block.as_ref().is_some_and(|b| b.place_below()) {
new_transforms.push(transform.clone(), &());
cursor.next();
} else {
@ -606,7 +603,7 @@ impl BlockMap {
// Discard below blocks at the end of the edit. They'll be reconstructed.
while let Some(transform) = cursor.item() {
if transform.block.as_ref().map_or(false, |b| b.place_below()) {
if transform.block.as_ref().is_some_and(|b| b.place_below()) {
cursor.next();
} else {
break;
@ -1328,7 +1325,7 @@ impl BlockSnapshot {
let Dimensions(output_start, input_start, _) = cursor.start();
let overshoot = if cursor
.item()
.map_or(false, |transform| transform.block.is_none())
.is_some_and(|transform| transform.block.is_none())
{
start_row.0 - output_start.0
} else {
@ -1358,7 +1355,7 @@ impl BlockSnapshot {
&& transform
.block
.as_ref()
.map_or(false, |block| block.height() > 0))
.is_some_and(|block| block.height() > 0))
{
break;
}
@ -1511,7 +1508,7 @@ impl BlockSnapshot {
pub(super) fn is_block_line(&self, row: BlockRow) -> bool {
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
cursor.seek(&row, Bias::Right);
cursor.item().map_or(false, |t| t.block.is_some())
cursor.item().is_some_and(|t| t.block.is_some())
}
pub(super) fn is_folded_buffer_header(&self, row: BlockRow) -> bool {
@ -1529,11 +1526,11 @@ impl BlockSnapshot {
.make_wrap_point(Point::new(row.0, 0), Bias::Left);
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(&());
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right);
cursor.item().map_or(false, |transform| {
cursor.item().is_some_and(|transform| {
transform
.block
.as_ref()
.map_or(false, |block| block.is_replacement())
.is_some_and(|block| block.is_replacement())
})
}
@ -1653,7 +1650,7 @@ impl BlockChunks<'_> {
if transform
.block
.as_ref()
.map_or(false, |block| block.height() == 0)
.is_some_and(|block| block.height() == 0)
{
self.transforms.next();
} else {
@ -1664,7 +1661,7 @@ impl BlockChunks<'_> {
if self
.transforms
.item()
.map_or(false, |transform| transform.block.is_none())
.is_some_and(|transform| transform.block.is_none())
{
let start_input_row = self.transforms.start().1.0;
let start_output_row = self.transforms.start().0.0;
@ -1774,7 +1771,7 @@ impl Iterator for BlockRows<'_> {
if transform
.block
.as_ref()
.map_or(false, |block| block.height() == 0)
.is_some_and(|block| block.height() == 0)
{
self.transforms.next();
} else {
@ -1786,7 +1783,7 @@ impl Iterator for BlockRows<'_> {
if transform
.block
.as_ref()
.map_or(true, |block| block.is_replacement())
.is_none_or(|block| block.is_replacement())
{
self.input_rows.seek(self.transforms.start().1.0);
}

View file

@ -491,14 +491,14 @@ impl FoldMap {
while folds
.peek()
.map_or(false, |(_, fold_range)| fold_range.start < edit.new.end)
.is_some_and(|(_, fold_range)| fold_range.start < edit.new.end)
{
let (fold, mut fold_range) = folds.next().unwrap();
let sum = new_transforms.summary();
assert!(fold_range.start.0 >= sum.input.len);
while folds.peek().map_or(false, |(next_fold, next_fold_range)| {
while folds.peek().is_some_and(|(next_fold, next_fold_range)| {
next_fold_range.start < fold_range.end
|| (next_fold_range.start == fold_range.end
&& fold.placeholder.merge_adjacent
@ -575,14 +575,14 @@ impl FoldMap {
for mut edit in inlay_edits {
old_transforms.seek(&edit.old.start, Bias::Left);
if old_transforms.item().map_or(false, |t| t.is_fold()) {
if old_transforms.item().is_some_and(|t| t.is_fold()) {
edit.old.start = old_transforms.start().0;
}
let old_start =
old_transforms.start().1.0 + (edit.old.start - old_transforms.start().0).0;
old_transforms.seek_forward(&edit.old.end, Bias::Right);
if old_transforms.item().map_or(false, |t| t.is_fold()) {
if old_transforms.item().is_some_and(|t| t.is_fold()) {
old_transforms.next();
edit.old.end = old_transforms.start().0;
}
@ -590,14 +590,14 @@ impl FoldMap {
old_transforms.start().1.0 + (edit.old.end - old_transforms.start().0).0;
new_transforms.seek(&edit.new.start, Bias::Left);
if new_transforms.item().map_or(false, |t| t.is_fold()) {
if new_transforms.item().is_some_and(|t| t.is_fold()) {
edit.new.start = new_transforms.start().0;
}
let new_start =
new_transforms.start().1.0 + (edit.new.start - new_transforms.start().0).0;
new_transforms.seek_forward(&edit.new.end, Bias::Right);
if new_transforms.item().map_or(false, |t| t.is_fold()) {
if new_transforms.item().is_some_and(|t| t.is_fold()) {
new_transforms.next();
edit.new.end = new_transforms.start().0;
}
@ -709,7 +709,7 @@ impl FoldSnapshot {
.transforms
.cursor::<Dimensions<InlayPoint, FoldPoint>>(&());
cursor.seek(&point, Bias::Right);
if cursor.item().map_or(false, |t| t.is_fold()) {
if cursor.item().is_some_and(|t| t.is_fold()) {
if bias == Bias::Left || point == cursor.start().0 {
cursor.start().1
} else {
@ -788,7 +788,7 @@ impl FoldSnapshot {
let inlay_offset = self.inlay_snapshot.to_inlay_offset(buffer_offset);
let mut cursor = self.transforms.cursor::<InlayOffset>(&());
cursor.seek(&inlay_offset, Bias::Right);
cursor.item().map_or(false, |t| t.placeholder.is_some())
cursor.item().is_some_and(|t| t.placeholder.is_some())
}
pub fn is_line_folded(&self, buffer_row: MultiBufferRow) -> bool {
@ -839,7 +839,7 @@ impl FoldSnapshot {
let inlay_end = if transform_cursor
.item()
.map_or(true, |transform| transform.is_fold())
.is_none_or(|transform| transform.is_fold())
{
inlay_start
} else if range.end < transform_end.0 {
@ -1348,7 +1348,7 @@ impl FoldChunks<'_> {
let inlay_end = if self
.transform_cursor
.item()
.map_or(true, |transform| transform.is_fold())
.is_none_or(|transform| transform.is_fold())
{
inlay_start
} else if range.end < transform_end.0 {
@ -1463,7 +1463,7 @@ impl FoldOffset {
.transforms
.cursor::<Dimensions<FoldOffset, TransformSummary>>(&());
cursor.seek(&self, Bias::Right);
let overshoot = if cursor.item().map_or(true, |t| t.is_fold()) {
let overshoot = if cursor.item().is_none_or(|t| t.is_fold()) {
Point::new(0, (self.0 - cursor.start().0.0) as u32)
} else {
let inlay_offset = cursor.start().1.input.len + self.0 - cursor.start().0.0;

View file

@ -625,7 +625,7 @@ impl InlayMap {
// we can push its remainder.
if buffer_edits_iter
.peek()
.map_or(true, |edit| edit.old.start >= cursor.end().0)
.is_none_or(|edit| edit.old.start >= cursor.end().0)
{
let transform_start = new_transforms.summary().input.len;
let transform_end =

View file

@ -74,10 +74,10 @@ impl WrapRows<'_> {
self.transforms
.seek(&WrapPoint::new(start_row, 0), Bias::Left);
let mut input_row = self.transforms.start().1.row();
if self.transforms.item().map_or(false, |t| t.is_isomorphic()) {
if self.transforms.item().is_some_and(|t| t.is_isomorphic()) {
input_row += start_row - self.transforms.start().0.row();
}
self.soft_wrapped = self.transforms.item().map_or(false, |t| !t.is_isomorphic());
self.soft_wrapped = self.transforms.item().is_some_and(|t| !t.is_isomorphic());
self.input_buffer_rows.seek(input_row);
self.input_buffer_row = self.input_buffer_rows.next().unwrap();
self.output_row = start_row;
@ -603,7 +603,7 @@ impl WrapSnapshot {
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
transforms.seek(&output_start, Bias::Right);
let mut input_start = TabPoint(transforms.start().1.0);
if transforms.item().map_or(false, |t| t.is_isomorphic()) {
if transforms.item().is_some_and(|t| t.is_isomorphic()) {
input_start.0 += output_start.0 - transforms.start().0.0;
}
let input_end = self
@ -634,7 +634,7 @@ impl WrapSnapshot {
cursor.seek(&WrapPoint::new(row + 1, 0), Bias::Left);
if cursor
.item()
.map_or(false, |transform| transform.is_isomorphic())
.is_some_and(|transform| transform.is_isomorphic())
{
let overshoot = row - cursor.start().0.row();
let tab_row = cursor.start().1.row() + overshoot;
@ -732,10 +732,10 @@ impl WrapSnapshot {
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
transforms.seek(&WrapPoint::new(start_row, 0), Bias::Left);
let mut input_row = transforms.start().1.row();
if transforms.item().map_or(false, |t| t.is_isomorphic()) {
if transforms.item().is_some_and(|t| t.is_isomorphic()) {
input_row += start_row - transforms.start().0.row();
}
let soft_wrapped = transforms.item().map_or(false, |t| !t.is_isomorphic());
let soft_wrapped = transforms.item().is_some_and(|t| !t.is_isomorphic());
let mut input_buffer_rows = self.tab_snapshot.rows(input_row);
let input_buffer_row = input_buffer_rows.next().unwrap();
WrapRows {
@ -754,7 +754,7 @@ impl WrapSnapshot {
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
cursor.seek(&point, Bias::Right);
let mut tab_point = cursor.start().1.0;
if cursor.item().map_or(false, |t| t.is_isomorphic()) {
if cursor.item().is_some_and(|t| t.is_isomorphic()) {
tab_point += point.0 - cursor.start().0.0;
}
TabPoint(tab_point)
@ -780,7 +780,7 @@ impl WrapSnapshot {
if bias == Bias::Left {
let mut cursor = self.transforms.cursor::<WrapPoint>(&());
cursor.seek(&point, Bias::Right);
if cursor.item().map_or(false, |t| !t.is_isomorphic()) {
if cursor.item().is_some_and(|t| !t.is_isomorphic()) {
point = *cursor.start();
*point.column_mut() -= 1;
}
@ -901,7 +901,7 @@ impl WrapChunks<'_> {
let output_end = WrapPoint::new(rows.end, 0);
self.transforms.seek(&output_start, Bias::Right);
let mut input_start = TabPoint(self.transforms.start().1.0);
if self.transforms.item().map_or(false, |t| t.is_isomorphic()) {
if self.transforms.item().is_some_and(|t| t.is_isomorphic()) {
input_start.0 += output_start.0 - self.transforms.start().0.0;
}
let input_end = self
@ -993,7 +993,7 @@ impl Iterator for WrapRows<'_> {
self.output_row += 1;
self.transforms
.seek_forward(&WrapPoint::new(self.output_row, 0), Bias::Left);
if self.transforms.item().map_or(false, |t| t.is_isomorphic()) {
if self.transforms.item().is_some_and(|t| t.is_isomorphic()) {
self.input_buffer_row = self.input_buffer_rows.next().unwrap();
self.soft_wrapped = false;
} else {

View file

@ -1429,7 +1429,7 @@ impl SelectionHistory {
if self
.undo_stack
.back()
.map_or(true, |e| e.selections != entry.selections)
.is_none_or(|e| e.selections != entry.selections)
{
self.undo_stack.push_back(entry);
if self.undo_stack.len() > MAX_SELECTION_HISTORY_LEN {
@ -1442,7 +1442,7 @@ impl SelectionHistory {
if self
.redo_stack
.back()
.map_or(true, |e| e.selections != entry.selections)
.is_none_or(|e| e.selections != entry.selections)
{
self.redo_stack.push_back(entry);
if self.redo_stack.len() > MAX_SELECTION_HISTORY_LEN {
@ -2512,9 +2512,7 @@ impl Editor {
.context_menu
.borrow()
.as_ref()
.map_or(false, |context| {
matches!(context, CodeContextMenu::Completions(_))
});
.is_some_and(|context| matches!(context, CodeContextMenu::Completions(_)));
showing_completions
|| self.edit_prediction_requires_modifier()
@ -2545,7 +2543,7 @@ impl Editor {
|| binding
.keystrokes()
.first()
.map_or(false, |keystroke| keystroke.modifiers.modified())
.is_some_and(|keystroke| keystroke.modifiers.modified())
}))
}
@ -2941,7 +2939,7 @@ impl Editor {
return false;
};
scope.override_name().map_or(false, |scope_name| {
scope.override_name().is_some_and(|scope_name| {
settings
.edit_predictions_disabled_in
.iter()
@ -4033,18 +4031,18 @@ impl Editor {
let following_text_allows_autoclose = snapshot
.chars_at(selection.start)
.next()
.map_or(true, |c| scope.should_autoclose_before(c));
.is_none_or(|c| scope.should_autoclose_before(c));
let preceding_text_allows_autoclose = selection.start.column == 0
|| snapshot.reversed_chars_at(selection.start).next().map_or(
true,
|c| {
|| snapshot
.reversed_chars_at(selection.start)
.next()
.is_none_or(|c| {
bracket_pair.start != bracket_pair.end
|| !snapshot
.char_classifier_at(selection.start)
.is_word(c)
},
);
});
let is_closing_quote = if bracket_pair.end == bracket_pair.start
&& bracket_pair.start.len() == 1
@ -4185,7 +4183,7 @@ impl Editor {
if !self.linked_edit_ranges.is_empty() {
let start_anchor = snapshot.anchor_before(selection.start);
let is_word_char = text.chars().next().map_or(true, |char| {
let is_word_char = text.chars().next().is_none_or(|char| {
let classifier = snapshot
.char_classifier_at(start_anchor.to_offset(&snapshot))
.ignore_punctuation(true);
@ -5427,11 +5425,11 @@ impl Editor {
let sort_completions = provider
.as_ref()
.map_or(false, |provider| provider.sort_completions());
.is_some_and(|provider| provider.sort_completions());
let filter_completions = provider
.as_ref()
.map_or(true, |provider| provider.filter_completions());
.is_none_or(|provider| provider.filter_completions());
let trigger_kind = match trigger {
Some(trigger) if buffer.read(cx).completion_triggers().contains(trigger) => {
@ -5537,7 +5535,7 @@ impl Editor {
let skip_digits = query
.as_ref()
.map_or(true, |query| !query.chars().any(|c| c.is_digit(10)));
.is_none_or(|query| !query.chars().any(|c| c.is_digit(10)));
let (mut words, provider_responses) = match &provider {
Some(provider) => {
@ -5971,7 +5969,7 @@ impl Editor {
let show_new_completions_on_confirm = completion
.confirm
.as_ref()
.map_or(false, |confirm| confirm(intent, window, cx));
.is_some_and(|confirm| confirm(intent, window, cx));
if show_new_completions_on_confirm {
self.show_completions(&ShowCompletions { trigger: None }, window, cx);
}
@ -6103,10 +6101,10 @@ impl Editor {
let spawn_straight_away = quick_launch
&& resolved_tasks
.as_ref()
.map_or(false, |tasks| tasks.templates.len() == 1)
.is_some_and(|tasks| tasks.templates.len() == 1)
&& code_actions
.as_ref()
.map_or(true, |actions| actions.is_empty())
.is_none_or(|actions| actions.is_empty())
&& debug_scenarios.is_empty();
editor.update_in(cx, |editor, window, cx| {
@ -6720,9 +6718,9 @@ impl Editor {
let buffer_id = cursor_position.buffer_id;
let buffer = this.buffer.read(cx);
if !buffer
if buffer
.text_anchor_for_position(cursor_position, cx)
.map_or(false, |(buffer, _)| buffer == cursor_buffer)
.is_none_or(|(buffer, _)| buffer != cursor_buffer)
{
return;
}
@ -6972,9 +6970,7 @@ impl Editor {
|| self
.quick_selection_highlight_task
.as_ref()
.map_or(true, |(prev_anchor_range, _)| {
prev_anchor_range != &query_range
})
.is_none_or(|(prev_anchor_range, _)| prev_anchor_range != &query_range)
{
let multi_buffer_visible_start = self
.scroll_manager
@ -7003,9 +6999,7 @@ impl Editor {
|| self
.debounced_selection_highlight_task
.as_ref()
.map_or(true, |(prev_anchor_range, _)| {
prev_anchor_range != &query_range
})
.is_none_or(|(prev_anchor_range, _)| prev_anchor_range != &query_range)
{
let multi_buffer_start = multi_buffer_snapshot
.anchor_before(0)
@ -7140,9 +7134,7 @@ impl Editor {
&& self
.edit_prediction_provider
.as_ref()
.map_or(false, |provider| {
provider.provider.show_completions_in_menu()
});
.is_some_and(|provider| provider.provider.show_completions_in_menu());
let preview_requires_modifier =
all_language_settings(file, cx).edit_predictions_mode() == EditPredictionsMode::Subtle;
@ -7726,7 +7718,7 @@ impl Editor {
|| self
.active_edit_prediction
.as_ref()
.map_or(false, |completion| {
.is_some_and(|completion| {
let invalidation_range = completion.invalidation_range.to_offset(&multibuffer);
let invalidation_range = invalidation_range.start..=invalidation_range.end;
!invalidation_range.contains(&offset_selection.head())
@ -8427,7 +8419,7 @@ impl Editor {
.context_menu
.borrow()
.as_ref()
.map_or(false, |menu| menu.visible())
.is_some_and(|menu| menu.visible())
}
pub fn context_menu_origin(&self) -> Option<ContextMenuOrigin> {
@ -8973,9 +8965,8 @@ impl Editor {
let end_row = start_row + line_count as u32;
visible_row_range.contains(&start_row)
&& visible_row_range.contains(&end_row)
&& cursor_row.map_or(true, |cursor_row| {
!((start_row..end_row).contains(&cursor_row))
})
&& cursor_row
.is_none_or(|cursor_row| !((start_row..end_row).contains(&cursor_row)))
})?;
content_origin
@ -9585,7 +9576,7 @@ impl Editor {
.tabstops
.iter()
.map(|tabstop| {
let is_end_tabstop = tabstop.ranges.first().map_or(false, |tabstop| {
let is_end_tabstop = tabstop.ranges.first().is_some_and(|tabstop| {
tabstop.is_empty() && tabstop.start == snippet.text.len() as isize
});
let mut tabstop_ranges = tabstop
@ -11716,7 +11707,7 @@ impl Editor {
let transpose_start = display_map
.buffer_snapshot
.clip_offset(transpose_offset.saturating_sub(1), Bias::Left);
if edits.last().map_or(true, |e| e.0.end <= transpose_start) {
if edits.last().is_none_or(|e| e.0.end <= transpose_start) {
let transpose_end = display_map
.buffer_snapshot
.clip_offset(transpose_offset + 1, Bias::Right);
@ -16229,23 +16220,21 @@ impl Editor {
if split {
workspace.split_item(SplitDirection::Right, item.clone(), window, cx);
} else {
if PreviewTabsSettings::get_global(cx).enable_preview_from_code_navigation {
let (preview_item_id, preview_item_idx) =
workspace.active_pane().read_with(cx, |pane, _| {
(pane.preview_item_id(), pane.preview_item_idx())
});
} else if PreviewTabsSettings::get_global(cx).enable_preview_from_code_navigation {
let (preview_item_id, preview_item_idx) =
workspace.active_pane().read_with(cx, |pane, _| {
(pane.preview_item_id(), pane.preview_item_idx())
});
workspace.add_item_to_active_pane(item.clone(), preview_item_idx, true, window, cx);
workspace.add_item_to_active_pane(item.clone(), preview_item_idx, true, window, cx);
if let Some(preview_item_id) = preview_item_id {
workspace.active_pane().update(cx, |pane, cx| {
pane.remove_item(preview_item_id, false, false, window, cx);
});
}
} else {
workspace.add_item_to_active_pane(item.clone(), None, true, window, cx);
if let Some(preview_item_id) = preview_item_id {
workspace.active_pane().update(cx, |pane, cx| {
pane.remove_item(preview_item_id, false, false, window, cx);
});
}
} else {
workspace.add_item_to_active_pane(item.clone(), None, true, window, cx);
}
workspace.active_pane().update(cx, |pane, cx| {
pane.set_preview_item_id(Some(item_id), cx);
@ -19010,7 +18999,7 @@ impl Editor {
fn has_blame_entries(&self, cx: &App) -> bool {
self.blame()
.map_or(false, |blame| blame.read(cx).has_generated_entries())
.is_some_and(|blame| blame.read(cx).has_generated_entries())
}
fn newest_selection_head_on_empty_line(&self, cx: &App) -> bool {
@ -19660,7 +19649,7 @@ impl Editor {
pub fn has_background_highlights<T: 'static>(&self) -> bool {
self.background_highlights
.get(&HighlightKey::Type(TypeId::of::<T>()))
.map_or(false, |(_, highlights)| !highlights.is_empty())
.is_some_and(|(_, highlights)| !highlights.is_empty())
}
pub fn background_highlights_in_range(
@ -20582,7 +20571,7 @@ impl Editor {
// For now, don't allow opening excerpts in buffers that aren't backed by
// regular project files.
fn can_open_excerpts_in_file(file: Option<&Arc<dyn language::File>>) -> bool {
file.map_or(true, |file| project::File::from_dyn(Some(file)).is_some())
file.is_none_or(|file| project::File::from_dyn(Some(file)).is_some())
}
fn marked_text_ranges(&self, cx: &App) -> Option<Vec<Range<OffsetUtf16>>> {
@ -21125,7 +21114,7 @@ impl Editor {
pub fn has_visible_completions_menu(&self) -> bool {
!self.edit_prediction_preview_is_active()
&& self.context_menu.borrow().as_ref().map_or(false, |menu| {
&& self.context_menu.borrow().as_ref().is_some_and(|menu| {
menu.visible() && matches!(menu, CodeContextMenu::Completions(_))
})
}
@ -21548,9 +21537,9 @@ fn is_grapheme_whitespace(text: &str) -> bool {
}
fn should_stay_with_preceding_ideograph(text: &str) -> bool {
text.chars().next().map_or(false, |ch| {
matches!(ch, '。' | '、' | '' | '' | '' | '' | '' | '…')
})
text.chars()
.next()
.is_some_and(|ch| matches!(ch, '。' | '、' | '' | '' | '' | '' | '' | '…'))
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
@ -21589,11 +21578,11 @@ impl<'a> Iterator for WordBreakingTokenizer<'a> {
} else {
let mut words = self.input[offset..].split_word_bound_indices().peekable();
let mut next_word_bound = words.peek().copied();
if next_word_bound.map_or(false, |(i, _)| i == 0) {
if next_word_bound.is_some_and(|(i, _)| i == 0) {
next_word_bound = words.next();
}
while let Some(grapheme) = iter.peek().copied() {
if next_word_bound.map_or(false, |(i, _)| i == offset) {
if next_word_bound.is_some_and(|(i, _)| i == offset) {
break;
};
if is_grapheme_whitespace(grapheme) != is_whitespace

View file

@ -810,10 +810,8 @@ impl Settings for EditorSettings {
if gutter.line_numbers.is_some() {
old_gutter.line_numbers = gutter.line_numbers
}
} else {
if gutter != GutterContent::default() {
current.gutter = Some(gutter)
}
} else if gutter != GutterContent::default() {
current.gutter = Some(gutter)
}
if let Some(b) = vscode.read_bool("editor.scrollBeyondLastLine") {
current.scroll_beyond_last_line = Some(if b {

View file

@ -919,6 +919,7 @@ impl EditorElement {
{
#[allow(
clippy::collapsible_if,
clippy::needless_return,
reason = "The cfg-block below makes this a false positive"
)]
if !text_hitbox.is_hovered(window) || editor.read_only(cx) {
@ -1126,26 +1127,24 @@ impl EditorElement {
let hovered_diff_hunk_row = if let Some(control_row) = hovered_diff_control {
Some(control_row)
} else {
if text_hovered {
let current_row = valid_point.row();
position_map.display_hunks.iter().find_map(|(hunk, _)| {
if let DisplayDiffHunk::Unfolded {
display_row_range, ..
} = hunk
{
if display_row_range.contains(&current_row) {
Some(display_row_range.start)
} else {
None
}
} else if text_hovered {
let current_row = valid_point.row();
position_map.display_hunks.iter().find_map(|(hunk, _)| {
if let DisplayDiffHunk::Unfolded {
display_row_range, ..
} = hunk
{
if display_row_range.contains(&current_row) {
Some(display_row_range.start)
} else {
None
}
})
} else {
None
}
} else {
None
}
})
} else {
None
};
if hovered_diff_hunk_row != editor.hovered_diff_hunk_row {
@ -1159,11 +1158,11 @@ impl EditorElement {
.inline_blame_popover
.as_ref()
.and_then(|state| state.popover_bounds)
.map_or(false, |bounds| bounds.contains(&event.position));
.is_some_and(|bounds| bounds.contains(&event.position));
let keyboard_grace = editor
.inline_blame_popover
.as_ref()
.map_or(false, |state| state.keyboard_grace);
.is_some_and(|state| state.keyboard_grace);
if mouse_over_inline_blame || mouse_over_popover {
editor.show_blame_popover(blame_entry, event.position, false, cx);
@ -1190,10 +1189,10 @@ impl EditorElement {
let is_visible = editor
.gutter_breakpoint_indicator
.0
.map_or(false, |indicator| indicator.is_active);
.is_some_and(|indicator| indicator.is_active);
let has_existing_breakpoint =
editor.breakpoint_store.as_ref().map_or(false, |store| {
editor.breakpoint_store.as_ref().is_some_and(|store| {
let Some(project) = &editor.project else {
return false;
};
@ -2220,12 +2219,11 @@ impl EditorElement {
cmp::max(padded_line, min_start)
};
let behind_edit_prediction_popover = edit_prediction_popover_origin.as_ref().map_or(
false,
|edit_prediction_popover_origin| {
let behind_edit_prediction_popover = edit_prediction_popover_origin
.as_ref()
.is_some_and(|edit_prediction_popover_origin| {
(pos_y..pos_y + line_height).contains(&edit_prediction_popover_origin.y)
},
);
});
let opacity = if behind_edit_prediction_popover {
0.5
} else {
@ -2291,9 +2289,7 @@ impl EditorElement {
None
}
})
.map_or(false, |source| {
matches!(source, CodeActionSource::Indicator(..))
});
.is_some_and(|source| matches!(source, CodeActionSource::Indicator(..)));
Some(editor.render_inline_code_actions(icon_size, display_point.row(), active, cx))
})?;
@ -2909,7 +2905,7 @@ impl EditorElement {
if multibuffer_row
.0
.checked_sub(1)
.map_or(false, |previous_row| {
.is_some_and(|previous_row| {
snapshot.is_line_folded(MultiBufferRow(previous_row))
})
{
@ -3900,7 +3896,7 @@ impl EditorElement {
for (row, block) in fixed_blocks {
let block_id = block.id();
if focused_block.as_ref().map_or(false, |b| b.id == block_id) {
if focused_block.as_ref().is_some_and(|b| b.id == block_id) {
focused_block = None;
}
@ -3957,7 +3953,7 @@ impl EditorElement {
};
let block_id = block.id();
if focused_block.as_ref().map_or(false, |b| b.id == block_id) {
if focused_block.as_ref().is_some_and(|b| b.id == block_id) {
focused_block = None;
}
@ -4736,7 +4732,7 @@ impl EditorElement {
}
};
let source_included = source_display_point.map_or(true, |source_display_point| {
let source_included = source_display_point.is_none_or(|source_display_point| {
visible_range
.to_inclusive()
.contains(&source_display_point.row())
@ -4916,7 +4912,7 @@ impl EditorElement {
let intersects_menu = |bounds: Bounds<Pixels>| -> bool {
context_menu_layout
.as_ref()
.map_or(false, |menu| bounds.intersects(&menu.bounds))
.is_some_and(|menu| bounds.intersects(&menu.bounds))
};
let can_place_above = {
@ -5101,7 +5097,7 @@ impl EditorElement {
if active_positions
.iter()
.any(|p| p.map_or(false, |p| display_row_range.contains(&p.row())))
.any(|p| p.is_some_and(|p| display_row_range.contains(&p.row())))
{
let y = display_row_range.start.as_f32() * line_height
+ text_hitbox.bounds.top()
@ -5214,7 +5210,7 @@ impl EditorElement {
let intersects_menu = |bounds: Bounds<Pixels>| -> bool {
context_menu_layout
.as_ref()
.map_or(false, |menu| bounds.intersects(&menu.bounds))
.is_some_and(|menu| bounds.intersects(&menu.bounds))
};
let final_origin = if popover_bounds_above.is_contained_within(hitbox)
@ -5299,7 +5295,7 @@ impl EditorElement {
let mut end_row = start_row.0;
while active_rows
.peek()
.map_or(false, |(active_row, has_selection)| {
.is_some_and(|(active_row, has_selection)| {
active_row.0 == end_row + 1
&& has_selection.selection == contains_non_empty_selection.selection
})
@ -6687,25 +6683,23 @@ impl EditorElement {
editor.set_scroll_position(position, window, cx);
}
cx.stop_propagation();
} else {
if minimap_hitbox.is_hovered(window) {
editor.scroll_manager.set_is_hovering_minimap_thumb(
!event.dragging()
&& layout
.thumb_layout
.thumb_bounds
.is_some_and(|bounds| bounds.contains(&event.position)),
cx,
);
} else if minimap_hitbox.is_hovered(window) {
editor.scroll_manager.set_is_hovering_minimap_thumb(
!event.dragging()
&& layout
.thumb_layout
.thumb_bounds
.is_some_and(|bounds| bounds.contains(&event.position)),
cx,
);
// Stop hover events from propagating to the
// underlying editor if the minimap hitbox is hovered
if !event.dragging() {
cx.stop_propagation();
}
} else {
editor.scroll_manager.hide_minimap_thumb(cx);
// Stop hover events from propagating to the
// underlying editor if the minimap hitbox is hovered
if !event.dragging() {
cx.stop_propagation();
}
} else {
editor.scroll_manager.hide_minimap_thumb(cx);
}
mouse_position = event.position;
});
@ -7084,9 +7078,7 @@ impl EditorElement {
let unstaged_hollow = ProjectSettings::get_global(cx)
.git
.hunk_style
.map_or(false, |style| {
matches!(style, GitHunkStyleSetting::UnstagedHollow)
});
.is_some_and(|style| matches!(style, GitHunkStyleSetting::UnstagedHollow));
unstaged == unstaged_hollow
}
@ -8183,7 +8175,7 @@ impl Element for EditorElement {
let is_row_soft_wrapped = |row: usize| {
row_infos
.get(row)
.map_or(true, |info| info.buffer_row.is_none())
.is_none_or(|info| info.buffer_row.is_none())
};
let start_anchor = if start_row == Default::default() {
@ -9718,14 +9710,12 @@ impl PointForPosition {
false
} else if start_row == end_row {
candidate_col >= start_col && candidate_col < end_col
} else if candidate_row == start_row {
candidate_col >= start_col
} else if candidate_row == end_row {
candidate_col < end_col
} else {
if candidate_row == start_row {
candidate_col >= start_col
} else if candidate_row == end_row {
candidate_col < end_col
} else {
true
}
true
}
}
}

View file

@ -415,7 +415,7 @@ impl GitBlame {
let old_end = cursor.end();
if row_edits
.peek()
.map_or(true, |next_edit| next_edit.old.start >= old_end)
.is_none_or(|next_edit| next_edit.old.start >= old_end)
&& let Some(entry) = cursor.item()
{
if old_end > edit.old.end {

View file

@ -271,7 +271,7 @@ impl Editor {
Task::ready(Ok(Navigated::No))
};
self.select(SelectPhase::End, window, cx);
return navigate_task;
navigate_task
}
}
@ -871,7 +871,7 @@ fn surrounding_filename(
.peekable();
while let Some(ch) = forwards.next() {
// Skip escaped whitespace
if ch == '\\' && forwards.peek().map_or(false, |ch| ch.is_whitespace()) {
if ch == '\\' && forwards.peek().is_some_and(|ch| ch.is_whitespace()) {
token_end += ch.len_utf8();
let whitespace = forwards.next().unwrap();
token_end += whitespace.len_utf8();

View file

@ -201,7 +201,7 @@ impl FollowableItem for Editor {
if buffer
.as_singleton()
.and_then(|buffer| buffer.read(cx).file())
.map_or(false, |file| file.is_private())
.is_some_and(|file| file.is_private())
{
return None;
}
@ -715,7 +715,7 @@ impl Item for Editor {
.read(cx)
.as_singleton()
.and_then(|buffer| buffer.read(cx).file())
.map_or(false, |file| file.disk_state() == DiskState::Deleted);
.is_some_and(|file| file.disk_state() == DiskState::Deleted);
h_flex()
.gap_2()

View file

@ -86,9 +86,9 @@ pub(crate) fn should_auto_close(
});
}
if to_auto_edit.is_empty() {
return None;
None
} else {
return Some(to_auto_edit);
Some(to_auto_edit)
}
}
@ -186,7 +186,7 @@ pub(crate) fn generate_auto_close_edits(
let range = node_name.byte_range();
return buffer.text_for_range(range).equals_str(name);
}
return is_empty;
is_empty
};
let tree_root_node = {
@ -227,7 +227,7 @@ pub(crate) fn generate_auto_close_edits(
let has_open_tag_with_same_tag_name = ancestor
.named_child(0)
.filter(|n| n.kind() == config.open_tag_node_name)
.map_or(false, |element_open_tag_node| {
.is_some_and(|element_open_tag_node| {
tag_node_name_equals(&element_open_tag_node, &tag_name)
});
if has_open_tag_with_same_tag_name {
@ -263,8 +263,7 @@ pub(crate) fn generate_auto_close_edits(
}
let is_after_open_tag = |node: &Node| {
return node.start_byte() < open_tag.start_byte()
&& node.end_byte() < open_tag.start_byte();
node.start_byte() < open_tag.start_byte() && node.end_byte() < open_tag.start_byte()
};
// perf: use cursor for more efficient traversal
@ -301,7 +300,7 @@ pub(crate) fn generate_auto_close_edits(
let edit_range = edit_anchor..edit_anchor;
edits.push((edit_range, format!("</{}>", tag_name)));
}
return Ok(edits);
Ok(edits)
}
pub(crate) fn refresh_enabled_in_any_buffer(
@ -367,7 +366,7 @@ pub(crate) fn construct_initial_buffer_versions_map<
initial_buffer_versions.insert(buffer_id, buffer_version);
}
}
return initial_buffer_versions;
initial_buffer_versions
}
pub(crate) fn handle_from(
@ -455,12 +454,9 @@ pub(crate) fn handle_from(
let ensure_no_edits_since_start = || -> Option<()> {
let has_edits_since_start = this
.read_with(cx, |this, cx| {
this.buffer
.read(cx)
.buffer(buffer_id)
.map_or(true, |buffer| {
buffer.read(cx).has_edits_since(&buffer_version_initial)
})
this.buffer.read(cx).buffer(buffer_id).is_none_or(|buffer| {
buffer.read(cx).has_edits_since(&buffer_version_initial)
})
})
.ok()?;

View file

@ -61,13 +61,13 @@ impl MouseContextMenu {
source,
offset: position - (source_position + content_origin),
};
return Some(MouseContextMenu::new(
Some(MouseContextMenu::new(
editor,
menu_position,
context_menu,
window,
cx,
));
))
}
pub(crate) fn new(

View file

@ -89,7 +89,7 @@ impl Editor {
.lsp_task_source()?;
if lsp_settings
.get(&lsp_tasks_source)
.map_or(true, |s| s.enable_lsp_tasks)
.is_none_or(|s| s.enable_lsp_tasks)
{
let buffer_id = buffer.read(cx).remote_id();
Some((lsp_tasks_source, buffer_id))

View file

@ -54,7 +54,7 @@ impl AssertionsReport {
pub fn passed_count(&self) -> usize {
self.ran
.iter()
.filter(|a| a.result.as_ref().map_or(false, |result| result.passed))
.filter(|a| a.result.as_ref().is_ok_and(|result| result.passed))
.count()
}

View file

@ -112,7 +112,7 @@ fn main() {
let telemetry = app_state.client.telemetry();
telemetry.start(system_id, installation_id, session_id, cx);
let enable_telemetry = env::var("ZED_EVAL_TELEMETRY").map_or(false, |value| value == "1")
let enable_telemetry = env::var("ZED_EVAL_TELEMETRY").is_ok_and(|value| value == "1")
&& telemetry.has_checksum_seed();
if enable_telemetry {
println!("Telemetry enabled");

View file

@ -70,10 +70,10 @@ impl Example for AddArgToTraitMethod {
let path_str = format!("crates/assistant_tools/src/{}.rs", tool_name);
let edits = edits.get(Path::new(&path_str));
let ignored = edits.map_or(false, |edits| {
let ignored = edits.is_some_and(|edits| {
edits.has_added_line(" _window: Option<gpui::AnyWindowHandle>,\n")
});
let uningored = edits.map_or(false, |edits| {
let uningored = edits.is_some_and(|edits| {
edits.has_added_line(" window: Option<gpui::AnyWindowHandle>,\n")
});
@ -89,7 +89,7 @@ impl Example for AddArgToTraitMethod {
let batch_tool_edits = edits.get(Path::new("crates/assistant_tools/src/batch_tool.rs"));
cx.assert(
batch_tool_edits.map_or(false, |edits| {
batch_tool_edits.is_some_and(|edits| {
edits.has_added_line(" window: Option<gpui::AnyWindowHandle>,\n")
}),
"Argument: batch_tool",

View file

@ -401,7 +401,7 @@ impl ExtensionBuilder {
let mut clang_path = wasi_sdk_dir.clone();
clang_path.extend(["bin", &format!("clang{}", env::consts::EXE_SUFFIX)]);
if fs::metadata(&clang_path).map_or(false, |metadata| metadata.is_file()) {
if fs::metadata(&clang_path).is_ok_and(|metadata| metadata.is_file()) {
return Ok(clang_path);
}

View file

@ -19,9 +19,8 @@ pub struct ExtensionEvents;
impl ExtensionEvents {
/// Returns the global [`ExtensionEvents`].
pub fn try_global(cx: &App) -> Option<Entity<Self>> {
return cx
.try_global::<GlobalExtensionEvents>()
.map(|g| g.0.clone());
cx.try_global::<GlobalExtensionEvents>()
.map(|g| g.0.clone())
}
fn new(_cx: &mut Context<Self>) -> Self {

View file

@ -562,12 +562,12 @@ impl ExtensionStore {
extensions
.into_iter()
.filter(|extension| {
this.extension_index.extensions.get(&extension.id).map_or(
true,
|installed_extension| {
this.extension_index
.extensions
.get(&extension.id)
.is_none_or(|installed_extension| {
installed_extension.manifest.version != extension.manifest.version
},
)
})
})
.collect()
})
@ -1451,7 +1451,7 @@ impl ExtensionStore {
if extension_dir
.file_name()
.map_or(false, |file_name| file_name == ".DS_Store")
.is_some_and(|file_name| file_name == ".DS_Store")
{
continue;
}

View file

@ -14,7 +14,7 @@ struct FeatureFlags {
}
pub static ZED_DISABLE_STAFF: LazyLock<bool> = LazyLock::new(|| {
std::env::var("ZED_DISABLE_STAFF").map_or(false, |value| !value.is_empty() && value != "0")
std::env::var("ZED_DISABLE_STAFF").is_ok_and(|value| !value.is_empty() && value != "0")
});
impl FeatureFlags {

View file

@ -135,7 +135,7 @@ impl Display for SystemSpecs {
fn try_determine_available_gpus() -> Option<String> {
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
{
return std::process::Command::new("vulkaninfo")
std::process::Command::new("vulkaninfo")
.args(&["--summary"])
.output()
.ok()
@ -150,11 +150,11 @@ fn try_determine_available_gpus() -> Option<String> {
]
.join("\n")
})
.or(Some("Failed to run `vulkaninfo --summary`".to_string()));
.or(Some("Failed to run `vulkaninfo --summary`".to_string()))
}
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
{
return None;
None
}
}

View file

@ -878,9 +878,7 @@ impl FileFinderDelegate {
PathMatchCandidateSet {
snapshot: worktree.snapshot(),
include_ignored: self.include_ignored.unwrap_or_else(|| {
worktree
.root_entry()
.map_or(false, |entry| entry.is_ignored)
worktree.root_entry().is_some_and(|entry| entry.is_ignored)
}),
include_root_name,
candidates: project::Candidates::Files,

View file

@ -728,7 +728,7 @@ impl PickerDelegate for OpenPathDelegate {
.child(LabelLike::new().child(label_with_highlights)),
)
}
DirectoryState::None { .. } => return None,
DirectoryState::None { .. } => None,
}
}

View file

@ -72,7 +72,7 @@ impl FileIcons {
return maybe_path;
}
}
return this.get_icon_for_type("default", cx);
this.get_icon_for_type("default", cx)
}
fn default_icon_theme(cx: &App) -> Option<Arc<IconTheme>> {

View file

@ -625,13 +625,13 @@ impl Fs for RealFs {
async fn is_file(&self, path: &Path) -> bool {
smol::fs::metadata(path)
.await
.map_or(false, |metadata| metadata.is_file())
.is_ok_and(|metadata| metadata.is_file())
}
async fn is_dir(&self, path: &Path) -> bool {
smol::fs::metadata(path)
.await
.map_or(false, |metadata| metadata.is_dir())
.is_ok_and(|metadata| metadata.is_dir())
}
async fn metadata(&self, path: &Path) -> Result<Option<Metadata>> {

View file

@ -269,10 +269,8 @@ impl GitExcludeOverride {
pub async fn restore_original(&mut self) -> Result<()> {
if let Some(ref original) = self.original_excludes {
smol::fs::write(&self.git_exclude_path, original).await?;
} else {
if self.git_exclude_path.exists() {
smol::fs::remove_file(&self.git_exclude_path).await?;
}
} else if self.git_exclude_path.exists() {
smol::fs::remove_file(&self.git_exclude_path).await?;
}
self.added_excludes = None;
@ -2052,7 +2050,7 @@ fn parse_branch_input(input: &str) -> Result<Vec<Branch>> {
}
fn parse_upstream_track(upstream_track: &str) -> Result<UpstreamTracking> {
if upstream_track == "" {
if upstream_track.is_empty() {
return Ok(UpstreamTracking::Tracked(UpstreamTrackingStatus {
ahead: 0,
behind: 0,

View file

@ -88,11 +88,10 @@ impl CommitView {
let ix = pane.items().position(|item| {
let commit_view = item.downcast::<CommitView>();
commit_view
.map_or(false, |view| view.read(cx).commit.sha == commit.sha)
.is_some_and(|view| view.read(cx).commit.sha == commit.sha)
});
if let Some(ix) = ix {
pane.activate_item(ix, true, true, window, cx);
return;
} else {
pane.add_item(Box::new(commit_view), true, true, None, window, cx);
}

Some files were not shown because too many files have changed in this diff Show more