diff --git a/src/core/sv_parser.rs b/src/core/sv_parser.rs index 4038b77..35dc85e 100644 --- a/src/core/sv_parser.rs +++ b/src/core/sv_parser.rs @@ -2,6 +2,7 @@ use std::fs::File; use std::io::BufRead; use std::{collections::HashMap, io::BufReader}; use std::path::PathBuf; +use anyhow::Error; use sv_parser::{parse_sv, unwrap_node, ConstantMintypmaxExpression, GateInstantiation, ListOfParameterAssignments, ListOfPortConnections, Locate, PackedDimensionRange, RefNode, SyntaxTree}; use super::fast_hdlparam::{FastHdlparam, Macro}; @@ -16,14 +17,15 @@ pub fn sv_parser(path: &str) -> Option { let result = parse_sv(&path, &defines, &includes, false, true); if let Ok((syntax_tree, _)) = result { - let hdlparam = make_fast_from_syntaxtree(&syntax_tree, &path); - return Some(hdlparam); + if let Ok(hdlparam) = make_fast_from_syntaxtree(&syntax_tree, &path) { + return Some(hdlparam); + } } None } -pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> FastHdlparam { +pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Result { let mut hdlparam = FastHdlparam { fast_macro: Macro { defines: Vec::new(), @@ -96,8 +98,13 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Fa let (mut end_line, mut end_character) = (id.line, start_character + id.len as u32); let net_type = match unwrap_node!(param_node, DataType) { Some(RefNode::DataType(data_type)) => { - let id = get_identifier(unwrap_node!(data_type, SimpleIdentifier, Keyword).unwrap()).unwrap(); - syntax_tree.get_str(&id).unwrap() + let id = unwrap_node!(data_type, SimpleIdentifier, Keyword); + if id == None { + "wire" + } else { + let id = get_identifier(id.unwrap()).unwrap(); + syntax_tree.get_str(&id).unwrap() + } } _ => "wire" }; @@ -129,8 +136,12 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Fa let net_type = match unwrap_node!(x, DataType, ImplicitDataType) { Some(RefNode::DataType(x)) => { - let id = unwrap_node!(x, Keyword).unwrap(); - syntax_tree.get_str(&get_identifier(id).unwrap()).unwrap() + let id = unwrap_node!(x, Keyword); + if id != None { + syntax_tree.get_str(&get_identifier(id.unwrap()).unwrap()).unwrap() + } else { + "unknown" + } }, Some(RefNode::ImplicitDataType(_)) => "wire", _ => "unknown" @@ -180,8 +191,12 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Fa } else { match unwrap_node!(x, DataType, ImplicitDataType) { Some(RefNode::DataType(x)) => { - let id = unwrap_node!(x, Keyword).unwrap(); - syntax_tree.get_str(&get_identifier(id).unwrap()).unwrap() + let id = unwrap_node!(x, Keyword); + if id != None { + syntax_tree.get_str(&get_identifier(id.unwrap()).unwrap()).unwrap() + } else { + "unknown" + } }, Some(RefNode::ImplicitDataType(_)) => "wire", _ => "unknown" @@ -276,7 +291,7 @@ pub fn make_fast_from_syntaxtree(syntax_tree: &SyntaxTree, path: &PathBuf) -> Fa } } - hdlparam + Ok(hdlparam) } fn get_inst_param_last_locate(x: &ListOfParameterAssignments) -> Option<(Locate, Locate)> { diff --git a/src/custom_request.rs b/src/custom_request.rs index 0b11294..d1e1da4 100644 --- a/src/custom_request.rs +++ b/src/custom_request.rs @@ -114,8 +114,9 @@ pub fn do_fast(path: String) -> Result { ); if let Some(syntax_tree) = parse_result { - let hdlparam = make_fast_from_syntaxtree(&syntax_tree, &path_buf); - return Ok(hdlparam); + if let Ok(hdlparam) = make_fast_from_syntaxtree(&syntax_tree, &path_buf) { + return Ok(hdlparam); + } } let api_error = tower_lsp::jsonrpc::Error { diff --git a/src/sources.rs b/src/sources.rs index 584f678..3437658 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -239,7 +239,19 @@ impl Sources { // 计算 fast if let Some(syntax_tree) = &syntax_tree { let path = PathBuf::from(uri.path().to_string()); - let fast = make_fast_from_syntaxtree(&syntax_tree, &path); + let fast = if let Ok(fast) = make_fast_from_syntaxtree(&syntax_tree, &path) { + fast + } else { + crate::core::fast_hdlparam::FastHdlparam { + fast_macro: crate::core::fast_hdlparam::Macro { + defines: Vec::new(), + errors: Vec::new(), + includes: Vec::new(), + invalid: Vec::new() + }, + content: Vec::new() + } + }; update_fast_to_client(backend.clone(), fast); } diff --git a/testfiles/hierarchical_name_of_type.sv b/testfiles/hierarchical_name_of_type.sv new file mode 100644 index 0000000..3ff199d --- /dev/null +++ b/testfiles/hierarchical_name_of_type.sv @@ -0,0 +1,8 @@ +module ibex_alu #( + parameter ibex_pkg::rv32b_e RV32B = ibex_pkg::RV32BNone +) ( + input ibex_pkg::alu_op_e operator_i, + input logic[31:0] operand_a_i, + input logic[31:0] operand_b_i +); +endmodule \ No newline at end of file