From 7e9cb513af503e9fae4f9ff1b1744d56a3283ff1 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Thu, 25 May 2023 13:47:42 +0900 Subject: [PATCH] fix: inherit config --- crates/els/completion.rs | 13 ++++++++----- crates/els/server.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/els/completion.rs b/crates/els/completion.rs index 15ad33369..8b725e4f2 100644 --- a/crates/els/completion.rs +++ b/crates/els/completion.rs @@ -2,7 +2,7 @@ use erg_common::consts::PYTHON_MODE; use lsp_types::CompletionResponse; use serde_json::Value; -use erg_common::config::ErgConfig; +use erg_common::config::{ErgConfig, Input}; use erg_common::dict::Dict; use erg_common::env::erg_pystd_path; use erg_common::impl_u8_enum; @@ -264,7 +264,7 @@ fn module_completions() -> Vec { comps } -fn load_modules(cache: Cache) { +fn load_modules(cfg: ErgConfig, cache: Cache) { let major_mods = [ "datetime", "glob", @@ -285,7 +285,10 @@ fn load_modules(cache: Cache) { let src = major_mods.into_iter().fold("".to_string(), |acc, module| { acc + &format!("_ = pyimport \"{module}\"\n") }); - let cfg = ErgConfig::string(src.clone()); + let cfg = ErgConfig { + input: Input::str(src.clone()), + ..cfg + }; let shared = SharedCompilerResource::new(cfg.clone()); let mut checker = HIRBuilder::inherit(cfg, shared.clone()); let _res = checker.build(src, "exec"); @@ -312,12 +315,12 @@ fn load_modules(cache: Cache) { } impl CompletionCache { - pub fn new() -> Self { + pub fn new(cfg: ErgConfig) -> Self { let cache = AtomicShared::new(Dict::default()); let clone = cache.clone(); std::thread::spawn(move || { crate::_log!("load_modules"); - load_modules(clone) + load_modules(cfg, clone) }); Self { cache } } diff --git a/crates/els/server.rs b/crates/els/server.rs index 08f1aae4a..952b23785 100644 --- a/crates/els/server.rs +++ b/crates/els/server.rs @@ -221,13 +221,13 @@ pub struct Server { impl Server { pub fn new(cfg: ErgConfig) -> Self { Self { + comp_cache: CompletionCache::new(cfg.copy()), cfg, home: normalize_path(std::env::current_dir().unwrap_or_default()), erg_path: erg_path(), // already normalized client_capas: ClientCapabilities::default(), disabled_features: vec![], opt_features: vec![], - comp_cache: CompletionCache::new(), file_cache: FileCache::new(), modules: Dict::new(), analysis_result: Dict::new(),