summaryrefslogtreecommitdiff
path: root/cli/lsp/logging.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-12-15 13:23:43 -0500
committerGitHub <noreply@github.com>2021-12-15 13:23:43 -0500
commit6c324acf2363e88293ab94cf3de6c9d7a264b55d (patch)
treeb0d7c8752bf7e7b471be4a50e65572d501bb8b5a /cli/lsp/logging.rs
parenta1f0796fccfafee19b2fe06155efe746da2e9654 (diff)
feat: REPL import specifier auto-completions (#13078)
Diffstat (limited to 'cli/lsp/logging.rs')
-rw-r--r--cli/lsp/logging.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/cli/lsp/logging.rs b/cli/lsp/logging.rs
new file mode 100644
index 000000000..0bfc2fbc8
--- /dev/null
+++ b/cli/lsp/logging.rs
@@ -0,0 +1,49 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+use std::sync::atomic::AtomicBool;
+use std::sync::atomic::AtomicUsize;
+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);
+
+pub fn set_lsp_debug_flag(value: bool) {
+ LSP_DEBUG_FLAG.store(value, Ordering::SeqCst)
+}
+
+pub fn lsp_debug_enabled() -> bool {
+ LSP_DEBUG_FLAG.load(Ordering::SeqCst)
+}
+
+pub fn set_lsp_log_level(level: log::Level) {
+ LSP_LOG_LEVEL.store(level as usize, Ordering::SeqCst)
+}
+
+pub fn lsp_log_level() -> log::Level {
+ let level = LSP_LOG_LEVEL.load(Ordering::SeqCst);
+ 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();
+ if lsp_log_level == log::Level::Debug {
+ crate::lsp::logging::lsp_debug!($($arg)+)
+ } else {
+ log::log!(lsp_log_level, $($arg)+)
+ }
+ )
+}
+
+macro_rules! lsp_debug {
+ ($($arg:tt)+) => (
+ if crate::lsp::logging::lsp_debug_enabled() {
+ log::debug!($($arg)+)
+ }
+ )
+}
+
+pub(super) use lsp_debug;
+pub(super) use lsp_log;