From 2fa0a69f9ab7748b73c8e454f6eb259b6fff1d1b Mon Sep 17 00:00:00 2001 From: Jonathan Tran Date: Thu, 12 Nov 2026 15:56:17 -0500 Subject: [PATCH 1/2] Change rustfmt to import each item separately --- rustfmt.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustfmt.toml b/rustfmt.toml index 862b9f06..db855c71 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,5 +2,5 @@ max_width = 120 edition = "2024" format_code_in_doc_comments = true format_strings = false -imports_granularity = "Crate" +imports_granularity = "Item" group_imports = "StdExternalCrate" From 3925e8fb1c43f7c82f0ef760169febe5fceef365 Mon Sep 17 00:00:00 2001 From: Jonathan Tran Date: Thu, 12 Nov 2026 15:56:52 -0500 Subject: [PATCH 2/2] Format --- cli-macro-impl/src/lib.rs | 11 +++++-- src/build_kcl_project.rs | 13 +++++---- src/cmd_alias.rs | 9 +++--- src/cmd_api.rs | 15 +++++----- src/cmd_api_call.rs | 1 - src/cmd_app.rs | 1 - src/cmd_auth.rs | 4 +-- src/cmd_completion.rs | 7 +++-- src/cmd_config.rs | 10 +++++-- src/cmd_file.rs | 22 ++++++-------- src/cmd_generate.rs | 12 +++++--- src/cmd_kcl.rs | 34 ++++++++++++++-------- src/cmd_ml/cmd_kcl.rs | 4 +-- src/cmd_open.rs | 4 +-- src/cmd_org.rs | 17 ++++++----- src/cmd_project.rs | 22 +++++++------- src/cmd_say.rs | 1 - src/config.rs | 3 +- src/config_file.rs | 16 +++++----- src/config_from_file.rs | 3 +- src/config_map.rs | 3 +- src/context.rs | 61 ++++++++++++++++++++++++--------------- src/docs_markdown.rs | 3 +- src/iostreams.rs | 14 ++++++--- src/main.rs | 7 ++--- src/ml/copilot/run.rs | 53 +++++++++++++++++++--------------- src/ml/copilot/state.rs | 7 +++-- src/ml/copilot/ui.rs | 16 +++++++--- src/ml/copilot/util.rs | 4 ++- src/project.rs | 10 +++---- src/tests.rs | 10 +++++-- src/types.rs | 3 +- src/update.rs | 14 +++++---- tests/config_env.rs | 3 +- tests/kcl_process.rs | 8 ++--- tests/output_formats.rs | 29 ++++++++++--------- tests/win_ca_smoke.rs | 7 +++-- 37 files changed, 272 insertions(+), 189 deletions(-) diff --git a/cli-macro-impl/src/lib.rs b/cli-macro-impl/src/lib.rs index 2a4e1ef4..55c689cd 100644 --- a/cli-macro-impl/src/lib.rs +++ b/cli-macro-impl/src/lib.rs @@ -1,10 +1,15 @@ use std::collections::BTreeMap; use anyhow::Result; -use inflector::cases::{kebabcase::to_kebab_case, titlecase::to_title_case}; -use openapitor::types::exts::{ParameterExt, ParameterSchemaOrContentExt, ReferenceOrExt, TokenStreamExt}; +use inflector::cases::kebabcase::to_kebab_case; +use inflector::cases::titlecase::to_title_case; +use openapitor::types::exts::ParameterExt; +use openapitor::types::exts::ParameterSchemaOrContentExt; +use openapitor::types::exts::ReferenceOrExt; +use openapitor::types::exts::TokenStreamExt; use proc_macro2::TokenStream; -use quote::{format_ident, quote}; +use quote::format_ident; +use quote::quote; use serde::Deserialize; use serde_tokenstream::from_tokenstream; use syn::ItemEnum; diff --git a/src/build_kcl_project.rs b/src/build_kcl_project.rs index 920560dc..608e5799 100644 --- a/src/build_kcl_project.rs +++ b/src/build_kcl_project.rs @@ -1,12 +1,13 @@ //! This module reads a KCL project from disk into memory, so it can be sent over the network. use std::env::current_dir; -use anyhow::{Result, anyhow}; -use camino::{Utf8Path, Utf8PathBuf}; -use kittycad_modeling_cmds::{ - exec_kcl::{KclFile, KclProject}, - shared::safe_filepath::SafeFilepath, -}; +use anyhow::Result; +use anyhow::anyhow; +use camino::Utf8Path; +use camino::Utf8PathBuf; +use kittycad_modeling_cmds::exec_kcl::KclFile; +use kittycad_modeling_cmds::exec_kcl::KclProject; +use kittycad_modeling_cmds::shared::safe_filepath::SafeFilepath; const FILES_TO_SEND_TO_ENGINE: [&str; 18] = [ "kcl", "fbx", "glb", "gltf", "obj", "ply", "step", "stl", "sat", "sab", "model", "catpart", "ipt", "prt", "xpr", diff --git a/src/cmd_alias.rs b/src/cmd_alias.rs index 601a5ccd..bb7d0308 100644 --- a/src/cmd_alias.rs +++ b/src/cmd_alias.rs @@ -1,7 +1,10 @@ use std::io::Write; -use anyhow::{Result, bail}; -use clap::{Command, CommandFactory, Parser}; +use anyhow::Result; +use anyhow::bail; +use clap::Command; +use clap::CommandFactory; +use clap::Parser; /// Create command shortcuts. /// @@ -37,7 +40,6 @@ impl crate::cmd::Command for CmdAlias { /// ```shell /// zoo alias delete aabb_mm /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdAliasDelete { @@ -99,7 +101,6 @@ impl crate::cmd::Command for CmdAliasDelete { /// zoo alias set aabb_mm "kcl bounding-box $1 --output-unit mm" /// zoo aabb_mm my-file.kcl /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdAliasSet { diff --git a/src/cmd_api.rs b/src/cmd_api.rs index 3e27ccb7..48d143e4 100644 --- a/src/cmd_api.rs +++ b/src/cmd_api.rs @@ -1,13 +1,14 @@ -use std::{ - collections::HashMap, - fmt::Write as _, - io::{Read, Write}, -}; +use std::collections::HashMap; +use std::fmt::Write as _; +use std::io::Read; +use std::io::Write; -use anyhow::{Result, anyhow}; +use anyhow::Result; +use anyhow::anyhow; use clap::Parser; use reqwest::header::CONTENT_TYPE; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; /// Makes an authenticated HTTP request to the Zoo API and prints the response. /// diff --git a/src/cmd_api_call.rs b/src/cmd_api_call.rs index 4877db1f..ef8cb08b 100644 --- a/src/cmd_api_call.rs +++ b/src/cmd_api_call.rs @@ -10,7 +10,6 @@ use itertools::Itertools; /// # convert a step file to an obj file /// zoo file convert ~/Downloads/cube.step ~/Downloads --output-format obj /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdApiCall { diff --git a/src/cmd_app.rs b/src/cmd_app.rs index c73db5da..b477fae8 100644 --- a/src/cmd_app.rs +++ b/src/cmd_app.rs @@ -26,7 +26,6 @@ an issue at https://github.com/KittyCAD/cli/issues/new"#; /// ```shell /// zoo app ../main.kcl /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdApp { diff --git a/src/cmd_auth.rs b/src/cmd_auth.rs index e7c8ba9c..ecb25d0d 100644 --- a/src/cmd_auth.rs +++ b/src/cmd_auth.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; -use anyhow::{Result, anyhow}; +use anyhow::Result; +use anyhow::anyhow; use clap::Parser; use oauth2::TokenResponse; @@ -306,7 +307,6 @@ impl crate::cmd::Command for CmdAuthLogin { /// zoo --host api.zoo.dev auth logout /// # => log out of specified host /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdAuthLogout {} diff --git a/src/cmd_completion.rs b/src/cmd_completion.rs index 9c0c3da0..063517fd 100644 --- a/src/cmd_completion.rs +++ b/src/cmd_completion.rs @@ -1,6 +1,9 @@ use anyhow::Result; -use clap::{Command, CommandFactory, Parser}; -use clap_complete::{Shell, generate}; +use clap::Command; +use clap::CommandFactory; +use clap::Parser; +use clap_complete::Shell; +use clap_complete::generate; /// Generate shell completion scripts. /// diff --git a/src/cmd_config.rs b/src/cmd_config.rs index d6967b22..38067af3 100644 --- a/src/cmd_config.rs +++ b/src/cmd_config.rs @@ -1,7 +1,9 @@ -use anyhow::{Result, bail}; +use anyhow::Result; +use anyhow::bail; use clap::Parser; -use crate::config::{CONFIG_OPTIONS, ConfigOption}; +use crate::config::CONFIG_OPTIONS; +use crate::config::ConfigOption; // TODO: make this doc a function that parses from the config the options so it's not hardcoded /// Manage configuration for `zoo`. @@ -171,7 +173,9 @@ impl crate::cmd::Command for CmdConfigList { mod test { use pretty_assertions::assert_eq; - use crate::{cmd::Command, config, config::Config}; + use crate::cmd::Command; + use crate::config; + use crate::config::Config; pub struct TestItem { name: String, diff --git a/src/cmd_file.rs b/src/cmd_file.rs index 644a002c..d08d2c88 100644 --- a/src/cmd_file.rs +++ b/src/cmd_file.rs @@ -1,15 +1,16 @@ -use std::{ - hash::{DefaultHasher, Hash, Hasher}, - str::FromStr, -}; +use std::hash::DefaultHasher; +use std::hash::Hash; +use std::hash::Hasher; +use std::str::FromStr; use anyhow::Result; use base64::prelude::*; use clap::Parser; -use kittycad_modeling_cmds::{ - self as kcmc, ModelingCmd, ok_response::OkModelingCmdResponse, shared::FileImportFormat, - websocket::OkWebSocketResponseData, -}; +use kittycad_modeling_cmds::ModelingCmd; +use kittycad_modeling_cmds::ok_response::OkModelingCmdResponse; +use kittycad_modeling_cmds::shared::FileImportFormat; +use kittycad_modeling_cmds::websocket::OkWebSocketResponseData; +use kittycad_modeling_cmds::{self as kcmc}; use crate::cmd_kcl::write_deterministic_export; @@ -19,7 +20,6 @@ use crate::cmd_kcl::write_deterministic_export; /// # convert a step file to an obj file /// zoo file convert --output-format=obj ./input.step ./ /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdFile { @@ -75,7 +75,6 @@ impl crate::cmd::Command for CmdFile { /// # when converting from stdin, the original file type is required /// cat my-obj.obj | zoo file convert --output-format=step --src-format=obj - output_dir /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdFileConvert { @@ -183,7 +182,6 @@ impl crate::cmd::Command for CmdFileConvert { /// # pass a file to snapshot from stdin /// cat my-obj.obj | zoo file snapshot --output-format=png --src-format=obj - my-file.png /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdFileSnapshot { @@ -611,7 +609,6 @@ impl crate::cmd::Command for CmdFileCenterOfMass { /// # pass a file from stdin, the original file type is required /// cat my-obj.obj | zoo file density - --src-format=obj -material-mass 212.2923 --material-mass-unit g --output-unit kg-m3 /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdFileDensity { @@ -695,7 +692,6 @@ impl crate::cmd::Command for CmdFileDensity { /// # pass a file from stdin, the original file type is required /// cat my-obj.obj | zoo file surface-area - --src-format=obj --output-unit m2 /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdFileSurfaceArea { diff --git a/src/cmd_generate.rs b/src/cmd_generate.rs index a93205cf..db1946be 100644 --- a/src/cmd_generate.rs +++ b/src/cmd_generate.rs @@ -1,7 +1,11 @@ -use std::{fs, io::Write}; - -use anyhow::{Context, Result}; -use clap::{Command, CommandFactory, Parser}; +use std::fs; +use std::io::Write; + +use anyhow::Context; +use anyhow::Result; +use clap::Command; +use clap::CommandFactory; +use clap::Parser; /// Generate various documentation files for the `zoo` command line. #[derive(Parser, Debug, Clone)] diff --git a/src/cmd_kcl.rs b/src/cmd_kcl.rs index ba708a2b..6f91e074 100644 --- a/src/cmd_kcl.rs +++ b/src/cmd_kcl.rs @@ -1,19 +1,27 @@ -use std::{net::SocketAddr, path::Path, str::FromStr}; +use std::net::SocketAddr; +use std::path::Path; +use std::str::FromStr; use anyhow::Result; use clap::Parser; -use image::{DynamicImage, ImageReader}; -use kcl_lib::{ToLspRange, TypedPath, unit_conversion::ToKcmc}; -use kcmc::{format::OutputFormat3d as OutputFormat, ok_response::OkModelingCmdResponse}; +use image::DynamicImage; +use image::ImageReader; +use kcl_lib::ToLspRange; +use kcl_lib::TypedPath; +use kcl_lib::unit_conversion::ToKcmc; +use kcmc::format::OutputFormat3d as OutputFormat; +use kcmc::ok_response::OkModelingCmdResponse; use kittycad::types as kt; -use kittycad_modeling_cmds::{self as kcmc, units::UnitLength, websocket::ModelingSessionData}; +use kittycad_modeling_cmds::units::UnitLength; +use kittycad_modeling_cmds::websocket::ModelingSessionData; +use kittycad_modeling_cmds::{self as kcmc}; use url::Url; -use crate::{ - iostreams::IoStreams, - kcl_error_fmt, - types::{CameraStyle, CameraView, FormatOutput}, -}; +use crate::iostreams::IoStreams; +use crate::kcl_error_fmt; +use crate::types::CameraStyle; +use crate::types::CameraView; +use crate::types::FormatOutput; mod camera_angles; @@ -213,7 +221,6 @@ impl crate::cmd::Command for CmdKclExport { /// # Pass a file to format from stdin /// cat my-obj.kcl | zoo kcl fmt - /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdKclFormat { @@ -1986,7 +1993,10 @@ fn combine_quadrants( output_path: &Path, output_format: kcmc::ImageFormat, ) -> Result<()> { - use image::{GenericImage, GenericImageView, ImageBuffer, Rgba}; + use image::GenericImage; + use image::GenericImageView; + use image::ImageBuffer; + use image::Rgba; let (w, h) = top_left.dimensions(); // Sanity checks diff --git a/src/cmd_ml/cmd_kcl.rs b/src/cmd_ml/cmd_kcl.rs index 4ca2d56f..c7df0700 100644 --- a/src/cmd_ml/cmd_kcl.rs +++ b/src/cmd_ml/cmd_kcl.rs @@ -1,4 +1,5 @@ -use anyhow::{Context, Result}; +use anyhow::Context; +use anyhow::Result; use clap::Parser; /// KCL machine learning commands. @@ -30,7 +31,6 @@ impl crate::cmd::Command for CmdKcl { /// ```shell /// zoo ml kcl copilot /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdKclCopilot { diff --git a/src/cmd_open.rs b/src/cmd_open.rs index 51cde6a9..f0905480 100644 --- a/src/cmd_open.rs +++ b/src/cmd_open.rs @@ -1,6 +1,7 @@ use anyhow::Result; use clap::Parser; -use parse_display::{Display, FromStr}; +use parse_display::Display; +use parse_display::FromStr; /// Shortcut to open the Zoo documentation or Account in your browser. /// @@ -15,7 +16,6 @@ use parse_display::{Display, FromStr}; /// # open your Zoo account in your browser /// zoo open account /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdOpen { diff --git a/src/cmd_org.rs b/src/cmd_org.rs index 6854f65b..10fda014 100644 --- a/src/cmd_org.rs +++ b/src/cmd_org.rs @@ -1,11 +1,12 @@ -use std::{ - collections::{HashMap, HashSet}, - fs, - io::Write, - path::{Path, PathBuf}, -}; - -use anyhow::{Context as _, Result}; +use std::collections::HashMap; +use std::collections::HashSet; +use std::fs; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; + +use anyhow::Context as _; +use anyhow::Result; use clap::Parser; use crate::types::FormatOutput; diff --git a/src/cmd_project.rs b/src/cmd_project.rs index c6a79161..be1767d8 100644 --- a/src/cmd_project.rs +++ b/src/cmd_project.rs @@ -1,11 +1,11 @@ -use std::{ - collections::HashSet, - future::Future, - io::Write, - path::{Path, PathBuf}, -}; - -use anyhow::{Context as _, Result}; +use std::collections::HashSet; +use std::future::Future; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; + +use anyhow::Context as _; +use anyhow::Result; use clap::Parser; use crate::types::FormatOutput; @@ -588,9 +588,11 @@ mod tests { command: &CmdProject, responses: Vec>, ) -> (Result<()>, String, Vec) { - use tokio::io::{AsyncBufReadExt, AsyncWriteExt}; + use tokio::io::AsyncBufReadExt; + use tokio::io::AsyncWriteExt; - use crate::{cmd::Command, config::Config}; + use crate::cmd::Command; + use crate::config::Config; let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); let host = format!("http://{}/custom-api", listener.local_addr().unwrap()); diff --git a/src/cmd_say.rs b/src/cmd_say.rs index b9e30c01..839b802a 100644 --- a/src/cmd_say.rs +++ b/src/cmd_say.rs @@ -8,7 +8,6 @@ use clap::Parser; /// zoo say hello! /// zoo say Hello World! /// ``` -/// #[derive(Parser, Debug, Clone)] #[clap(verbatim_doc_comment)] pub struct CmdSay { diff --git a/src/config.rs b/src/config.rs index dadf01c9..b16a455f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,7 @@ use std::fmt::Write; -use anyhow::{Result, anyhow}; +use anyhow::Result; +use anyhow::anyhow; use thiserror::Error; /// This trait describes interaction with the configuration for `zoo`. diff --git a/src/config_file.rs b/src/config_file.rs index e66f9321..f9706a58 100644 --- a/src/config_file.rs +++ b/src/config_file.rs @@ -1,10 +1,12 @@ -use std::{ - env, fs, - io::Write, - path::{Path, PathBuf}, -}; - -use anyhow::{Context, Result, anyhow}; +use std::env; +use std::fs; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; + +use anyhow::Context; +use anyhow::Result; +use anyhow::anyhow; const ZOO_CONFIG_DIR: &str = "ZOO_CONFIG_DIR"; const XDG_CONFIG_HOME: &str = "XDG_CONFIG_HOME"; diff --git a/src/config_from_file.rs b/src/config_from_file.rs index 56c12ea0..16859662 100644 --- a/src/config_from_file.rs +++ b/src/config_from_file.rs @@ -1,4 +1,5 @@ -use anyhow::{Result, anyhow}; +use anyhow::Result; +use anyhow::anyhow; use crate::config_alias::AliasConfig; diff --git a/src/config_map.rs b/src/config_map.rs index 25712ae2..35847e48 100644 --- a/src/config_map.rs +++ b/src/config_map.rs @@ -1,4 +1,5 @@ -use anyhow::{Result, anyhow}; +use anyhow::Result; +use anyhow::anyhow; // ConfigMap implements a low-level get/set config that is backed by an in-memory tree of toml // nodes. It allows us to interact with a toml-based config programmatically, preserving any diff --git a/src/context.rs b/src/context.rs index bf9f4dba..e724a4fb 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,27 +1,38 @@ -use std::{path::Path, str::FromStr, time::Duration}; +use std::path::Path; +use std::str::FromStr; +use std::time::Duration; -use anyhow::{Result, anyhow}; +use anyhow::Result; +use anyhow::anyhow; use camino::Utf8Path; -use futures::{SinkExt, StreamExt}; -use kcl_lib::{KclRuntimeFlags, RuntimeFlag, engine_connection::EngineManager}; -use kittycad_modeling_cmds::{ - ModelingCmd, ToggleGraphics, each_cmd as mcmd, - id::ModelingCmdId, - output::TakeSnapshot, - websocket::{ - FailureWebSocketResponse, ModelingCmdReq, ModelingSessionData, OkWebSocketResponseData, RawFile, - SuccessWebSocketResponse, WebSocketRequest, WebSocketResponse, - }, -}; -use tokio_tungstenite::{ - WebSocketStream, - tungstenite::{Message as WsMsg, protocol::Role}, -}; - -use crate::{ - build_kcl_project::build_kcl_project, cmd_kcl, config::Config, config_file::get_env_var, kcl_error_fmt, - types::FormatOutput, -}; +use futures::SinkExt; +use futures::StreamExt; +use kcl_lib::KclRuntimeFlags; +use kcl_lib::RuntimeFlag; +use kcl_lib::engine_connection::EngineManager; +use kittycad_modeling_cmds::ModelingCmd; +use kittycad_modeling_cmds::ToggleGraphics; +use kittycad_modeling_cmds::each_cmd as mcmd; +use kittycad_modeling_cmds::id::ModelingCmdId; +use kittycad_modeling_cmds::output::TakeSnapshot; +use kittycad_modeling_cmds::websocket::FailureWebSocketResponse; +use kittycad_modeling_cmds::websocket::ModelingCmdReq; +use kittycad_modeling_cmds::websocket::ModelingSessionData; +use kittycad_modeling_cmds::websocket::OkWebSocketResponseData; +use kittycad_modeling_cmds::websocket::RawFile; +use kittycad_modeling_cmds::websocket::SuccessWebSocketResponse; +use kittycad_modeling_cmds::websocket::WebSocketRequest; +use kittycad_modeling_cmds::websocket::WebSocketResponse; +use tokio_tungstenite::WebSocketStream; +use tokio_tungstenite::tungstenite::Message as WsMsg; +use tokio_tungstenite::tungstenite::protocol::Role; + +use crate::build_kcl_project::build_kcl_project; +use crate::cmd_kcl; +use crate::config::Config; +use crate::config_file::get_env_var; +use crate::kcl_error_fmt; +use crate::types::FormatOutput; type DirectWs = WebSocketStream; type DirectWsRead = futures::stream::SplitStream; @@ -1012,7 +1023,8 @@ fn websocket_failure_to_anyhow(response: WebSocketResponse) -> anyhow::Error { #[cfg(test)] mod test { - use std::{collections::HashMap, sync::Arc}; + use std::collections::HashMap; + use std::sync::Arc; use pretty_assertions::assert_eq; @@ -1292,7 +1304,8 @@ mod test { } async fn assert_local_kcl_handshake(host_source: &str, version: &str, statuses: Vec) { - use tokio::io::{AsyncBufReadExt, AsyncWriteExt}; + use tokio::io::AsyncBufReadExt; + use tokio::io::AsyncWriteExt; let expected_requests = statuses.len(); let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); diff --git a/src/docs_markdown.rs b/src/docs_markdown.rs index 2ede4ead..31b6574f 100644 --- a/src/docs_markdown.rs +++ b/src/docs_markdown.rs @@ -328,10 +328,11 @@ pub fn app_to_markdown(app: &Command, title: &str) -> Result { #[cfg(test)] mod test { + use pretty_assertions::assert_eq; + use super::LanguageCodeBlock; use super::cleanup_code_blocks; use super::language_and_code; - use pretty_assertions::assert_eq; fn definition_descriptions(markdown: &str) -> Vec<&str> { let mut descriptions = Vec::new(); diff --git a/src/iostreams.rs b/src/iostreams.rs index 48c6eaf4..bbb39b1a 100644 --- a/src/iostreams.rs +++ b/src/iostreams.rs @@ -1,7 +1,13 @@ -use std::{collections::HashMap, env, io::IsTerminal, process::Command}; - -use anyhow::{Result, anyhow}; -use terminal_size::{Height, Width, terminal_size}; +use std::collections::HashMap; +use std::env; +use std::io::IsTerminal; +use std::process::Command; + +use anyhow::Result; +use anyhow::anyhow; +use terminal_size::Height; +use terminal_size::Width; +use terminal_size::terminal_size; use crate::config_file::get_env_var; diff --git a/src/main.rs b/src/main.rs index c7462482..7849477e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,10 +66,9 @@ mod tests; mod update; -use std::{ - error::Error as StdError, - io::{Read, Write}, -}; +use std::error::Error as StdError; +use std::io::Read; +use std::io::Write; use anyhow::Result; use clap::Parser; diff --git a/src/ml/copilot/run.rs b/src/ml/copilot/run.rs index d2f853c5..386bd6f1 100644 --- a/src/ml/copilot/run.rs +++ b/src/ml/copilot/run.rs @@ -1,32 +1,37 @@ -use std::{ - io::Write as _, - path::{Path, PathBuf}, -}; +use std::io::Write as _; +use std::path::Path; +use std::path::PathBuf; use anyhow::Result; -use crossterm::{ - cursor::MoveTo, - event::{Event, EventStream}, - execute, queue, - terminal::{ClearType, EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode}, -}; -use futures::{SinkExt, StreamExt}; +use crossterm::cursor::MoveTo; +use crossterm::event::Event; +use crossterm::event::EventStream; +use crossterm::execute; +use crossterm::queue; +use crossterm::terminal::ClearType; +use crossterm::terminal::EnterAlternateScreen; +use crossterm::terminal::LeaveAlternateScreen; +use crossterm::terminal::disable_raw_mode; +use crossterm::terminal::enable_raw_mode; +use futures::SinkExt; +use futures::StreamExt; use kcl_lib::TypedPath; use log::LevelFilter; -use ratatui::{Terminal, backend::CrosstermBackend}; +use ratatui::Terminal; +use ratatui::backend::CrosstermBackend; use similar::TextDiff; use tokio::sync::mpsc; -use tokio_tungstenite::{ - WebSocketStream, - tungstenite::{Message, protocol::Role}, -}; +use tokio_tungstenite::WebSocketStream; +use tokio_tungstenite::tungstenite::Message; +use tokio_tungstenite::tungstenite::protocol::Role; -use crate::ml::copilot::{ - state, - state::{App, ChatEvent, KeyAction}, - ui::draw, - util::{join_secure, scan_relevant_files}, -}; +use crate::ml::copilot::state; +use crate::ml::copilot::state::App; +use crate::ml::copilot::state::ChatEvent; +use crate::ml::copilot::state::KeyAction; +use crate::ml::copilot::ui::draw; +use crate::ml::copilot::util::join_secure; +use crate::ml::copilot::util::scan_relevant_files; const PAYLOAD_LOG_LIMIT: usize = 10_000; @@ -700,7 +705,9 @@ async fn render_side_by_side( host: &str, edits: &[state::PendingFileEdit], ) -> anyhow::Result { - use kittycad_modeling_cmds::{ImageFormat, ModelingCmd, TakeSnapshot}; + use kittycad_modeling_cmds::ImageFormat; + use kittycad_modeling_cmds::ModelingCmd; + use kittycad_modeling_cmds::TakeSnapshot; // Determine old code and path from current directory let (old_code, old_main_path) = ctx.get_code_and_file_path(&std::path::PathBuf::from(".")).await?; let old_settings = crate::cmd_kcl::get_modeling_settings_from_project_toml(&old_main_path)?; diff --git a/src/ml/copilot/state.rs b/src/ml/copilot/state.rs index e4e66af3..96501c42 100644 --- a/src/ml/copilot/state.rs +++ b/src/ml/copilot/state.rs @@ -1,7 +1,10 @@ use std::collections::VecDeque; -use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; -use serde::{Deserialize, Serialize}; +use crossterm::event::KeyCode; +use crossterm::event::KeyEvent; +use crossterm::event::KeyModifiers; +use serde::Deserialize; +use serde::Serialize; #[derive(Debug, Default, Clone)] pub struct App { diff --git a/src/ml/copilot/ui.rs b/src/ml/copilot/ui.rs index 6610befe..e66ae2cc 100644 --- a/src/ml/copilot/ui.rs +++ b/src/ml/copilot/ui.rs @@ -1,6 +1,8 @@ -use ratatui::{prelude::*, widgets::*}; +use ratatui::prelude::*; +use ratatui::widgets::*; -use super::state::{App, ChatEvent}; +use super::state::App; +use super::state::ChatEvent; const ASSISTANT_LABEL: &str = "ML-ephant> "; const ASSISTANT_INDENT: &str = " "; // 4 spaces for a pleasant left gutter @@ -40,7 +42,12 @@ fn render_preserving_newlines(s: &str) -> Vec { } fn render_markdown_to_lines(md: &str) -> Vec { - use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag, TagEnd}; + use pulldown_cmark::CodeBlockKind; + use pulldown_cmark::Event; + use pulldown_cmark::Options; + use pulldown_cmark::Parser; + use pulldown_cmark::Tag; + use pulldown_cmark::TagEnd; let mut lines: Vec = Vec::new(); let mut cur = String::new(); let mut list_prefix = String::new(); @@ -310,7 +317,8 @@ pub fn draw(frame: &mut Frame, app: &App) { #[cfg(test)] mod tests { - use ratatui::{Terminal, backend::TestBackend}; + use ratatui::Terminal; + use ratatui::backend::TestBackend; use super::*; diff --git a/src/ml/copilot/util.rs b/src/ml/copilot/util.rs index 1471bdd0..82660ae2 100644 --- a/src/ml/copilot/util.rs +++ b/src/ml/copilot/util.rs @@ -1,5 +1,7 @@ // keep Result import only when used -use std::path::{Component, Path, PathBuf}; +use std::path::Component; +use std::path::Path; +use std::path::PathBuf; #[allow(unused_imports)] use anyhow::Result; diff --git a/src/project.rs b/src/project.rs index ce145ada..7e7f9b05 100644 --- a/src/project.rs +++ b/src/project.rs @@ -1,9 +1,9 @@ -use std::{ - collections::VecDeque, - path::{Path, PathBuf}, -}; +use std::collections::VecDeque; +use std::path::Path; +use std::path::PathBuf; -use anyhow::{Context as _, Result}; +use anyhow::Context as _; +use anyhow::Result; pub struct LocalProject { pub root: PathBuf, diff --git a/src/tests.rs b/src/tests.rs index 7035115d..d0856069 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,7 +1,9 @@ -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; use anyhow::Result; -use test_context::{AsyncTestContext, test_context}; +use test_context::AsyncTestContext; +use test_context::test_context; use crate::config::Config; @@ -17,7 +19,9 @@ macro_rules! svec { /// if the CLI is supposed to output json/yaml. #[test] fn status_output_respects_format() -> Result<()> { - use crate::types::FormatOutput::{Json, Table, Yaml}; + use crate::types::FormatOutput::Json; + use crate::types::FormatOutput::Table; + use crate::types::FormatOutput::Yaml; enum WrittenTo { Stdout, diff --git a/src/types.rs b/src/types.rs index d403dd73..b82a2c07 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,5 @@ -use parse_display::{Display, FromStr}; +use parse_display::Display; +use parse_display::FromStr; use serde::Deserialize; #[derive(Debug, Clone, PartialEq, Eq, FromStr, Display, clap::ValueEnum)] diff --git a/src/update.rs b/src/update.rs index 1ff1c7c6..56cbedfc 100644 --- a/src/update.rs +++ b/src/update.rs @@ -1,12 +1,14 @@ +use std::fs; +use std::io::IsTerminal; +use std::io::Write; #[cfg(target_family = "unix")] use std::os::unix::fs::PermissionsExt; -use std::{ - fs, - io::{IsTerminal, Write}, -}; -use anyhow::{Context, Result, anyhow}; -use serde::{Deserialize, Serialize}; +use anyhow::Context; +use anyhow::Result; +use anyhow::anyhow; +use serde::Deserialize; +use serde::Serialize; use crate::config_file::get_env_var; diff --git a/tests/config_env.rs b/tests/config_env.rs index 3b8172a5..0efd9dfa 100644 --- a/tests/config_env.rs +++ b/tests/config_env.rs @@ -1,4 +1,5 @@ -use std::{path::Path, process::Command}; +use std::path::Path; +use std::process::Command; fn run_config(config_dir: &Path, args: &[&str], host: Option<&str>) -> String { let mut cmd = Command::new(env!("CARGO_BIN_EXE_zoo")); diff --git a/tests/kcl_process.rs b/tests/kcl_process.rs index c83e0c0b..2eb8d4c9 100644 --- a/tests/kcl_process.rs +++ b/tests/kcl_process.rs @@ -16,10 +16,10 @@ //! pure CLI/config behavior that can be tested with injected values or in-memory //! config. -use std::{ - path::{Path, PathBuf}, - process::{Command, Output}, -}; +use std::path::Path; +use std::path::PathBuf; +use std::process::Command; +use std::process::Output; const ANALYZE_CUBE_KCL: &str = r#"@settings(kclVersion = 2.0) diff --git a/tests/output_formats.rs b/tests/output_formats.rs index 0de175da..06ae0db6 100644 --- a/tests/output_formats.rs +++ b/tests/output_formats.rs @@ -1,19 +1,22 @@ //! Exercise output selection through the CLI with local HTTP/WebSocket servers. -use std::{path::Path, process::Output, time::Duration}; +use std::path::Path; +use std::process::Output; +use std::time::Duration; -use futures::{SinkExt, StreamExt}; -use kittycad_modeling_cmds::{ - ModelingCmd, - exec_kcl::ExecKclProjectOk, - websocket::{OkWebSocketResponseData, SuccessWebSocketResponse, WebSocketRequest}, -}; -use serde_json::{Value, json}; -use tokio::{ - io::{AsyncReadExt, AsyncWriteExt}, - net::TcpListener, - process::Command, -}; +use futures::SinkExt; +use futures::StreamExt; +use kittycad_modeling_cmds::ModelingCmd; +use kittycad_modeling_cmds::exec_kcl::ExecKclProjectOk; +use kittycad_modeling_cmds::websocket::OkWebSocketResponseData; +use kittycad_modeling_cmds::websocket::SuccessWebSocketResponse; +use kittycad_modeling_cmds::websocket::WebSocketRequest; +use serde_json::Value; +use serde_json::json; +use tokio::io::AsyncReadExt; +use tokio::io::AsyncWriteExt; +use tokio::net::TcpListener; +use tokio::process::Command; use tokio_tungstenite::tungstenite::Message; const CALL_ID: &str = "8fea640b-1257-4b44-94b3-66061dd2f3dc"; diff --git a/tests/win_ca_smoke.rs b/tests/win_ca_smoke.rs index bdd9981c..a07d395c 100644 --- a/tests/win_ca_smoke.rs +++ b/tests/win_ca_smoke.rs @@ -1,7 +1,10 @@ use std::time::Duration; -use anyhow::{Context, Result, anyhow}; -use tokio::{process::Command, time::sleep}; +use anyhow::Context; +use anyhow::Result; +use anyhow::anyhow; +use tokio::process::Command; +use tokio::time::sleep; use url::Url; #[cfg_attr(not(target_os = "windows"), ignore)]