diff --git a/src/core/hdlparam.rs b/src/core/hdlparam.rs index 63f4fd3..4aea7eb 100644 --- a/src/core/hdlparam.rs +++ b/src/core/hdlparam.rs @@ -303,6 +303,8 @@ pub struct Macro { pub struct FastHdlparam { #[serde(rename = "macro")] pub fast_macro: Macro, + #[serde(rename = "fileType")] + pub file_type: String, pub content: Vec } diff --git a/src/core/sv_parser.rs b/src/core/sv_parser.rs index 5d9486b..96f2abe 100644 --- a/src/core/sv_parser.rs +++ b/src/core/sv_parser.rs @@ -83,7 +83,10 @@ pub fn sv_parser(path: &str) -> Option { None } -pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Result { +pub fn make_fast_from_syntaxtree( + syntax_tree: &SyntaxTree, + path: &PathBuf +) -> Result { // 对不同操作系统文件路径的支持 let path = to_escape_path(path); @@ -94,7 +97,8 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Re includes: get_includes(&path), invalid: Vec::new() }, - content: Vec::new() + content: Vec::new(), + file_type: "common".to_string() }; let mut ansi_port_last_dir = ""; diff --git a/src/core/vhdl_parser.rs b/src/core/vhdl_parser.rs index 93cde9d..8a25380 100644 --- a/src/core/vhdl_parser.rs +++ b/src/core/vhdl_parser.rs @@ -17,7 +17,8 @@ pub fn vhdl_parser(path: &str) -> FastHdlparam { includes: Vec::new(), invalid: Vec::new() }, - content: Vec::new() + content: Vec::new(), + file_type: "common".to_string() }; let parser = VHDLParser::new(VHDLStandard::VHDL2008); @@ -52,7 +53,8 @@ pub fn make_fast_from_design_file(design_file: &DesignFile) -> Option Result { #[derive(Deserialize, Serialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct DoFastApiRequestParams { path: String, + file_type: String, + tool_chain: String } @@ -73,7 +76,9 @@ impl <'a>tower_lsp::jsonrpc::Method<&'a Arc, (DoFastApiRequestParams, ) fn invoke(&self, _server: &'a Arc, _params: (DoFastApiRequestParams, )) -> Self::Future { let request_param = _params.0; let path = request_param.path; - let hdlparam = do_fast(path, _server); + let file_type = request_param.file_type; + let tool_chain = request_param.tool_chain; + let hdlparam = do_fast(path, file_type, tool_chain, _server); future::ready(hdlparam) } } @@ -89,19 +94,35 @@ fn make_textdocumenitem_from_path(path_buf: &PathBuf) -> Option) -> Result { - info!("parse fast \"{}\"", path); +pub fn do_fast( + path: String, + file_type: String, + tool_chain: String, + backend: &Arc +) -> Result { + info!("parse fast {:?}, type: {:?}, toolchain: {:?}", path, file_type, tool_chain); + // 根据 file_type 和 tool_chain 计算正确的 path + let path = { + if file_type == "ip" && tool_chain == "xilinx" { + let pathbuf = PathBuf::from_str(&path).unwrap(); + let basename = pathbuf.file_name().unwrap().to_str().unwrap(); + format!("{}/{}.vho", path, basename) + } else { + path + } + }; + let language_id = get_language_id_by_path_str(&path); let parse_fast_by_language_id = |language_id: &str| { match language_id { "vhdl" => { - do_vhdl_fast(&path, backend) + do_vhdl_fast(&path, &file_type, &tool_chain, backend) } "verilog" | "systemverilog" => { - do_sv_fast(&path, backend) + do_sv_fast(&path, &file_type, &tool_chain, backend) } _ => Err(tower_lsp::jsonrpc::Error { @@ -139,7 +160,14 @@ pub fn do_fast(path: String, backend: &Arc) -> Result { } } -fn do_sv_fast(path: &str, backend: &Arc) -> Result { +fn do_sv_fast( + path: &str, + #[allow(unused)] + file_type: &str, + #[allow(unused)] + tool_chain: &str, + backend: &Arc +) -> Result { let path_buf = PathBuf::from(&path); let doc = match make_textdocumenitem_from_path(&path_buf) { @@ -169,7 +197,8 @@ fn do_sv_fast(path: &str, backend: &Arc) -> Result { let sources = &backend.server.srcs; if let Some(syntax_tree) = parse_result { - if let Ok(fast) = make_fast_from_syntaxtree(&syntax_tree, &path_buf) { + if let Ok(mut fast) = make_fast_from_syntaxtree(&syntax_tree, &path_buf) { + fast.file_type = file_type.to_string(); let hdl_param = sources.hdl_param.clone(); hdl_param.update_fast(path.to_string(), fast.clone()); return Ok(fast); @@ -183,13 +212,24 @@ fn do_sv_fast(path: &str, backend: &Arc) -> Result { }) } -fn do_vhdl_fast(path: &str, backend: &Arc) -> Result { +fn do_vhdl_fast( + path: &str, + #[allow(unused)] + file_type: &str, + #[allow(unused)] + tool_chain: &str, + backend: &Arc +) -> Result { let sources = &backend.server.srcs; let pathbuf = PathBuf::from_str(path).unwrap(); if let Some(design_file) = vhdl_parse(&pathbuf) { let hdl_param = sources.hdl_param.clone(); - if let Some(fast) = make_fast_from_design_file(&design_file) { + if let Some(mut fast) = make_fast_from_design_file(&design_file) { + fast.file_type = file_type.to_string(); hdl_param.update_fast(path.to_string(), fast.clone()); + // if file_type == "ip" { + // info!("ip debug, path: {}, fast: {:#?}", path, fast); + // } return Ok(fast); } } @@ -201,37 +241,37 @@ fn do_vhdl_fast(path: &str, backend: &Arc) -> Result { }) } -#[derive(Clone)] -pub struct UpdateFastApi; +// #[derive(Clone)] +// pub struct UpdateFastApi; -impl <'a>tower_lsp::jsonrpc::Method<&'a Arc, (DoFastApiRequestParams, ), Result> for UpdateFastApi { - type Future = future::Ready>; +// impl <'a>tower_lsp::jsonrpc::Method<&'a Arc, (DoFastApiRequestParams, ), Result> for UpdateFastApi { +// type Future = future::Ready>; - fn invoke(&self, _server: &'a Arc, _params: (DoFastApiRequestParams, )) -> Self::Future { - let request_param = _params.0; - let path = request_param.path; - let hdlparam = update_fast(path, _server); - future::ready(hdlparam) - } -} +// fn invoke(&self, _server: &'a Arc, _params: (DoFastApiRequestParams, )) -> Self::Future { +// let request_param = _params.0; +// let path = request_param.path; +// let hdlparam = update_fast(path, _server); +// future::ready(hdlparam) +// } +// } -pub fn update_fast(path: String, backend: &Arc) -> Result { - { - let fast_sync_controller = backend.server.srcs.fast_sync_controller.read().unwrap(); - if let Some(fast_lock) = fast_sync_controller.get(&path) { - let fast_lock = fast_lock.clone(); - drop(fast_sync_controller); - let _unused = fast_lock.write().unwrap(); - } - } +// pub fn update_fast(path: String, backend: &Arc) -> Result { +// { +// let fast_sync_controller = backend.server.srcs.fast_sync_controller.read().unwrap(); +// if let Some(fast_lock) = fast_sync_controller.get(&path) { +// let fast_lock = fast_lock.clone(); +// drop(fast_sync_controller); +// let _unused = fast_lock.write().unwrap(); +// } +// } - // 去缓存中寻找 - let hdl_param = backend.server.srcs.hdl_param.clone(); - let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap(); - if let Some(hdl_file) = path_to_hdl_file.get(&path) { - let fast = hdl_file.fast.clone(); - Ok(fast) - } else { - do_fast(path, backend) - } -} \ No newline at end of file +// // 去缓存中寻找 +// let hdl_param = backend.server.srcs.hdl_param.clone(); +// let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap(); +// if let Some(hdl_file) = path_to_hdl_file.get(&path) { +// let fast = hdl_file.fast.clone(); +// Ok(fast) +// } else { +// do_fast(path, backend) +// } +// } \ No newline at end of file