One big cleanup pass of clippy lints

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
ForLoveOfCats 2022-08-10 17:39:24 -04:00 committed by K Simmons
parent e7540d2833
commit 8ba2f77148
138 changed files with 1328 additions and 1366 deletions

View file

@ -7,8 +7,7 @@ use gpui::{
use settings::Settings;
use workspace::StatusItemView;
pub const NEW_ISSUE_URL: &'static str =
"https://github.com/zed-industries/feedback/issues/new/choose";
pub const NEW_ISSUE_URL: &str = "https://github.com/zed-industries/feedback/issues/new/choose";
pub struct FeedbackLink;

View file

@ -116,7 +116,7 @@ impl super::LspAdapter for CLspAdapter {
) -> Option<CodeLabel> {
let label = completion
.label
.strip_prefix("")
.strip_prefix('•')
.unwrap_or(&completion.label)
.trim();

View file

@ -72,7 +72,7 @@ impl super::LspAdapter for GoLspAdapter {
}
}
} else if let Some(path) = this.cached_server_binary(container_dir.clone()).await {
return Ok(path.to_path_buf());
return Ok(path);
}
let gobin_dir = container_dir.join("gobin");
@ -122,7 +122,7 @@ impl super::LspAdapter for GoLspAdapter {
}
if let Some(path) = last_binary_path {
Ok(path.to_path_buf())
Ok(path)
} else {
Err(anyhow!("no cached binary"))
}
@ -141,7 +141,7 @@ impl super::LspAdapter for GoLspAdapter {
// Gopls returns nested fields and methods as completions.
// To syntax highlight these, combine their final component
// with their detail.
let name_offset = label.rfind(".").unwrap_or(0);
let name_offset = label.rfind('.').unwrap_or(0);
match completion.kind.zip(completion.detail.as_ref()) {
Some((lsp::CompletionItemKind::MODULE, detail)) => {

View file

@ -206,7 +206,7 @@ mod tests {
);
// dedent the closing paren if it is shifted to the beginning of the line
let argument_ix = buffer.text().find("1").unwrap();
let argument_ix = buffer.text().find('1').unwrap();
buffer.edit(
[(argument_ix..argument_ix + 1, "")],
Some(AutoindentMode::EachLine),

View file

@ -65,7 +65,7 @@ impl LspAdapter for TypeScriptLspAdapter {
("typescript", versions.typescript_version.as_str()),
(
"typescript-language-server",
&versions.server_version.as_str(),
versions.server_version.as_str(),
),
],
&version_dir,

View file

@ -29,7 +29,7 @@ use serde_json::json;
use settings::{self, KeymapFileContent, Settings, SettingsFileContent};
use smol::process::Command;
use std::{env, ffi::OsStr, fs, panic, path::PathBuf, sync::Arc, thread, time::Duration};
use terminal;
use theme::ThemeRegistry;
use util::{ResultExt, TryFutureExt};
use workspace::{self, AppState, NewFile, OpenPaths};
@ -54,7 +54,7 @@ fn main() {
let db = app.background().spawn(async move {
project::Db::open(&*zed::paths::DB)
.log_err()
.unwrap_or(project::Db::null())
.unwrap_or_else(project::Db::null)
});
load_embedded_fonts(&app);
@ -182,10 +182,8 @@ fn main() {
if client::IMPERSONATE_LOGIN.is_some() {
client.authenticate_and_connect(false, &cx).await?;
}
} else {
if client.has_keychain_credentials(&cx) {
client.authenticate_and_connect(true, &cx).await?;
}
} else if client.has_keychain_credentials(&cx) {
client.authenticate_and_connect(true, &cx).await?;
}
Ok::<_, anyhow::Error>(())
})
@ -222,7 +220,9 @@ fn init_logger() {
let level = LevelFilter::Info;
// Prevent log file from becoming too large.
const MAX_LOG_BYTES: u64 = 1 * 1024 * 1024;
const KIB: u64 = 1024;
const MIB: u64 = 1024 * KIB;
const MAX_LOG_BYTES: u64 = MIB;
if fs::metadata(&*zed::paths::LOG).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES)
{
let _ = fs::rename(&*zed::paths::LOG, &*zed::paths::OLD_LOG);
@ -406,7 +406,7 @@ fn load_embedded_fonts(app: &App) {
for font_path in &font_paths {
scope.spawn(async {
let font_path = &*font_path;
let font_bytes = Assets.load(&font_path).unwrap().to_vec();
let font_bytes = Assets.load(font_path).unwrap().to_vec();
embedded_fonts.lock().push(Arc::from(font_bytes));
});
}
@ -426,7 +426,7 @@ async fn watch_themes(
let mut events = fs
.watch("styles/src".as_ref(), Duration::from_millis(100))
.await;
while let Some(_) = events.next().await {
while (events.next().await).is_some() {
let output = Command::new("npm")
.current_dir("styles")
.args(["run", "build-themes"])

View file

@ -42,11 +42,11 @@ where
///Loads the given watched JSON file. In the special case that the file is
///empty (ignoring whitespace) or is not a file, this will return T::default()
async fn load(fs: Arc<dyn Fs>, path: &Path) -> Option<T> {
if !fs.is_file(&path).await {
if !fs.is_file(path).await {
return Some(T::default());
}
fs.load(&path).await.log_err().and_then(|data| {
fs.load(path).await.log_err().and_then(|data| {
if data.trim().is_empty() {
Some(T::default())
} else {
@ -74,7 +74,7 @@ pub fn watch_settings_file(
pub fn keymap_updated(content: KeymapFileContent, cx: &mut MutableAppContext) {
cx.clear_bindings();
settings::KeymapFileContent::load_defaults(cx);
content.add(cx).log_err();
content.add_to_cx(cx).log_err();
}
pub fn settings_updated(
@ -84,7 +84,7 @@ pub fn settings_updated(
cx: &mut MutableAppContext,
) {
let mut settings = defaults.clone();
settings.set_user_settings(content, theme_registry, &cx.font_cache());
settings.set_user_settings(content, theme_registry, cx.font_cache());
cx.set_global(settings);
cx.refresh_windows();
}

View file

@ -143,7 +143,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
cx.add_action({
let app_state = app_state.clone();
move |_: &mut Workspace, _: &OpenKeymap, cx: &mut ViewContext<Workspace>| {
open_config_file(&paths::KEYMAP, app_state.clone(), cx, || Default::default());
open_config_file(&paths::KEYMAP, app_state.clone(), cx, Default::default);
}
});
cx.add_action({
@ -222,7 +222,7 @@ pub fn initialize_workspace(
pane.toolbar().update(cx, |toolbar, cx| {
let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(project.clone()));
toolbar.add_item(breadcrumbs, cx);
let buffer_search_bar = cx.add_view(|cx| BufferSearchBar::new(cx));
let buffer_search_bar = cx.add_view(BufferSearchBar::new);
toolbar.add_item(buffer_search_bar, cx);
let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
toolbar.add_item(project_search_bar, cx);
@ -273,7 +273,7 @@ pub fn initialize_workspace(
sidebar.add_item(
"icons/folder_tree_16.svg",
"Project Panel".to_string(),
project_panel.into(),
project_panel,
cx,
)
});
@ -281,7 +281,7 @@ pub fn initialize_workspace(
sidebar.add_item(
"icons/user_group_16.svg",
"Contacts Panel".to_string(),
contact_panel.into(),
contact_panel,
cx,
)
});
@ -487,7 +487,7 @@ fn open_bundled_config_file(
title: &str,
cx: &mut ViewContext<Workspace>,
) {
workspace.with_local_workspace(cx, app_state.clone(), |workspace, cx| {
workspace.with_local_workspace(cx, app_state, |workspace, cx| {
let project = workspace.project().clone();
let buffer = project.update(cx, |project, cx| {
let text = Assets::get(asset_path).unwrap().data;
@ -1005,7 +1005,7 @@ mod tests {
.insert_file("/root/a.txt", "changed".to_string())
.await;
editor
.condition(&cx, |editor, cx| editor.has_conflict(cx))
.condition(cx, |editor, cx| editor.has_conflict(cx))
.await;
cx.read(|cx| assert!(editor.is_dirty(cx)));
@ -1072,7 +1072,7 @@ mod tests {
// Edit the file and save it again. This time, there is no filename prompt.
editor.update(cx, |editor, cx| {
editor.handle_input(" there", cx);
assert_eq!(editor.is_dirty(cx.as_ref()), true);
assert!(editor.is_dirty(cx.as_ref()));
});
let save_task = workspace.update(cx, |workspace, cx| workspace.save_active_item(false, cx));
save_task.await.unwrap();
@ -1570,30 +1570,20 @@ mod tests {
// Reopen all the closed items, ensuring they are reopened in the same order
// in which they were closed.
workspace
.update(cx, |workspace, cx| Pane::reopen_closed_item(workspace, cx))
.await;
workspace.update(cx, Pane::reopen_closed_item).await;
assert_eq!(active_path(&workspace, cx), Some(file3.clone()));
workspace
.update(cx, |workspace, cx| Pane::reopen_closed_item(workspace, cx))
.await;
workspace.update(cx, Pane::reopen_closed_item).await;
assert_eq!(active_path(&workspace, cx), Some(file2.clone()));
workspace
.update(cx, |workspace, cx| Pane::reopen_closed_item(workspace, cx))
.await;
workspace.update(cx, Pane::reopen_closed_item).await;
assert_eq!(active_path(&workspace, cx), Some(file4.clone()));
workspace
.update(cx, |workspace, cx| Pane::reopen_closed_item(workspace, cx))
.await;
workspace.update(cx, Pane::reopen_closed_item).await;
assert_eq!(active_path(&workspace, cx), Some(file1.clone()));
// Reopening past the last closed item is a no-op.
workspace
.update(cx, |workspace, cx| Pane::reopen_closed_item(workspace, cx))
.await;
workspace.update(cx, Pane::reopen_closed_item).await;
assert_eq!(active_path(&workspace, cx), Some(file1.clone()));
// Reopening closed items doesn't interfere with navigation history.