Skip to content

Commit

Permalink
Replace lazy_static! with Lazy type
Browse files Browse the repository at this point in the history
  • Loading branch information
efoerster committed Jun 30, 2019
1 parent 006de0c commit 51884eb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 33 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -25,7 +25,6 @@ indoc = "0.3.1"
itertools = "0.8.0"
jsonrpc = { path = "jsonrpc" }
jsonrpc-derive = { path = "jsonrpc_derive" }
lazy_static = "1.3.0"
log = "0.4.6"
lsp-types = { git = "https://github.com/latex-lsp/lsp-types", rev = "3616cc1bccfab93c4469f16a0f439cf3d11138f3", features = ["proposed"] }
nom = "5.0.0-beta2"
Expand Down
6 changes: 2 additions & 4 deletions src/data/symbols.rs
@@ -1,4 +1,4 @@
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -30,6 +30,4 @@ pub struct LatexArgumentSymbol {

static JSON: &'static str = include_str!("symbols.json");

lazy_static! {
pub static ref DATABASE: LatexSymbolDatabase = serde_json::from_str(JSON).unwrap();
}
pub static DATABASE: Lazy<LatexSymbolDatabase> = Lazy::new(|| serde_json::from_str(JSON).unwrap());
29 changes: 13 additions & 16 deletions src/diagnostics/build.rs
@@ -1,6 +1,6 @@
use crate::workspace::Document;
use lazy_static::lazy_static;
use lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range, Uri};
use once_cell::sync::Lazy;
use path_clean::PathClean;
use regex::{Match, Regex};
use std::cmp::Ordering;
Expand Down Expand Up @@ -79,25 +79,22 @@ impl Into<Diagnostic> for BuildError {

const MAX_LINE_LENGTH: usize = 79;

const PACKAGE_MESSAGE_PATTERN: &str = "^\\([a-zA-Z_\\-]+\\)\\s*(?P<msg>.*)$";
pub static PACKAGE_MESSAGE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new("^\\([a-zA-Z_\\-]+\\)\\s*(?P<msg>.*)$").unwrap());

const FILE_PATTERN: &str = "\\((?P<file>[^\r\n()]+\\.(tex|sty|cls))";
pub static FILE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new("\\((?P<file>[^\r\n()]+\\.(tex|sty|cls))").unwrap());

const TEX_ERROR_PATTERN: &str =
"(?m)^! ((?P<msg1>(.|\r|\n)*?)\r?\nl\\.(?P<line>\\d+)|(?P<msg2>[^\r\n]*))";
pub static TEX_ERROR_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("(?m)^! ((?P<msg1>(.|\r|\n)*?)\r?\nl\\.(?P<line>\\d+)|(?P<msg2>[^\r\n]*))").unwrap()
});

const WARNING_PATTERN: &str = "(LaTeX|Package [a-zA-Z_\\-]+) Warning: (?P<msg>[^\r\n]*)";
pub static WARNING_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new("(LaTeX|Package [a-zA-Z_\\-]+) Warning: (?P<msg>[^\r\n]*)").unwrap());

const BAD_BOX_PATTERN: &str =
"(?P<msg>(Ov|Und)erfull \\\\[hv]box[^\r\n]*lines? (?P<line>\\d+)[^\r\n]*)";

lazy_static! {
static ref PACKAGE_MESSAGE_REGEX: Regex = Regex::new(PACKAGE_MESSAGE_PATTERN).unwrap();
static ref FILE_REGEX: Regex = Regex::new(FILE_PATTERN).unwrap();
static ref TEX_ERROR_REGEX: Regex = Regex::new(TEX_ERROR_PATTERN).unwrap();
static ref WARNING_REGEX: Regex = Regex::new(WARNING_PATTERN).unwrap();
static ref BAD_BOX_REGEX: Regex = Regex::new(BAD_BOX_PATTERN).unwrap();
}
pub static BAD_BOX_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("(?P<msg>(Ov|Und)erfull \\\\[hv]box[^\r\n]*lines? (?P<line>\\d+)[^\r\n]*)").unwrap()
});

fn parse_build_log(uri: &Uri, log: &str) -> Vec<BuildError> {
let log = prepare_log(log);
Expand Down
9 changes: 3 additions & 6 deletions src/diagnostics/latex.rs
@@ -1,6 +1,6 @@
use crate::workspace::Document;
use lazy_static::lazy_static;
use lsp_types::*;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
Expand Down Expand Up @@ -44,11 +44,8 @@ impl LatexDiagnosticsProvider {
}
}

const LINE_PATTERN: &str = "(\\d+):(\\d+):(\\d+):(\\w+):(\\w)+:(.*)";

lazy_static! {
static ref LINE_REGEX: Regex = Regex::new(LINE_PATTERN).unwrap();
}
pub static LINE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new("(\\d+):(\\d+):(\\d+):(\\w+):(\\w)+:(.*)").unwrap());

fn lint(path: &Path) -> Option<Vec<Diagnostic>> {
let file = File::open(path).ok()?;
Expand Down
1 change: 0 additions & 1 deletion src/server.rs
Expand Up @@ -31,7 +31,6 @@ use lsp_types::*;
use once_cell::sync::OnceCell;
use runtime::task::JoinHandle;
use serde::de::DeserializeOwned;
use std::borrow::Cow;
use std::ffi::OsStr;
use std::fs;
use std::mem;
Expand Down
7 changes: 3 additions & 4 deletions src/tex/resolver/mod.rs
@@ -1,5 +1,5 @@
use crate::syntax::Language;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::env;
use std::ffi::OsStr;
Expand All @@ -25,9 +25,8 @@ pub enum TexDistributionKind {
Miktex,
}

lazy_static! {
pub static ref TEX_RESOLVER: Result<Arc<TexResolver>> = TexResolver::load().map(Arc::new);
}
pub static TEX_RESOLVER: Lazy<Result<Arc<TexResolver>>> =
Lazy::new(|| TexResolver::load().map(Arc::new));

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct TexResolver {
Expand Down

0 comments on commit 51884eb

Please sign in to comment.