formatting

This commit is contained in:
Jack Wright 2024-06-25 17:01:46 -07:00
parent 8f4f705a7c
commit a0ed00fcba
3 changed files with 40 additions and 200 deletions

View File

@ -89,11 +89,7 @@ pub fn evaluate_repl(
if let Err(e) = convert_env_values(engine_state, &unique_stack) { if let Err(e) = convert_env_values(engine_state, &unique_stack) {
report_error_new(engine_state, &e); report_error_new(engine_state, &e);
} }
perf!( perf!("translate env vars", start_time, use_color);
"translate env vars",
start_time,
use_color
);
// seed env vars // seed env vars
unique_stack.add_env_var( unique_stack.add_env_var(
@ -222,22 +218,14 @@ fn get_line_editor(
// Now that reedline is created, get the history session id and store it in engine_state // Now that reedline is created, get the history session id and store it in engine_state
store_history_id_in_engine(engine_state, &line_editor); store_history_id_in_engine(engine_state, &line_editor);
perf!( perf!("setup reedline", start_time, use_color);
"setup reedline",
start_time,
use_color
);
if let Some(history) = engine_state.history_config() { if let Some(history) = engine_state.history_config() {
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
line_editor = setup_history(nushell_path, engine_state, line_editor, history)?; line_editor = setup_history(nushell_path, engine_state, line_editor, history)?;
perf!( perf!("setup history", start_time, use_color);
"setup history",
start_time,
use_color
);
} }
Ok(line_editor) Ok(line_editor)
} }
@ -280,22 +268,14 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
if let Err(err) = engine_state.merge_env(&mut stack, cwd) { if let Err(err) = engine_state.merge_env(&mut stack, cwd) {
report_error_new(engine_state, &err); report_error_new(engine_state, &err);
} }
perf!( perf!("merge env", start_time, use_color);
"merge env",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
// Reset the ctrl-c handler // Reset the ctrl-c handler
if let Some(ctrlc) = &mut engine_state.ctrlc { if let Some(ctrlc) = &mut engine_state.ctrlc {
ctrlc.store(false, Ordering::SeqCst); ctrlc.store(false, Ordering::SeqCst);
} }
perf!( perf!("reset ctrlc", start_time, use_color);
"reset ctrlc",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
// Right before we start our prompt and take input from the user, // Right before we start our prompt and take input from the user,
@ -305,11 +285,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
report_error_new(engine_state, &err); report_error_new(engine_state, &err);
} }
} }
perf!( perf!("pre-prompt hook", start_time, use_color);
"pre-prompt hook",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
// Next, check all the environment variables they ask for // Next, check all the environment variables they ask for
@ -318,11 +294,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
if let Err(error) = hook::eval_env_change_hook(env_change, engine_state, &mut stack) { if let Err(error) = hook::eval_env_change_hook(env_change, engine_state, &mut stack) {
report_error_new(engine_state, &error) report_error_new(engine_state, &error)
} }
perf!( perf!("env-change hook", start_time, use_color);
"env-change hook",
start_time,
use_color
);
let engine_reference = Arc::new(engine_state.clone()); let engine_reference = Arc::new(engine_state.clone());
let config = engine_state.get_config(); let config = engine_state.get_config();
@ -334,11 +306,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
vi_normal: map_nucursorshape_to_cursorshape(config.cursor_shape_vi_normal), vi_normal: map_nucursorshape_to_cursorshape(config.cursor_shape_vi_normal),
emacs: map_nucursorshape_to_cursorshape(config.cursor_shape_emacs), emacs: map_nucursorshape_to_cursorshape(config.cursor_shape_emacs),
}; };
perf!( perf!("get config/cursor config", start_time, use_color);
"get config/cursor config",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
// at this line we have cloned the state for the completer and the transient prompt // at this line we have cloned the state for the completer and the transient prompt
@ -370,11 +338,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
.with_ansi_colors(config.use_ansi_coloring) .with_ansi_colors(config.use_ansi_coloring)
.with_cursor_config(cursor_config); .with_cursor_config(cursor_config);
perf!( perf!("reedline builder", start_time, use_color);
"reedline builder",
start_time,
use_color
);
let style_computer = StyleComputer::from_config(engine_state, &stack_arc); let style_computer = StyleComputer::from_config(engine_state, &stack_arc);
@ -389,11 +353,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
line_editor.disable_hints() line_editor.disable_hints()
}; };
perf!( perf!("reedline coloring/style_computer", start_time, use_color);
"reedline coloring/style_computer",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
trace!("adding menus"); trace!("adding menus");
@ -403,11 +363,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
Reedline::create() Reedline::create()
}); });
perf!( perf!("reedline adding menus", start_time, use_color);
"reedline adding menus",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
let buffer_editor = get_editor(engine_state, &stack_arc, Span::unknown()); let buffer_editor = get_editor(engine_state, &stack_arc, Span::unknown());
@ -424,11 +380,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
line_editor line_editor
}; };
perf!( perf!("reedline buffer_editor", start_time, use_color);
"reedline buffer_editor",
start_time,
use_color
);
if let Some(history) = engine_state.history_config() { if let Some(history) = engine_state.history_config() {
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
@ -438,22 +390,14 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
} }
} }
perf!( perf!("sync_history", start_time, use_color);
"sync_history",
start_time,
use_color
);
} }
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
// Changing the line editor based on the found keybindings // Changing the line editor based on the found keybindings
line_editor = setup_keybindings(engine_state, line_editor); line_editor = setup_keybindings(engine_state, line_editor);
perf!( perf!("keybindings", start_time, use_color);
"keybindings",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
let config = &engine_state.get_config().clone(); let config = &engine_state.get_config().clone();
@ -470,11 +414,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
nu_prompt, nu_prompt,
); );
perf!( perf!("update_prompt", start_time, use_color);
"update_prompt",
start_time,
use_color
);
*entry_num += 1; *entry_num += 1;
@ -501,11 +441,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
// so we should avoid it or making stack cheaper to clone. // so we should avoid it or making stack cheaper to clone.
let mut stack = Arc::unwrap_or_clone(stack_arc); let mut stack = Arc::unwrap_or_clone(stack_arc);
perf!( perf!("line_editor setup", start_time, use_color);
"line_editor setup",
start_time,
use_color
);
let line_editor_input_time = std::time::Instant::now(); let line_editor_input_time = std::time::Instant::now();
match input { match input {
@ -542,11 +478,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
} }
} }
perf!( perf!("pre_execution_hook", start_time, use_color);
"pre_execution_hook",
start_time,
use_color
);
let mut repl = engine_state.repl_state.lock().expect("repl state mutex"); let mut repl = engine_state.repl_state.lock().expect("repl state mutex");
repl.cursor_pos = line_editor.current_insertion_point(); repl.cursor_pos = line_editor.current_insertion_point();
@ -995,11 +927,7 @@ fn run_shell_integration_osc2(
// ESC]2;stringBEL -- Set window title to string // ESC]2;stringBEL -- Set window title to string
run_ansi_sequence(&format!("\x1b]2;{title}\x07")); run_ansi_sequence(&format!("\x1b]2;{title}\x07"));
perf!( perf!("set title with command osc2", start_time, use_color);
"set title with command osc2",
start_time,
use_color
);
} }
} }

View File

@ -219,11 +219,7 @@ fn main() -> Result<()> {
logger(|builder| configure(&level, &target, filters, builder))?; logger(|builder| configure(&level, &target, filters, builder))?;
// info!("start logging {}:{}:{}", file!(), line!(), column!()); // info!("start logging {}:{}:{}", file!(), line!(), column!());
perf!( perf!("start logging", start_time, use_color);
"start logging",
start_time,
use_color
);
} }
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
@ -242,21 +238,13 @@ fn main() -> Result<()> {
"env-path", "env-path",
parsed_nu_cli_args.env_file.as_ref(), parsed_nu_cli_args.env_file.as_ref(),
); );
perf!( perf!("set_config_path", start_time, use_color);
"set_config_path",
start_time,
use_color
);
#[cfg(unix)] #[cfg(unix)]
{ {
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
terminal::acquire(engine_state.is_interactive); terminal::acquire(engine_state.is_interactive);
perf!( perf!("acquire_terminal", start_time, use_color);
"acquire_terminal",
start_time,
use_color
);
} }
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
@ -270,20 +258,12 @@ fn main() -> Result<()> {
engine_state.add_env_var("NU_LIB_DIRS".into(), Value::list(vals, span)); engine_state.add_env_var("NU_LIB_DIRS".into(), Value::list(vals, span));
} }
perf!( perf!("NU_LIB_DIRS setup", start_time, use_color);
"NU_LIB_DIRS setup",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
// First, set up env vars as strings only // First, set up env vars as strings only
gather_parent_env_vars(&mut engine_state, &init_cwd); gather_parent_env_vars(&mut engine_state, &init_cwd);
perf!( perf!("gather env vars", start_time, use_color);
"gather env vars",
start_time,
use_color
);
engine_state.add_env_var( engine_state.add_env_var(
"NU_VERSION".to_string(), "NU_VERSION".to_string(),
@ -344,11 +324,7 @@ fn main() -> Result<()> {
} }
std::process::exit(0) std::process::exit(0)
} }
perf!( perf!("run test_bins", start_time, use_color);
"run test_bins",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
let input = if let Some(redirect_stdin) = &parsed_nu_cli_args.redirect_stdin { let input = if let Some(redirect_stdin) = &parsed_nu_cli_args.redirect_stdin {
@ -358,20 +334,12 @@ fn main() -> Result<()> {
trace!("not redirecting stdin"); trace!("not redirecting stdin");
PipelineData::empty() PipelineData::empty()
}; };
perf!( perf!("redirect stdin", start_time, use_color);
"redirect stdin",
start_time,
use_color
);
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
// Set up the $nu constant before evaluating config files (need to have $nu available in them) // Set up the $nu constant before evaluating config files (need to have $nu available in them)
engine_state.generate_nu_constant(); engine_state.generate_nu_constant();
perf!( perf!("create_nu_constant", start_time, use_color);
"create_nu_constant",
start_time,
use_color
);
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
if let Some(plugins) = &parsed_nu_cli_args.plugins { if let Some(plugins) = &parsed_nu_cli_args.plugins {
@ -409,20 +377,12 @@ fn main() -> Result<()> {
} }
engine_state.merge_delta(working_set.render())?; engine_state.merge_delta(working_set.render())?;
perf!( perf!("load plugins specified in --plugins", start_time, use_color)
"load plugins specified in --plugins",
start_time,
use_color
)
} }
start_time = std::time::Instant::now(); start_time = std::time::Instant::now();
if parsed_nu_cli_args.lsp { if parsed_nu_cli_args.lsp {
perf!( perf!("lsp starting", start_time, use_color);
"lsp starting",
start_time,
use_color
);
if parsed_nu_cli_args.no_config_file.is_none() { if parsed_nu_cli_args.no_config_file.is_none() {
let mut stack = nu_protocol::engine::Stack::new(); let mut stack = nu_protocol::engine::Stack::new();

View File

@ -35,11 +35,7 @@ pub(crate) fn run_commands(
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file, NUSHELL_FOLDER); read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file, NUSHELL_FOLDER);
perf!( perf!("read plugins", start_time, use_color);
"read plugins",
start_time,
use_color
);
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
// If we have a env file parameter *OR* we have a login shell parameter, read the env file // If we have a env file parameter *OR* we have a login shell parameter, read the env file
@ -54,11 +50,7 @@ pub(crate) fn run_commands(
config_files::read_default_env_file(engine_state, &mut stack) config_files::read_default_env_file(engine_state, &mut stack)
} }
perf!( perf!("read env.nu", start_time, use_color);
"read env.nu",
start_time,
use_color
);
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
// If we have a config file parameter *OR* we have a login shell parameter, read the config file // If we have a config file parameter *OR* we have a login shell parameter, read the config file
@ -71,11 +63,7 @@ pub(crate) fn run_commands(
); );
} }
perf!( perf!("read config.nu", start_time, use_color);
"read config.nu",
start_time,
use_color
);
// If we have a login shell parameter, read the login file // If we have a login shell parameter, read the login file
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
@ -83,11 +71,7 @@ pub(crate) fn run_commands(
config_files::read_loginshell_file(engine_state, &mut stack); config_files::read_loginshell_file(engine_state, &mut stack);
} }
perf!( perf!("read login.nu", start_time, use_color);
"read login.nu",
start_time,
use_color
);
} }
// Before running commands, set up the startup time // Before running commands, set up the startup time
@ -111,11 +95,7 @@ pub(crate) fn run_commands(
report_error_new(engine_state, &err); report_error_new(engine_state, &err);
std::process::exit(1); std::process::exit(1);
} }
perf!( perf!("evaluate_commands", start_time, use_color);
"evaluate_commands",
start_time,
use_color
);
} }
pub(crate) fn run_file( pub(crate) fn run_file(
@ -138,11 +118,7 @@ pub(crate) fn run_file(
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file, NUSHELL_FOLDER); read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file, NUSHELL_FOLDER);
perf!( perf!("read plugins", start_time, use_color);
"read plugins",
start_time,
use_color
);
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
// only want to load config and env if relative argument is provided. // only want to load config and env if relative argument is provided.
@ -156,11 +132,7 @@ pub(crate) fn run_file(
} else { } else {
config_files::read_default_env_file(engine_state, &mut stack) config_files::read_default_env_file(engine_state, &mut stack)
} }
perf!( perf!("read env.nu", start_time, use_color);
"read env.nu",
start_time,
use_color
);
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
if parsed_nu_cli_args.config_file.is_some() { if parsed_nu_cli_args.config_file.is_some() {
@ -171,11 +143,7 @@ pub(crate) fn run_file(
false, false,
); );
} }
perf!( perf!("read config.nu", start_time, use_color);
"read config.nu",
start_time,
use_color
);
} }
// Regenerate the $nu constant to contain the startup time and any other potential updates // Regenerate the $nu constant to contain the startup time and any other potential updates
@ -192,11 +160,7 @@ pub(crate) fn run_file(
report_error_new(engine_state, &err); report_error_new(engine_state, &err);
std::process::exit(1); std::process::exit(1);
} }
perf!( perf!("evaluate_file", start_time, use_color);
"evaluate_file",
start_time,
use_color
);
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
let last_exit_code = stack.get_env_var(&*engine_state, "LAST_EXIT_CODE"); let last_exit_code = stack.get_env_var(&*engine_state, "LAST_EXIT_CODE");
@ -208,11 +172,7 @@ pub(crate) fn run_file(
} }
} }
} }
perf!( perf!("get exit code", start_time, use_color);
"get exit code",
start_time,
use_color
);
} }
pub(crate) fn run_repl( pub(crate) fn run_repl(
@ -238,11 +198,7 @@ pub(crate) fn run_repl(
// Reload use_color from config in case it's different from the default value // Reload use_color from config in case it's different from the default value
let use_color = engine_state.get_config().use_ansi_coloring; let use_color = engine_state.get_config().use_ansi_coloring;
perf!( perf!("setup_config", start_time, use_color);
"setup_config",
start_time,
use_color
);
let start_time = std::time::Instant::now(); let start_time = std::time::Instant::now();
let ret_val = evaluate_repl( let ret_val = evaluate_repl(
@ -253,11 +209,7 @@ pub(crate) fn run_repl(
parsed_nu_cli_args.no_std_lib, parsed_nu_cli_args.no_std_lib,
entire_start_time, entire_start_time,
); );
perf!( perf!("evaluate_repl", start_time, use_color);
"evaluate_repl",
start_time,
use_color
);
ret_val ret_val
} }