diff --git a/src/completion/feature.rs b/src/completion/feature.rs index fe81758..9aaeeea 100644 --- a/src/completion/feature.rs +++ b/src/completion/feature.rs @@ -167,35 +167,58 @@ fn get_position_port_param_completion( // 补全当前 module 的所有 param if let Some((inst_module, file_type, _)) = hdl_param.find_module_context_by_name(&instance.inst_type) { let mut completion_items = Vec::::new(); - for param in inst_module.params { - let label_details = CompletionItemLabelDetails { - detail: None, - ..CompletionItemLabelDetails::default() - }; + match file_type.as_str() { + "primitives" => { + if let Some(primitives_inst) = inst_module.instances.first() { + for param_assignment in &primitives_inst.intstparam_assignments { + let label_details = CompletionItemLabelDetails { + detail: None, + ..CompletionItemLabelDetails::default() + }; - let param_desc = match file_type.as_str() { - "common" => { - param.to_vlog_description() - } - "ip" => { - param.to_vhdl_description() - } - "primitives" => { - param.to_vlog_description() - } - _ => { - param.to_vlog_description() - } - }; + let name = param_assignment.parameter.clone().unwrap(); + let param_desc = format!("parameter {}", name); - let c_item = CompletionItem { - label: param.name, - detail: Some(param_desc), - label_details: Some(label_details), - kind: Some(CompletionItemKind::TYPE_PARAMETER), - ..CompletionItem::default() - }; - completion_items.push(c_item); + let c_item = CompletionItem { + label: name, + detail: Some(param_desc), + label_details: Some(label_details), + kind: Some(CompletionItemKind::TYPE_PARAMETER), + ..CompletionItem::default() + }; + completion_items.push(c_item); + } + } + } + _ => { + for param in inst_module.params { + let label_details = CompletionItemLabelDetails { + detail: None, + ..CompletionItemLabelDetails::default() + }; + + let param_desc = match file_type.as_str() { + "common" => { + param.to_vlog_description() + } + "ip" => { + param.to_vhdl_description() + } + _ => { + param.to_vlog_description() + } + }; + + let c_item = CompletionItem { + label: param.name, + detail: Some(param_desc), + label_details: Some(label_details), + kind: Some(CompletionItemKind::TYPE_PARAMETER), + ..CompletionItem::default() + }; + completion_items.push(c_item); + } + } } return Some(CompletionList { is_incomplete: false, @@ -210,35 +233,58 @@ fn get_position_port_param_completion( if port_range.contains(pos) { if let Some((inst_module, file_type, _)) = hdl_param.find_module_context_by_name(&instance.inst_type) { let mut completion_items = Vec::::new(); - for port in inst_module.ports { - let label_details = CompletionItemLabelDetails { - detail: None, - ..CompletionItemLabelDetails::default() - }; + match file_type.as_str() { + "primitives" => { + if let Some(primitives_inst) = inst_module.instances.first() { + for port_assignment in &primitives_inst.intstport_assignments { + let label_details = CompletionItemLabelDetails { + detail: None, + ..CompletionItemLabelDetails::default() + }; - let port_desc = match file_type.as_str() { - "common" => { - port.to_vlog_description() - } - "ip" => { - port.to_vhdl_description() - } - "primitives" => { - port.to_vlog_description() - } - _ => { - port.to_vlog_description() - } - }; + let name = port_assignment.port.clone().unwrap(); + let port_desc = format!("parameter {}", name); - let c_item = CompletionItem { - label: port.name, - detail: Some(port_desc), - label_details: Some(label_details), - kind: Some(CompletionItemKind::PROPERTY), - ..CompletionItem::default() - }; - completion_items.push(c_item); + let c_item = CompletionItem { + label: name, + detail: Some(port_desc), + label_details: Some(label_details), + kind: Some(CompletionItemKind::PROPERTY), + ..CompletionItem::default() + }; + completion_items.push(c_item); + } + } + } + _ => { + for port in inst_module.ports { + let label_details = CompletionItemLabelDetails { + detail: None, + ..CompletionItemLabelDetails::default() + }; + + let port_desc = match file_type.as_str() { + "common" => { + port.to_vlog_description() + } + "ip" => { + port.to_vhdl_description() + } + _ => { + port.to_vlog_description() + } + }; + + let c_item = CompletionItem { + label: port.name, + detail: Some(port_desc), + label_details: Some(label_details), + kind: Some(CompletionItemKind::PROPERTY), + ..CompletionItem::default() + }; + completion_items.push(c_item); + } + } } return Some(CompletionList { is_incomplete: false, diff --git a/src/completion/sv.rs b/src/completion/sv.rs index fd270c9..63a60d0 100644 --- a/src/completion/sv.rs +++ b/src/completion/sv.rs @@ -201,6 +201,34 @@ fn get_completion_token(text: &Rope, line: RopeSlice, pos: Position) -> String { } } +fn make_primitives_instantiation_code(text: &str) -> String { + let mut instantiations = text.lines() + .filter(|line| !line.trim().is_empty() && !line.trim().starts_with("//")) + .collect::>(); + // remove fake module and endmodule + instantiations.remove(0); + instantiations.pop(); + + instantiations.iter().map(|line| { + let trimmed = line.trim_start(); + if trimmed.contains('.') { + format!("\t{}", trimmed) + } else { + trimmed.to_string() + } + }).collect::>().join("\n") +} + +fn make_primitives_module_profile_code(text: &str) -> String { + let mut lines: Vec<&str> = text.split_inclusive('\n').collect(); + + if lines.len() > 1 { + lines.remove(0); + lines.pop(); + } + + lines.join("") +} fn make_instantiation_code(module: &crate::core::hdlparam::Module) -> String { @@ -324,6 +352,8 @@ fn make_module_completions( } } + + module_completioms }