Skip to content

Commit

Permalink
fix: inherit config
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed May 25, 2023
1 parent dab9def commit 7e9cb51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions crates/els/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -264,7 +264,7 @@ fn module_completions() -> Vec<CompletionItem> {
comps
}

fn load_modules(cache: Cache) {
fn load_modules(cfg: ErgConfig, cache: Cache) {
let major_mods = [
"datetime",
"glob",
Expand All @@ -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");
Expand All @@ -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 }
}
Expand Down
2 changes: 1 addition & 1 deletion crates/els/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ pub struct Server<Checker: BuildRunnable = HIRBuilder> {
impl<Checker: BuildRunnable> Server<Checker> {
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(),
Expand Down

0 comments on commit 7e9cb51

Please sign in to comment.