fix new fast: stage

This commit is contained in:
light-ly 2024-12-03 17:24:01 +08:00
parent 509fd1a506
commit b52d69bdbb
4 changed files with 97 additions and 69 deletions

1
Cargo.lock generated
View File

@ -1416,7 +1416,6 @@ dependencies = [
name = "sv-parser"
version = "0.13.3"
dependencies = [
"log",
"nom",
"nom-greedyerror",
"sv-parser-error",

View File

@ -1,7 +1,7 @@
use std::collections::HashSet;
use std::path::PathBuf;
use log::info;
use vhdl_lang::ast::DesignFile;
use vhdl_lang::ast::{AnyDesignUnit, DesignFile};
use vhdl_lang::{kind_str, Token, VHDLParser, VHDLStandard};
use super::hdlparam::*;
@ -53,6 +53,27 @@ pub fn vhdl_parse_str(path: &PathBuf, code: &str) -> Option<DesignFile> {
None
}
pub fn new_make_fast_from_design_file(units: Vec<(AnyDesignUnit, Vec<Token>)>, design_file: &DesignFile) -> Option<FastHdlparam> {
let mut hdlparam = FastHdlparam {
fast_macro: Macro {
defines: Vec::new(),
errors: Vec::new(),
includes: Vec::new(),
invalid: Vec::new()
},
content: Vec::new(),
file_type: "common".to_string()
};
info!("get units {:#?}", units);
// for (tokens, design_unit) in &design_file.design_units {
// }
Some(hdlparam)
}
pub fn make_fast_from_design_file(design_file: &DesignFile) -> Option<FastHdlparam> {
let mut hdlparam = FastHdlparam {
fast_macro: Macro {

View File

@ -2,6 +2,7 @@ use crate::core::hdlparam::HdlParam;
use crate::core::primitive_parser::PrimitiveText;
use crate::core::sv_parser::make_fast_from_syntaxtree;
use crate::core::vhdl_parser::make_fast_from_design_file;
use crate::core::vhdl_parser::new_make_fast_from_design_file;
use crate::core::vhdl_parser::vhdl_parse_str;
use crate::definition::def_types::*;
use crate::definition::get_scopes_from_syntax_tree;
@ -768,10 +769,72 @@ pub fn vhdl_parser_pipeline(
configure.extension_path.to_string()
};
let mut global_project = project_handle.write().unwrap();
match &mut *global_project {
Some(vhdl_project) => {
if let Some(source) = vhdl_project.project.get_source(&escape_path) {
source.change(None, &doc.to_string());
vhdl_project.project.update_source(&source);
vhdl_project.project.analyse();
} else {
vhdl_project.config_file_strs.push(format!("{:?}", escape_path));
let mut messages = Vec::new();
let config_str = format!(
r#"
[libraries]
digital_lsp.files = [{}]
"#, vhdl_project.config_file_strs.join(",")
);
let config = vhdl_lang::Config::from_str(&config_str, Path::new(""));
if let Ok(mut config) = config {
config.append(&vhdl_project.std_config, &mut messages);
let mut project = Project::from_config(config, &mut messages);
project.analyse();
*vhdl_project = VhdlProject { project, std_config: vhdl_project.std_config.clone(), config_file_strs: vhdl_project.config_file_strs.clone() };
}
}
}
None => {
let std_cfg_path = match PathBuf::from_str(&(extension_path.clone() + "/resources/dide-lsp/static/vhdl_std_lib/vhdl_ls.toml")) {
Ok(path) => path,
Err(e) => {
info!("error happen in <vhdl_parse_pipeline>: {:?}", e);
return;
}
};
match vhdl_lang::Config::read_file_path(&std_cfg_path) {
Ok(std_config) => {
let config_str = format!(
r#"
[libraries]
digital_lsp.files = [{:?}]
"#, escape_path
);
let mut config_file_strs = Vec::new();
config_file_strs.push(format!("{:?}", escape_path));
let config = vhdl_lang::Config::from_str(&config_str, Path::new(""));
if let Ok(mut config) = config {
let mut messages = Vec::new();
config.append(&std_config, &mut messages);
let mut project = Project::from_config(config, &mut messages);
project.analyse();
*global_project = Some(VhdlProject { project, std_config, config_file_strs });
}
}
Err(e) => info!("error happen in <vhdl_parse_pipeline>: Can't load standard vhdl lib from {std_cfg_path:#?} because {e:#?}")
}
}
}
drop(global_project);
let mut global_project = project_handle.write().unwrap();
match &mut *global_project {
Some(vhdl_project) => {
let mut file = source_handle.write().unwrap();
let text = doc.to_string();
let mut scope_tree = if let Some(design_file) = vhdl_parse_str(&escape_path, &text) {
if let Some(mut fast) = make_fast_from_design_file(&design_file) {
let units_in_file = vhdl_project.project.get_analyzed_units(&escape_path);
if let Some(mut fast) = new_make_fast_from_design_file(units_in_file, &design_file) {
let parse_ir = ParseIR::DesignFile(design_file);
file.parse_ir = Some(parse_ir);
@ -832,65 +895,10 @@ pub fn vhdl_parser_pipeline(
}
// eprintln!("{:#?}", *global_scope);
let mut global_project = project_handle.write().unwrap();
match &mut *global_project {
Some(vhdl_project) => {
if let Some(source) = vhdl_project.project.get_source(&escape_path) {
source.change(None, &doc.to_string());
vhdl_project.project.update_source(&source);
vhdl_project.project.analyse();
} else {
vhdl_project.config_file_strs.push(format!("{:?}", escape_path));
let mut messages = Vec::new();
let config_str = format!(
r#"
[libraries]
digital_lsp.files = [{}]
"#, vhdl_project.config_file_strs.join(",")
);
let config = vhdl_lang::Config::from_str(&config_str, Path::new(""));
if let Ok(mut config) = config {
config.append(&vhdl_project.std_config, &mut messages);
let mut project = Project::from_config(config, &mut messages);
project.analyse();
*vhdl_project = VhdlProject { project, std_config: vhdl_project.std_config.clone(), config_file_strs: vhdl_project.config_file_strs.clone() };
}
}
}
None => {
let std_cfg_path = match PathBuf::from_str(&(extension_path + "/resources/dide-lsp/static/vhdl_std_lib/vhdl_ls.toml")) {
Ok(path) => path,
Err(e) => {
info!("error happen in <vhdl_parse_pipeline>: {:?}", e);
return;
}
};
match vhdl_lang::Config::read_file_path(&std_cfg_path) {
Ok(std_config) => {
let config_str = format!(
r#"
[libraries]
digital_lsp.files = [{:?}]
"#, escape_path
);
let mut config_file_strs = Vec::new();
config_file_strs.push(format!("{:?}", escape_path));
let config = vhdl_lang::Config::from_str(&config_str, Path::new(""));
if let Ok(mut config) = config {
let mut messages = Vec::new();
config.append(&std_config, &mut messages);
let mut project = Project::from_config(config, &mut messages);
project.analyse();
*global_project = Some(VhdlProject { project, std_config, config_file_strs });
}
}
Err(e) => info!("error happen in <vhdl_parse_pipeline>: Can't load standard vhdl lib from {std_cfg_path:#?} because {e:#?}")
}
}
}
drop(global_project);
drop(global_scope);
}
_ => ()
}
}
//TODO: add bounds checking for utf8<->utf16 conversions

@ -1 +1 @@
Subproject commit 2446bd0a812d1667ad7033f10cd27a03967fa15e
Subproject commit efa2b481aafda0f8361dac8456ab35bda93bfe01