Skip to content

Commit

Permalink
Change imports granularity
Browse files Browse the repository at this point in the history
  • Loading branch information
doonv committed Jan 7, 2024
1 parent 14ea537 commit e27c71a
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 101 deletions.
6 changes: 2 additions & 4 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! A simple example
use bevy::{
log::{Level, LogPlugin},
prelude::*,
};
use bevy::log::{Level, LogPlugin};
use bevy::prelude::*;
use bevy_dev_console::prelude::*;

fn main() {
Expand Down
14 changes: 5 additions & 9 deletions examples/custom_functions.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
//! A simple exmaple
use bevy::{
log::{Level, LogPlugin},
prelude::*,
};
use bevy_dev_console::{
builtin_parser::{Environment, Number, RunError, Spanned, StrongRef, Value},
prelude::*,
register,
};
use bevy::log::{Level, LogPlugin};
use bevy::prelude::*;
use bevy_dev_console::builtin_parser::{Environment, Number, RunError, Spanned, StrongRef, Value};
use bevy_dev_console::prelude::*;
use bevy_dev_console::register;

// Declare the functions we want to create:

Expand Down
3 changes: 2 additions & 1 deletion examples/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//!
//! **Warning:** This is very experimental, might not work.
use bevy::{log::LogPlugin, prelude::*};
use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy_dev_console::prelude::*;

#[derive(Resource, Reflect, Default, Debug)]
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
imports_granularity = "Module"
8 changes: 6 additions & 2 deletions src/builtin_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ use logos::Span;

use crate::command::{CommandParser, DefaultCommandParser};

use self::{lexer::TokenStream, parser::parse};
use self::lexer::TokenStream;
use self::parser::parse;

pub(crate) mod lexer;
pub(crate) mod number;
pub(crate) mod parser;
pub(crate) mod runner;

pub use number::*;
pub use runner::{environment::Environment, error::RunError, unique_rc::*, Value};
pub use runner::environment::Environment;
pub use runner::error::RunError;
pub use runner::unique_rc::*;
pub use runner::Value;

/// Additonal traits for span.
pub trait SpanExtension {
Expand Down
20 changes: 9 additions & 11 deletions src/builtin_parser/parser.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//! Generates an abstract syntax tree from a list of tokens.
use logos::Span;
use std::{collections::HashMap, num::IntErrorKind};
use std::collections::HashMap;
use std::num::IntErrorKind;

use super::{
lexer::{FailedToLexCharacter, Token, TokenStream},
number::Number,
runner::environment::Function,
Environment, Spanned,
};
use super::lexer::{FailedToLexCharacter, Token, TokenStream};
use super::number::Number;
use super::runner::environment::Function;
use super::{Environment, Spanned};

/// An [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree).
///
Expand Down Expand Up @@ -456,10 +455,9 @@ fn parse_object(

#[cfg(test)]
mod tests {
use super::{
super::{lexer::TokenStream, Environment},
parse,
};
use super::super::lexer::TokenStream;
use super::super::Environment;
use super::parse;

#[test]
fn var_assign() {
Expand Down
31 changes: 14 additions & 17 deletions src/builtin_parser/runner.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
//! Executes the abstract syntax tree.
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;

use environment::Environment;

use crate::{command::CommandHints, ui::COMMAND_RESULT_NAME};

use self::{
error::RunError,
reflection::{object_to_dynamic_struct, CreateRegistration, IntoResource},
unique_rc::{UniqueRc, WeakRef},
};

use super::{
parser::{Ast, Expression, Operator},
Number, SpanExtension, Spanned,
};
use bevy::{
prelude::*,
reflect::{DynamicEnum, ReflectMut, TypeInfo, TypeRegistration, VariantInfo},
};
use crate::command::CommandHints;
use crate::ui::COMMAND_RESULT_NAME;

use self::error::RunError;
use self::reflection::{object_to_dynamic_struct, CreateRegistration, IntoResource};
use self::unique_rc::{UniqueRc, WeakRef};

use super::parser::{Ast, Expression, Operator};
use super::{Number, SpanExtension, Spanned};
use bevy::prelude::*;
use bevy::reflect::{DynamicEnum, ReflectMut, TypeInfo, TypeRegistration, VariantInfo};

pub mod environment;
pub mod error;
Expand Down
19 changes: 10 additions & 9 deletions src/builtin_parser/runner/environment.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
//! Environment and function registeration
use std::{collections::HashMap, fmt::Debug};
use std::collections::HashMap;
use std::fmt::Debug;

use bevy::{ecs::world::World, log::warn, reflect::TypeRegistration};
use bevy::ecs::world::World;
use bevy::log::warn;
use bevy::reflect::TypeRegistration;
use logos::Span;

use crate::builtin_parser::SpanExtension;

use super::{
super::{parser::Expression, Spanned},
error::RunError,
eval_expression, stdlib,
unique_rc::UniqueRc,
EvalParams, Value,
};
use super::super::parser::Expression;
use super::super::Spanned;
use super::error::RunError;
use super::unique_rc::UniqueRc;
use super::{eval_expression, stdlib, EvalParams, Value};

/// Macro for mass registering functions.
///
Expand Down
7 changes: 3 additions & 4 deletions src/builtin_parser/runner/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::borrow::Cow;

use logos::Span;

use crate::{
builtin_parser::{number::Number, Spanned},
command::{CommandHint, CommandHintColor},
};
use crate::builtin_parser::number::Number;
use crate::builtin_parser::Spanned;
use crate::command::{CommandHint, CommandHintColor};

use super::Value;

Expand Down
9 changes: 4 additions & 5 deletions src/builtin_parser/runner/reflection.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{any::TypeId, collections::HashMap};
use std::any::TypeId;
use std::collections::HashMap;

use bevy::{
prelude::*,
reflect::{DynamicStruct, ReflectFromPtr, TypeRegistration},
};
use bevy::prelude::*;
use bevy::reflect::{DynamicStruct, ReflectFromPtr, TypeRegistration};

use super::Value;

Expand Down
13 changes: 9 additions & 4 deletions src/builtin_parser/runner/stdlib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use crate::{builtin_parser::runner::environment::Variable, register};
use bevy::{ecs::world::World, log::info, reflect::TypeRegistration};
use std::{cell::Ref, ops::Range};
use crate::builtin_parser::runner::environment::Variable;
use crate::register;
use bevy::ecs::world::World;
use bevy::log::info;
use bevy::reflect::TypeRegistration;
use std::cell::Ref;
use std::ops::Range;

use super::{error::RunError, Environment, Spanned, Value};
use super::error::RunError;
use super::{Environment, Spanned, Value};

fn print(
value: Spanned<Value>,
Expand Down
10 changes: 4 additions & 6 deletions src/builtin_parser/runner/unique_rc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::{
cell::{Ref, RefCell, RefMut},
fmt::Debug,
ops::{Deref, DerefMut},
rc::{Rc, Weak},
};
use std::cell::{Ref, RefCell, RefMut};
use std::fmt::Debug;
use std::ops::{Deref, DerefMut};
use std::rc::{Rc, Weak};

/// A uniquely owned [`Rc`] with interior mutability. Interior mutability is abstracted away with [`WeakRef`].
///
Expand Down
6 changes: 4 additions & 2 deletions src/builtin_parser/runner/value.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt::Debug;
use std::{cell::RefCell, rc::Rc};
use std::rc::Rc;

use crate::builtin_parser::number::Number;
use crate::builtin_parser::{Environment, StrongRef};

use super::super::Spanned;
use super::environment::FunctionParam;
use super::error::RunError;
use super::reflection::{CreateRegistration, IntoResource};
use super::unique_rc::WeakRef;
use super::{super::Spanned, error::RunError};

use bevy::ecs::world::World;
use bevy::reflect::{
Expand Down
6 changes: 4 additions & 2 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Command execution functionality.
use std::{borrow::Cow, ops::Range};
use std::borrow::Cow;
use std::ops::Range;

use bevy::{ecs::system::Command, prelude::*};
use bevy::ecs::system::Command;
use bevy::prelude::*;

/// The command parser currrently being used by the dev console.
#[derive(Resource)]
Expand Down
3 changes: 2 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Configuration structs for the developer console.
use bevy::{log::Level, prelude::*};
use bevy::log::Level;
use bevy::prelude::*;
use bevy_egui::egui::{Color32, FontId, TextFormat};

/// The configuration of the developer console.
Expand Down
13 changes: 7 additions & 6 deletions src/logging/android_tracing.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use bevy::utils::tracing::{
field::Field,
span::{Attributes, Record},
Event, Id, Level, Subscriber,
};
use bevy::utils::tracing::field::Field;
use bevy::utils::tracing::span::{Attributes, Record};
use bevy::utils::tracing::{Event, Id, Level, Subscriber};
use std::fmt::{Debug, Write};
use tracing_subscriber::{field::Visit, layer::Context, registry::LookupSpan, Layer};
use tracing_subscriber::field::Visit;
use tracing_subscriber::layer::Context;
use tracing_subscriber::registry::LookupSpan;
use tracing_subscriber::Layer;

#[derive(Default)]
pub(crate) struct AndroidLayer;
Expand Down
16 changes: 8 additions & 8 deletions src/logging/log_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ mod android_tracing;
static GLOBAL: tracy_client::ProfiledAllocator<std::alloc::System> =
tracy_client::ProfiledAllocator::new(std::alloc::System, 100);

use bevy::ecs::event::{Event, EventWriter};
use bevy::ecs::system::{Res, Resource};
use bevy::log::trace;
use bevy::utils::tracing::Subscriber;
pub use bevy::utils::tracing::{warn, Level};
use bevy::{
ecs::{
event::{Event, EventWriter},
system::{Res, Resource},
},
log::trace,
};

use bevy::app::{App, Plugin, Update};
use tracing_log::LogTracer;
use tracing_subscriber::field::Visit;
#[cfg(feature = "tracing-chrome")]
use tracing_subscriber::fmt::{format::DefaultFields, FormattedFields};
use tracing_subscriber::{field::Visit, layer::Layer, prelude::*, registry::Registry, EnvFilter};
use tracing_subscriber::layer::Layer;
use tracing_subscriber::prelude::*;
use tracing_subscriber::registry::Registry;
use tracing_subscriber::EnvFilter;

/// [`bevy_dev_console`](crate)'s custom [LogPlugin](bevy::log::LogPlugin).
/// This plugin allows [`bevy_dev_console`](crate) to access Bevy logs
Expand Down
17 changes: 7 additions & 10 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
//! Made with [`bevy_egui`].
use bevy::prelude::*;
use bevy_egui::{
egui::{text::LayoutJob, Stroke, TextFormat},
*,
};
use bevy_egui::egui::text::LayoutJob;
use bevy_egui::egui::{Stroke, TextFormat};
use bevy_egui::*;
use chrono::prelude::*;
use web_time::SystemTime;

use crate::{
command::{CommandHints, ExecuteCommand},
config::ToColor32,
logging::log_plugin::LogMessage,
prelude::ConsoleConfig,
};
use crate::command::{CommandHints, ExecuteCommand};
use crate::config::ToColor32;
use crate::logging::log_plugin::LogMessage;
use crate::prelude::ConsoleConfig;

/// Prefix for log messages that show a previous command.
pub const COMMAND_MESSAGE_PREFIX: &str = "$ ";
Expand Down

0 comments on commit e27c71a

Please sign in to comment.