From e8e746628785df31545fd465489dc75eba5a6c10 Mon Sep 17 00:00:00 2001 From: LSTM-Kirigaya <1193466151@qq.com> Date: Sun, 6 Oct 2024 15:28:00 +0800 Subject: [PATCH] update & save --- vhdl_lang/Cargo.toml | 1 + vhdl_lang/src/project.rs | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/vhdl_lang/Cargo.toml b/vhdl_lang/Cargo.toml index b29851a..a88a7e8 100644 --- a/vhdl_lang/Cargo.toml +++ b/vhdl_lang/Cargo.toml @@ -29,6 +29,7 @@ itertools = "0" subst = "0.3.0" strum = { version = "0.26.2", features = ["derive"] } enum-map = "2.7.3" +log = "0.4.19" [dev-dependencies] tempfile = "3" diff --git a/vhdl_lang/src/project.rs b/vhdl_lang/src/project.rs index d660a5b..fd37257 100644 --- a/vhdl_lang/src/project.rs +++ b/vhdl_lang/src/project.rs @@ -14,6 +14,7 @@ use crate::named_entity::EntRef; use crate::standard::VHDLStandard; use crate::syntax::VHDLParser; use crate::{data::*, EntHierarchy, EntityId}; +use log::info; use fnv::{FnvHashMap, FnvHashSet}; use std::collections::hash_map::Entry; use std::path::Path; @@ -89,14 +90,33 @@ impl Project { self.parse_and_add_files(new_files, messages); } - pub fn new_without_config(path: &PathBuf, messages: &mut dyn MessageHandler, standard: Option) -> Project { - let mut project = Project::new(standard.unwrap_or(VHDLStandard::VHDL2008)); - let file = project.load_file_without_config(&path); - project.parse_and_add_files(file, messages); - // project.config = Config::default(); + pub fn new_without_config(path: &PathBuf, messages: &mut dyn MessageHandler) -> Project { + let config_str = format!( + r#" +[libraries] +lib.files = ['{:?}'] + "#, path.to_str().unwrap() + ); + let new_config = Config::from_str(&config_str, path.parent().unwrap()).unwrap(); + let project = Project::from_config(new_config, messages); + info!("new config {:#?}", project.config); project } + pub fn digital_lsp_update_config( &mut self, path: &PathBuf, messages: &mut dyn MessageHandler) { + let config_str = format!( + r#" +[libraries] +lib.files = ['{:?}'] + "#, path.to_str().unwrap() + ); + if let Ok(mut new_config) = Config::from_str(&config_str, path.parent().unwrap()) { + new_config.append(&self.config, messages); + self.update_config(new_config, messages); + info!("update config {:#?}", self.config); + } + } + pub fn add_file( &mut self, path: &PathBuf,