2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-12-15 13:23:43 -05:00
|
|
|
|
|
|
|
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);
|
2023-03-30 10:43:16 -04:00
|
|
|
static LSP_WARN_LEVEL: AtomicUsize =
|
|
|
|
AtomicUsize::new(log::Level::Warn as usize);
|
2021-12-15 13:23:43 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-03-30 10:43:16 -04:00
|
|
|
/// Change the lsp to log at the provided level.
|
2021-12-15 13:23:43 -05:00
|
|
|
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);
|
2022-06-25 18:13:24 -04:00
|
|
|
// TODO(bartlomieju):
|
|
|
|
#[allow(clippy::undocumented_unsafe_blocks)]
|
|
|
|
unsafe {
|
|
|
|
std::mem::transmute(level)
|
|
|
|
}
|
2021-12-15 13:23:43 -05:00
|
|
|
}
|
|
|
|
|
2023-03-30 10:43:16 -04:00
|
|
|
/// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-15 13:23:43 -05:00
|
|
|
/// 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)+) => (
|
2023-03-30 10:43:16 -04:00
|
|
|
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)+) => (
|
2023-11-14 17:10:51 -05:00
|
|
|
{
|
|
|
|
let lsp_log_level = $crate::lsp::logging::lsp_warn_level();
|
|
|
|
if lsp_log_level == log::Level::Debug {
|
|
|
|
$crate::lsp::logging::lsp_debug!($($arg)+)
|
|
|
|
} else {
|
|
|
|
log::log!(lsp_log_level, $($arg)+)
|
|
|
|
}
|
2021-12-15 13:23:43 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2023-03-30 10:43:16 -04:00
|
|
|
pub(super) use lsp_warn;
|