diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2021-12-19 02:44:42 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-18 16:14:42 -0500 |
commit | 6de53b631fcdb96d72639b6d2db3592d5fa8498d (patch) | |
tree | 9a93d868f5f434a4898f212cb6bd53e65ca49ce0 /cli/lsp/tsc.rs | |
parent | 3db18bf9e6466c74efd9052df4d372ea0b581154 (diff) |
refactor: use `once_cell` instead of `lazy_static` (#13135)
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r-- | cli/lsp/tsc.rs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index a0b201bc0..d7cf47003 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -42,6 +42,7 @@ use log::warn; use lspower::jsonrpc::Error as LspError; use lspower::jsonrpc::Result as LspResult; use lspower::lsp; +use once_cell::sync::Lazy; use regex::Captures; use regex::Regex; use std::borrow::Cow; @@ -56,16 +57,23 @@ use text_size::TextSize; use tokio::sync::mpsc; use tokio::sync::oneshot; -lazy_static::lazy_static! { - static ref BRACKET_ACCESSOR_RE: Regex = Regex::new(r#"^\[['"](.+)[\['"]\]$"#).unwrap(); - static ref CAPTION_RE: Regex = Regex::new(r"<caption>(.*?)</caption>\s*\r?\n((?:\s|\S)*)").unwrap(); - static ref CODEBLOCK_RE: Regex = Regex::new(r"^\s*[~`]{3}").unwrap(); - static ref EMAIL_MATCH_RE: Regex = Regex::new(r"(.+)\s<([-.\w]+@[-.\w]+)>").unwrap(); - static ref JSDOC_LINKS_RE: Regex = Regex::new(r"(?i)\{@(link|linkplain|linkcode) (https?://[^ |}]+?)(?:[| ]([^{}\n]+?))?\}").unwrap(); - static ref PART_KIND_MODIFIER_RE: Regex = Regex::new(r",|\s+").unwrap(); - static ref PART_RE: Regex = Regex::new(r"^(\S+)\s*-?\s*").unwrap(); - static ref SCOPE_RE: Regex = Regex::new(r"scope_(\d)").unwrap(); -} +static BRACKET_ACCESSOR_RE: Lazy<Regex> = + Lazy::new(|| Regex::new(r#"^\[['"](.+)[\['"]\]$"#).unwrap()); +static CAPTION_RE: Lazy<Regex> = Lazy::new(|| { + Regex::new(r"<caption>(.*?)</caption>\s*\r?\n((?:\s|\S)*)").unwrap() +}); +static CODEBLOCK_RE: Lazy<Regex> = + Lazy::new(|| Regex::new(r"^\s*[~`]{3}").unwrap()); +static EMAIL_MATCH_RE: Lazy<Regex> = + Lazy::new(|| Regex::new(r"(.+)\s<([-.\w]+@[-.\w]+)>").unwrap()); +static JSDOC_LINKS_RE: Lazy<Regex> = Lazy::new(|| { + Regex::new(r"(?i)\{@(link|linkplain|linkcode) (https?://[^ |}]+?)(?:[| ]([^{}\n]+?))?\}").unwrap() +}); +static PART_KIND_MODIFIER_RE: Lazy<Regex> = + Lazy::new(|| Regex::new(r",|\s+").unwrap()); +static PART_RE: Lazy<Regex> = + Lazy::new(|| Regex::new(r"^(\S+)\s*-?\s*").unwrap()); +static SCOPE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"scope_(\d)").unwrap()); const FILE_EXTENSION_KIND_MODIFIERS: &[&str] = &[".d.ts", ".ts", ".tsx", ".js", ".jsx", ".json"]; |