chore: Fix several style lints (#17488)

It's not comprehensive enough to start linting on `style` group, but
hey, it's a start.

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-09-06 11:58:39 +02:00 committed by GitHub
parent 93249fc82b
commit e6c1c51b37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
361 changed files with 3530 additions and 3587 deletions

View file

@ -145,20 +145,14 @@ impl Kernel {
}
pub fn set_execution_state(&mut self, status: &ExecutionState) {
match self {
Kernel::RunningKernel(running_kernel) => {
running_kernel.execution_state = status.clone();
}
_ => {}
if let Kernel::RunningKernel(running_kernel) = self {
running_kernel.execution_state = status.clone();
}
}
pub fn set_kernel_info(&mut self, kernel_info: &KernelInfoReply) {
match self {
Kernel::RunningKernel(running_kernel) => {
running_kernel.kernel_info = Some(kernel_info.clone());
}
_ => {}
if let Kernel::RunningKernel(running_kernel) = self {
running_kernel.kernel_info = Some(kernel_info.clone());
}
}

View file

@ -76,10 +76,10 @@ fn rank_mime_type(mimetype: &MimeType) -> usize {
pub(crate) trait OutputContent {
fn clipboard_content(&self, cx: &WindowContext) -> Option<ClipboardItem>;
fn has_clipboard_content(&self, _cx: &WindowContext) -> bool {
return false;
false
}
fn has_buffer_content(&self, _cx: &WindowContext) -> bool {
return false;
false
}
fn buffer_content(&mut self, _cx: &mut WindowContext) -> Option<Model<Buffer>> {
None
@ -184,10 +184,7 @@ impl Output {
multi_buffer
});
let editor =
Editor::for_multibuffer(multibuffer, None, false, cx);
editor
Editor::for_multibuffer(multibuffer, None, false, cx)
}));
workspace
.update(cx, |workspace, cx| {
@ -360,30 +357,9 @@ impl ExecutionView {
}
JupyterMessageContent::ExecuteReply(reply) => {
for payload in reply.payload.iter() {
match payload {
// Pager data comes in via `?` at the end of a statement in Python, used for showing documentation.
// Some UI will show this as a popup. For ease of implementation, it's included as an output here.
runtimelib::Payload::Page { data, .. } => {
let output = Output::new(data, None, cx);
self.outputs.push(output);
}
// There are other payloads that could be handled here, such as updating the input.
// Below are the other payloads that _could_ be handled, but are not required for Zed.
// Set next input adds text to the next cell. Not required to support.
// However, this could be implemented by adding text to the buffer.
// Trigger in python using `get_ipython().set_next_input("text")`
//
// runtimelib::Payload::SetNextInput { text, replace } => {},
// Not likely to be used in the context of Zed, where someone could just open the buffer themselves
// Python users can trigger this with the `%edit` magic command
// runtimelib::Payload::EditMagic { filename, line_number } => {},
// Ask the user if they want to exit the kernel. Not required to support.
// runtimelib::Payload::AskExit { keepkernel } => {},
_ => {}
if let runtimelib::Payload::Page { data, .. } = payload {
let output = Output::new(data, None, cx);
self.outputs.push(output);
}
}
cx.notify();
@ -450,21 +426,17 @@ impl ExecutionView {
fn apply_terminal_text(&mut self, text: &str, cx: &mut ViewContext<Self>) -> Option<Output> {
if let Some(last_output) = self.outputs.last_mut() {
match last_output {
Output::Stream {
content: last_stream,
} => {
// Don't need to add a new output, we already have a terminal output
// and can just update the most recent terminal output
last_stream.update(cx, |last_stream, cx| {
last_stream.append_text(text, cx);
cx.notify();
});
return None;
}
// A different output type is "in the way", so we need to create a new output,
// which is the same as having no prior stream/terminal text
_ => {}
if let Output::Stream {
content: last_stream,
} = last_output
{
// Don't need to add a new output, we already have a terminal output
// and can just update the most recent terminal output
last_stream.update(cx, |last_stream, cx| {
last_stream.append_text(text, cx);
cx.notify();
});
return None;
}
}
@ -517,7 +489,7 @@ impl Render for ExecutionView {
.into_any_element(),
};
if self.outputs.len() == 0 {
if self.outputs.is_empty() {
return v_flex()
.min_h(cx.line_height())
.justify_center()

View file

@ -50,12 +50,12 @@ impl ImageView {
id: gpui_image_data.id.0 as u64,
});
return Ok(ImageView {
Ok(ImageView {
clipboard_image,
height,
width,
image: Arc::new(gpui_image_data),
});
})
}
}

View file

@ -323,7 +323,7 @@ impl OutputContent for TerminalOutput {
}
fn buffer_content(&mut self, cx: &mut WindowContext) -> Option<Model<Buffer>> {
if let Some(_) = self.full_buffer.as_ref() {
if self.full_buffer.as_ref().is_some() {
return self.full_buffer.clone();
}

View file

@ -73,7 +73,7 @@ pub struct TableView {
}
fn cell_content(row: &Value, field: &str) -> String {
match row.get(&field) {
match row.get(field) {
Some(Value::String(s)) => s.clone(),
Some(Value::Number(n)) => n.to_string(),
Some(Value::Bool(b)) => b.to_string(),
@ -116,7 +116,7 @@ impl TableView {
};
for row in data {
let content = cell_content(&row, &field.name);
let content = cell_content(row, &field.name);
runs[0].len = content.len();
let cell_width = cx
.text_system()
@ -130,7 +130,7 @@ impl TableView {
widths.push(width)
}
let cached_clipboard_content = Self::create_clipboard_content(&table);
let cached_clipboard_content = Self::create_clipboard_content(table);
Self {
table: table.clone(),
@ -272,7 +272,7 @@ impl Render for TableView {
let body = data
.iter()
.map(|row| self.render_row(&self.table.schema, false, &row, cx));
.map(|row| self.render_row(&self.table.schema, false, row, cx));
v_flex()
.id("table")

View file

@ -242,7 +242,7 @@ impl Render for ReplSessionsPage {
for spec in kernel_specifications {
kernels_by_language
.entry(spec.kernelspec.language.clone())
.or_insert_with(Vec::new)
.or_default()
.push(spec);
}

View file

@ -129,7 +129,7 @@ impl ReplStore {
// Top priority is the selected kernel
return runtime_specification.name.to_lowercase() == selected.to_lowercase();
}
return false;
false
})
.cloned();

View file

@ -260,7 +260,7 @@ impl Session {
let stderr = kernel.process.stderr.take();
cx.spawn(|_session, mut _cx| async move {
if let None = stderr {
if stderr.is_none() {
return;
}
let reader = BufReader::new(stderr.unwrap());
@ -275,7 +275,7 @@ impl Session {
let stdout = kernel.process.stdout.take();
cx.spawn(|_session, mut _cx| async move {
if let None = stdout {
if stdout.is_none() {
return;
}
let reader = BufReader::new(stdout.unwrap());
@ -411,11 +411,8 @@ impl Session {
}
fn send(&mut self, message: JupyterMessage, _cx: &mut ViewContext<Self>) -> anyhow::Result<()> {
match &mut self.kernel {
Kernel::RunningKernel(kernel) => {
kernel.request_tx.try_send(message).ok();
}
_ => {}
if let Kernel::RunningKernel(kernel) = &mut self.kernel {
kernel.request_tx.try_send(message).ok();
}
anyhow::Ok(())
@ -571,7 +568,7 @@ impl Session {
cx.notify();
}
JupyterMessageContent::KernelInfoReply(reply) => {
self.kernel.set_kernel_info(&reply);
self.kernel.set_kernel_info(reply);
cx.notify();
}
JupyterMessageContent::UpdateDisplayData(update) => {
@ -592,8 +589,7 @@ impl Session {
}
if let Some(block) = self.blocks.get_mut(parent_message_id) {
block.handle_message(&message, cx);
return;
block.handle_message(message, cx);
}
}