diff --git a/src/main.rs b/src/main.rs index 4b875ab..e425645 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use request::{ test::CustomParamRequest, test::CustomRequest, fast::DoFastApi, + fast::SyncFastApi, config::UpdateConfigurationApi, primitives::DoPrimitivesJudgeApi }; @@ -54,7 +55,8 @@ async fn main() { .custom_method("custom/paramRequest", CustomParamRequest) // for test .custom_method("api/fast", DoFastApi) .custom_method("api/do-primitives-judge", DoPrimitivesJudgeApi) - .custom_method("api/update-fast", UpdateConfigurationApi) + .custom_method("api/update-configuration", UpdateConfigurationApi) + .custom_method("api/sync-fast", SyncFastApi) .finish(); Server::new(stdin, stdout, socket) diff --git a/src/request/fast.rs b/src/request/fast.rs index da2f8a8..be86625 100644 --- a/src/request/fast.rs +++ b/src/request/fast.rs @@ -33,7 +33,6 @@ pub struct DoFastApi; impl <'a>tower_lsp::jsonrpc::Method<&'a Arc, (DoFastApiRequestParams, ), Result> for DoFastApi { type Future = future::Ready>; - fn invoke(&self, _server: &'a Arc, _params: (DoFastApiRequestParams, )) -> Self::Future { let request_param = _params.0; let path = request_param.path; @@ -44,6 +43,30 @@ impl <'a>tower_lsp::jsonrpc::Method<&'a Arc, (DoFastApiRequestParams, ) } } + +#[derive(Deserialize, Serialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct SyncFastApiRequestParams { + path: String, + file_type: String, + tool_chain: String +} + +#[derive(Clone)] +pub struct SyncFastApi; + +impl <'a>tower_lsp::jsonrpc::Method<&'a Arc, (SyncFastApiRequestParams, ), Result> for SyncFastApi { + type Future = future::Ready>; + fn invoke(&self, _server: &'a Arc, _params: (SyncFastApiRequestParams, )) -> Self::Future { + let request_param = _params.0; + let path = request_param.path; + let file_type = request_param.file_type; + let tool_chain = request_param.tool_chain; + let hdlparam = sync_fast(path, file_type, tool_chain, _server); + future::ready(hdlparam) + } +} + fn make_textdocumenitem_from_path(path_buf: &PathBuf) -> Option { if let Ok(url) = Url::from_file_path(path_buf) { if let Ok(text) = fs::read_to_string(path_buf) { @@ -141,6 +164,7 @@ fn do_sv_fast( ) -> Result { let path_buf = PathBuf::from(&path); + // 从 pathbuf 中读取文本并作为 TextDocumentItem 打开 let doc = match make_textdocumenitem_from_path(&path_buf) { Some(doc) => doc, None => { @@ -269,3 +293,39 @@ fn do_vhdl_fast( data: None }) } + + +pub fn sync_fast( + path: String, + file_type: String, + tool_chain: String, + backend: &Arc +) -> Result { + // 根据 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!("{}/synth/{}.vhd", path, basename) + } else { + path + } + }; + + { + let uri = Url::from_file_path(path.to_string()).unwrap(); + let file_id = backend.server.srcs.get_id(&uri); + if let Some(file) = backend.server.srcs.get_file(file_id) { + let _ = file.read().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, file_type, tool_chain, backend) + } +} \ No newline at end of file