Merge branch 'vhdl_project' of https://github.com/Digital-EDA/digital-lsp-server into vhdl_project
This commit is contained in:
commit
d8ddebc744
@ -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 {
|
||||
|
140
src/sources.rs
140
src/sources.rs
@ -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,70 +769,6 @@ pub fn vhdl_parser_pipeline(
|
||||
configure.extension_path.to_string()
|
||||
};
|
||||
|
||||
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 parse_ir = ParseIR::DesignFile(design_file);
|
||||
file.parse_ir = Some(parse_ir);
|
||||
|
||||
for module in &fast.content {
|
||||
info!("parse port number: {:?}", module.ports.len());
|
||||
}
|
||||
|
||||
let file_type = {
|
||||
let fast_map = hdl_param_handle.path_to_hdl_file.read().unwrap();
|
||||
if let Some(hdl_file) = fast_map.get(escape_path_string) {
|
||||
hdl_file.fast.file_type.to_string()
|
||||
} else {
|
||||
if let Some(relative_path) = escape_path_string.strip_prefix(&extension_path) {
|
||||
if relative_path.starts_with("/user/ip") || relative_path.starts_with("user/ip") {
|
||||
"ip".to_string()
|
||||
} else {
|
||||
"common".to_string()
|
||||
}
|
||||
} else {
|
||||
"common".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fast.file_type = file_type;
|
||||
hdl_param_handle.update_fast(escape_path_string.to_string(), fast.clone());
|
||||
let scope_tree = get_scopes_from_vhdl_fast(&fast, doc, uri);
|
||||
scope_tree
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
file.parse_ir = None;
|
||||
None
|
||||
};
|
||||
drop(file);
|
||||
|
||||
|
||||
info!("finish parse {:?}", uri.to_string());
|
||||
|
||||
// 更新 global_scope,用于 sv 的解析
|
||||
// global_scope 为全局最大的那个 scope,它的 scopes 和 defs 下的元素和每一个文件一一对应
|
||||
let mut global_scope = scope_handle.write().unwrap();
|
||||
match &mut *global_scope {
|
||||
Some(scope) => match &mut scope_tree {
|
||||
Some(tree) => {
|
||||
// 更新所有 uri 为当前 uri 的文件结构
|
||||
scope.defs.retain(|x| &x.url() != uri);
|
||||
scope.scopes.retain(|x| &x.url() != uri);
|
||||
|
||||
scope.defs.append(&mut tree.defs);
|
||||
scope.scopes.append(&mut tree.scopes);
|
||||
}
|
||||
None => (),
|
||||
},
|
||||
// 使用 scope_tree 来更新全局的 scope
|
||||
None => *global_scope = scope_tree,
|
||||
}
|
||||
// eprintln!("{:#?}", *global_scope);
|
||||
|
||||
let mut global_project = project_handle.write().unwrap();
|
||||
match &mut *global_project {
|
||||
Some(vhdl_project) => {
|
||||
@ -858,7 +795,7 @@ pub fn vhdl_parser_pipeline(
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let std_cfg_path = match PathBuf::from_str(&(extension_path + "/resources/dide-lsp/static/vhdl_std_lib/vhdl_ls.toml")) {
|
||||
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);
|
||||
@ -890,7 +827,78 @@ pub fn vhdl_parser_pipeline(
|
||||
}
|
||||
drop(global_project);
|
||||
|
||||
drop(global_scope);
|
||||
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) {
|
||||
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);
|
||||
|
||||
for module in &fast.content {
|
||||
info!("parse port number: {:?}", module.ports.len());
|
||||
}
|
||||
|
||||
let file_type = {
|
||||
let fast_map = hdl_param_handle.path_to_hdl_file.read().unwrap();
|
||||
if let Some(hdl_file) = fast_map.get(escape_path_string) {
|
||||
hdl_file.fast.file_type.to_string()
|
||||
} else {
|
||||
if let Some(relative_path) = escape_path_string.strip_prefix(&extension_path) {
|
||||
if relative_path.starts_with("/user/ip") || relative_path.starts_with("user/ip") {
|
||||
"ip".to_string()
|
||||
} else {
|
||||
"common".to_string()
|
||||
}
|
||||
} else {
|
||||
"common".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fast.file_type = file_type;
|
||||
hdl_param_handle.update_fast(escape_path_string.to_string(), fast.clone());
|
||||
let scope_tree = get_scopes_from_vhdl_fast(&fast, doc, uri);
|
||||
scope_tree
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
file.parse_ir = None;
|
||||
None
|
||||
};
|
||||
drop(file);
|
||||
|
||||
|
||||
info!("finish parse {:?}", uri.to_string());
|
||||
|
||||
// 更新 global_scope,用于 sv 的解析
|
||||
// global_scope 为全局最大的那个 scope,它的 scopes 和 defs 下的元素和每一个文件一一对应
|
||||
let mut global_scope = scope_handle.write().unwrap();
|
||||
match &mut *global_scope {
|
||||
Some(scope) => match &mut scope_tree {
|
||||
Some(tree) => {
|
||||
// 更新所有 uri 为当前 uri 的文件结构
|
||||
scope.defs.retain(|x| &x.url() != uri);
|
||||
scope.scopes.retain(|x| &x.url() != uri);
|
||||
|
||||
scope.defs.append(&mut tree.defs);
|
||||
scope.scopes.append(&mut tree.scopes);
|
||||
}
|
||||
None => (),
|
||||
},
|
||||
// 使用 scope_tree 来更新全局的 scope
|
||||
None => *global_scope = scope_tree,
|
||||
}
|
||||
// eprintln!("{:#?}", *global_scope);
|
||||
|
||||
drop(global_scope);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: add bounds checking for utf8<->utf16 conversions
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 2446bd0a812d1667ad7033f10cd27a03967fa15e
|
||||
Subproject commit efa2b481aafda0f8361dac8456ab35bda93bfe01
|
Loading…
x
Reference in New Issue
Block a user