增加对于 IP 的解析
This commit is contained in:
parent
3a4bd0c7e4
commit
cea86eb8f9
@ -303,6 +303,8 @@ pub struct Macro {
|
|||||||
pub struct FastHdlparam {
|
pub struct FastHdlparam {
|
||||||
#[serde(rename = "macro")]
|
#[serde(rename = "macro")]
|
||||||
pub fast_macro: Macro,
|
pub fast_macro: Macro,
|
||||||
|
#[serde(rename = "fileType")]
|
||||||
|
pub file_type: String,
|
||||||
pub content: Vec<Module>
|
pub content: Vec<Module>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,10 @@ pub fn sv_parser(path: &str) -> Option<FastHdlparam> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Result<FastHdlparam, std::io::Error> {
|
pub fn make_fast_from_syntaxtree(
|
||||||
|
syntax_tree: &SyntaxTree,
|
||||||
|
path: &PathBuf
|
||||||
|
) -> Result<FastHdlparam, std::io::Error> {
|
||||||
// 对不同操作系统文件路径的支持
|
// 对不同操作系统文件路径的支持
|
||||||
let path = to_escape_path(path);
|
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),
|
includes: get_includes(&path),
|
||||||
invalid: Vec::new()
|
invalid: Vec::new()
|
||||||
},
|
},
|
||||||
content: Vec::new()
|
content: Vec::new(),
|
||||||
|
file_type: "common".to_string()
|
||||||
};
|
};
|
||||||
let mut ansi_port_last_dir = "";
|
let mut ansi_port_last_dir = "";
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ pub fn vhdl_parser(path: &str) -> FastHdlparam {
|
|||||||
includes: Vec::new(),
|
includes: Vec::new(),
|
||||||
invalid: Vec::new()
|
invalid: Vec::new()
|
||||||
},
|
},
|
||||||
content: Vec::new()
|
content: Vec::new(),
|
||||||
|
file_type: "common".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let parser = VHDLParser::new(VHDLStandard::VHDL2008);
|
let parser = VHDLParser::new(VHDLStandard::VHDL2008);
|
||||||
@ -52,7 +53,8 @@ pub fn make_fast_from_design_file(design_file: &DesignFile) -> Option<FastHdlpar
|
|||||||
includes: Vec::new(),
|
includes: Vec::new(),
|
||||||
invalid: Vec::new()
|
invalid: Vec::new()
|
||||||
},
|
},
|
||||||
content: Vec::new()
|
content: Vec::new(),
|
||||||
|
file_type: "common".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut all_tockens = Vec::new();
|
let mut all_tockens = Vec::new();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
use request::{ CustomParamRequest, CustomRequest, DoFastApi, UpdateFastApi };
|
use request::{ CustomParamRequest, CustomRequest, DoFastApi };
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -46,7 +46,7 @@ async fn main() {
|
|||||||
.custom_method("custom/request", CustomRequest)
|
.custom_method("custom/request", CustomRequest)
|
||||||
.custom_method("custom/paramRequest", CustomParamRequest)
|
.custom_method("custom/paramRequest", CustomParamRequest)
|
||||||
.custom_method("api/fast", DoFastApi)
|
.custom_method("api/fast", DoFastApi)
|
||||||
.custom_method("api/update-fast", UpdateFastApi)
|
// .custom_method("api/update-fast", UpdateFastApi)
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
Server::new(stdin, stdout, socket)
|
Server::new(stdin, stdout, socket)
|
||||||
|
@ -59,8 +59,11 @@ pub fn custom_param_request(param: String) -> Result<i32> {
|
|||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct DoFastApiRequestParams {
|
pub struct DoFastApiRequestParams {
|
||||||
path: String,
|
path: String,
|
||||||
|
file_type: String,
|
||||||
|
tool_chain: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -73,7 +76,9 @@ impl <'a>tower_lsp::jsonrpc::Method<&'a Arc<Backend>, (DoFastApiRequestParams, )
|
|||||||
fn invoke(&self, _server: &'a Arc<Backend>, _params: (DoFastApiRequestParams, )) -> Self::Future {
|
fn invoke(&self, _server: &'a Arc<Backend>, _params: (DoFastApiRequestParams, )) -> Self::Future {
|
||||||
let request_param = _params.0;
|
let request_param = _params.0;
|
||||||
let path = request_param.path;
|
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)
|
future::ready(hdlparam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,19 +94,35 @@ fn make_textdocumenitem_from_path(path_buf: &PathBuf) -> Option<TextDocumentItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 前端交互接口: do_fast,输入文件路径,计算出对应的 fast 结构
|
/// 前端交互接口: do_fast,输入文件路径,计算出对应的 fast 结构
|
||||||
pub fn do_fast(path: String, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
pub fn do_fast(
|
||||||
info!("parse fast \"{}\"", path);
|
path: String,
|
||||||
|
file_type: String,
|
||||||
|
tool_chain: String,
|
||||||
|
backend: &Arc<Backend>
|
||||||
|
) -> Result<FastHdlparam> {
|
||||||
|
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 language_id = get_language_id_by_path_str(&path);
|
||||||
|
|
||||||
let parse_fast_by_language_id = |language_id: &str| {
|
let parse_fast_by_language_id = |language_id: &str| {
|
||||||
match language_id {
|
match language_id {
|
||||||
"vhdl" => {
|
"vhdl" => {
|
||||||
do_vhdl_fast(&path, backend)
|
do_vhdl_fast(&path, &file_type, &tool_chain, backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
"verilog" | "systemverilog" => {
|
"verilog" | "systemverilog" => {
|
||||||
do_sv_fast(&path, backend)
|
do_sv_fast(&path, &file_type, &tool_chain, backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => Err(tower_lsp::jsonrpc::Error {
|
_ => Err(tower_lsp::jsonrpc::Error {
|
||||||
@ -139,7 +160,14 @@ pub fn do_fast(path: String, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_sv_fast(path: &str, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
fn do_sv_fast(
|
||||||
|
path: &str,
|
||||||
|
#[allow(unused)]
|
||||||
|
file_type: &str,
|
||||||
|
#[allow(unused)]
|
||||||
|
tool_chain: &str,
|
||||||
|
backend: &Arc<Backend>
|
||||||
|
) -> Result<FastHdlparam> {
|
||||||
let path_buf = PathBuf::from(&path);
|
let path_buf = PathBuf::from(&path);
|
||||||
|
|
||||||
let doc = match make_textdocumenitem_from_path(&path_buf) {
|
let doc = match make_textdocumenitem_from_path(&path_buf) {
|
||||||
@ -169,7 +197,8 @@ fn do_sv_fast(path: &str, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
|||||||
|
|
||||||
let sources = &backend.server.srcs;
|
let sources = &backend.server.srcs;
|
||||||
if let Some(syntax_tree) = parse_result {
|
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();
|
let hdl_param = sources.hdl_param.clone();
|
||||||
hdl_param.update_fast(path.to_string(), fast.clone());
|
hdl_param.update_fast(path.to_string(), fast.clone());
|
||||||
return Ok(fast);
|
return Ok(fast);
|
||||||
@ -183,13 +212,24 @@ fn do_sv_fast(path: &str, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_vhdl_fast(path: &str, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
fn do_vhdl_fast(
|
||||||
|
path: &str,
|
||||||
|
#[allow(unused)]
|
||||||
|
file_type: &str,
|
||||||
|
#[allow(unused)]
|
||||||
|
tool_chain: &str,
|
||||||
|
backend: &Arc<Backend>
|
||||||
|
) -> Result<FastHdlparam> {
|
||||||
let sources = &backend.server.srcs;
|
let sources = &backend.server.srcs;
|
||||||
let pathbuf = PathBuf::from_str(path).unwrap();
|
let pathbuf = PathBuf::from_str(path).unwrap();
|
||||||
if let Some(design_file) = vhdl_parse(&pathbuf) {
|
if let Some(design_file) = vhdl_parse(&pathbuf) {
|
||||||
let hdl_param = sources.hdl_param.clone();
|
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());
|
hdl_param.update_fast(path.to_string(), fast.clone());
|
||||||
|
// if file_type == "ip" {
|
||||||
|
// info!("ip debug, path: {}, fast: {:#?}", path, fast);
|
||||||
|
// }
|
||||||
return Ok(fast);
|
return Ok(fast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,37 +241,37 @@ fn do_vhdl_fast(path: &str, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
// #[derive(Clone)]
|
||||||
pub struct UpdateFastApi;
|
// pub struct UpdateFastApi;
|
||||||
|
|
||||||
impl <'a>tower_lsp::jsonrpc::Method<&'a Arc<Backend>, (DoFastApiRequestParams, ), Result<FastHdlparam>> for UpdateFastApi {
|
// impl <'a>tower_lsp::jsonrpc::Method<&'a Arc<Backend>, (DoFastApiRequestParams, ), Result<FastHdlparam>> for UpdateFastApi {
|
||||||
type Future = future::Ready<Result<FastHdlparam>>;
|
// type Future = future::Ready<Result<FastHdlparam>>;
|
||||||
|
|
||||||
fn invoke(&self, _server: &'a Arc<Backend>, _params: (DoFastApiRequestParams, )) -> Self::Future {
|
// fn invoke(&self, _server: &'a Arc<Backend>, _params: (DoFastApiRequestParams, )) -> Self::Future {
|
||||||
let request_param = _params.0;
|
// let request_param = _params.0;
|
||||||
let path = request_param.path;
|
// let path = request_param.path;
|
||||||
let hdlparam = update_fast(path, _server);
|
// let hdlparam = update_fast(path, _server);
|
||||||
future::ready(hdlparam)
|
// future::ready(hdlparam)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn update_fast(path: String, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
// pub fn update_fast(path: String, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
||||||
{
|
// {
|
||||||
let fast_sync_controller = backend.server.srcs.fast_sync_controller.read().unwrap();
|
// let fast_sync_controller = backend.server.srcs.fast_sync_controller.read().unwrap();
|
||||||
if let Some(fast_lock) = fast_sync_controller.get(&path) {
|
// if let Some(fast_lock) = fast_sync_controller.get(&path) {
|
||||||
let fast_lock = fast_lock.clone();
|
// let fast_lock = fast_lock.clone();
|
||||||
drop(fast_sync_controller);
|
// drop(fast_sync_controller);
|
||||||
let _unused = fast_lock.write().unwrap();
|
// let _unused = fast_lock.write().unwrap();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 去缓存中寻找
|
// // 去缓存中寻找
|
||||||
let hdl_param = backend.server.srcs.hdl_param.clone();
|
// let hdl_param = backend.server.srcs.hdl_param.clone();
|
||||||
let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
// let path_to_hdl_file = hdl_param.path_to_hdl_file.read().unwrap();
|
||||||
if let Some(hdl_file) = path_to_hdl_file.get(&path) {
|
// if let Some(hdl_file) = path_to_hdl_file.get(&path) {
|
||||||
let fast = hdl_file.fast.clone();
|
// let fast = hdl_file.fast.clone();
|
||||||
Ok(fast)
|
// Ok(fast)
|
||||||
} else {
|
// } else {
|
||||||
do_fast(path, backend)
|
// do_fast(path, backend)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
Loading…
x
Reference in New Issue
Block a user