Skip to content

Commit

Permalink
Improve performance of integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed Jun 2, 2019
1 parent cf27ffc commit 05352f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/resolver/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use std::process::Command;
use std::sync::Arc;

mod miktex;
mod texlive;

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Error {
KpsewhichNotFound,
UnsupportedTexDistribution,
Expand All @@ -16,18 +18,23 @@ pub enum Error {

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum TexDistributionKind {
Texlive,
Miktex,
}

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

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct TexResolver {
pub files_by_name: HashMap<OsString, PathBuf>,
}

impl TexResolver {
pub fn load() -> Result<Self> {
fn load() -> Result<Self> {
let directories = Self::find_root_directories()?;
let kind = Self::detect_distribution(&directories)?;
let files_by_name = Self::read_database(&directories, kind)?;
Expand Down
6 changes: 3 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::reference::ReferenceProvider;
use crate::rename::RenameProvider;
use crate::request;
use crate::resolver;
use crate::resolver::TexResolver;
use crate::resolver::{TexResolver, TEX_RESOLVER};
use crate::syntax::bibtex::BibtexDeclaration;
use crate::syntax::text::SyntaxNode;
use crate::syntax::SyntaxTree;
Expand Down Expand Up @@ -384,10 +384,10 @@ impl<C: LspClient + Send + Sync> jsonrpc::ActionHandler for LatexLspServer<C> {
}
}
Action::LoadResolver => {
match TexResolver::load() {
match &*TEX_RESOLVER {
Ok(res) => {
let mut resolver = self.resolver.lock().await;
*resolver = Arc::new(res);
*resolver = Arc::clone(&res);
}
Err(why) => {
let message = match why {
Expand Down

0 comments on commit 05352f2

Please sign in to comment.