diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-03-30 10:43:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-30 10:43:16 -0400 |
commit | e0429e2ad641e9207e00838de209ce33b3562f70 (patch) | |
tree | 496c38dadb79c4dc9ae4eea755e2ac6a65440ad4 /cli/lsp/logging.rs | |
parent | 3deade4b14de809f67ed0471f8e91c91b25fedcc (diff) |
fix(repl): improve package.json support (#18497)
1. Fixes a cosmetic issue in the repl where it would display lsp warning
messages.
2. Lazily loads dependencies from the package.json on use.
3. Supports using bare specifiers from package.json in the REPL.
Closes #17929
Closes #18494
Diffstat (limited to 'cli/lsp/logging.rs')
-rw-r--r-- | cli/lsp/logging.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/cli/lsp/logging.rs b/cli/lsp/logging.rs index 7099b08bc..8b703f2a5 100644 --- a/cli/lsp/logging.rs +++ b/cli/lsp/logging.rs @@ -6,6 +6,8 @@ use std::sync::atomic::Ordering; static LSP_DEBUG_FLAG: AtomicBool = AtomicBool::new(false); static LSP_LOG_LEVEL: AtomicUsize = AtomicUsize::new(log::Level::Info as usize); +static LSP_WARN_LEVEL: AtomicUsize = + AtomicUsize::new(log::Level::Warn as usize); pub fn set_lsp_debug_flag(value: bool) { LSP_DEBUG_FLAG.store(value, Ordering::SeqCst) @@ -15,6 +17,7 @@ pub fn lsp_debug_enabled() -> bool { LSP_DEBUG_FLAG.load(Ordering::SeqCst) } +/// Change the lsp to log at the provided level. pub fn set_lsp_log_level(level: log::Level) { LSP_LOG_LEVEL.store(level as usize, Ordering::SeqCst) } @@ -28,13 +31,40 @@ pub fn lsp_log_level() -> log::Level { } } +/// Change the lsp to warn at the provided level. +pub fn set_lsp_warn_level(level: log::Level) { + LSP_WARN_LEVEL.store(level as usize, Ordering::SeqCst) +} + +pub fn lsp_warn_level() -> log::Level { + let level = LSP_LOG_LEVEL.load(Ordering::SeqCst); + // TODO(bartlomieju): + #[allow(clippy::undocumented_unsafe_blocks)] + unsafe { + std::mem::transmute(level) + } +} + /// Use this macro to do "info" logs in the lsp code. This allows /// for downgrading these logs to another log level in the REPL. macro_rules! lsp_log { ($($arg:tt)+) => ( - let lsp_log_level = crate::lsp::logging::lsp_log_level(); + let lsp_log_level = $crate::lsp::logging::lsp_log_level(); + if lsp_log_level == log::Level::Debug { + $crate::lsp::logging::lsp_debug!($($arg)+) + } else { + log::log!(lsp_log_level, $($arg)+) + } + ) +} + +/// Use this macro to do "warn" logs in the lsp code. This allows +/// for downgrading these logs to another log level in the REPL. +macro_rules! lsp_warn { + ($($arg:tt)+) => ( + let lsp_log_level = $crate::lsp::logging::lsp_warn_level(); if lsp_log_level == log::Level::Debug { - crate::lsp::logging::lsp_debug!($($arg)+) + $crate::lsp::logging::lsp_debug!($($arg)+) } else { log::log!(lsp_log_level, $($arg)+) } @@ -51,3 +81,4 @@ macro_rules! lsp_debug { pub(super) use lsp_debug; pub(super) use lsp_log; +pub(super) use lsp_warn; |