add primitives port/param auto completion
This commit is contained in:
parent
82b4f6f092
commit
ec5e1f19c4
@ -167,6 +167,30 @@ 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::<CompletionItem>::new();
|
||||
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 name = param_assignment.parameter.clone().unwrap();
|
||||
let param_desc = format!("parameter {}", name);
|
||||
|
||||
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,
|
||||
@ -180,9 +204,6 @@ fn get_position_port_param_completion(
|
||||
"ip" => {
|
||||
param.to_vhdl_description()
|
||||
}
|
||||
"primitives" => {
|
||||
param.to_vlog_description()
|
||||
}
|
||||
_ => {
|
||||
param.to_vlog_description()
|
||||
}
|
||||
@ -197,6 +218,8 @@ fn get_position_port_param_completion(
|
||||
};
|
||||
completion_items.push(c_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Some(CompletionList {
|
||||
is_incomplete: false,
|
||||
items: completion_items
|
||||
@ -210,6 +233,30 @@ 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::<CompletionItem>::new();
|
||||
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 name = port_assignment.port.clone().unwrap();
|
||||
let port_desc = format!("parameter {}", name);
|
||||
|
||||
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,
|
||||
@ -223,9 +270,6 @@ fn get_position_port_param_completion(
|
||||
"ip" => {
|
||||
port.to_vhdl_description()
|
||||
}
|
||||
"primitives" => {
|
||||
port.to_vlog_description()
|
||||
}
|
||||
_ => {
|
||||
port.to_vlog_description()
|
||||
}
|
||||
@ -240,6 +284,8 @@ fn get_position_port_param_completion(
|
||||
};
|
||||
completion_items.push(c_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Some(CompletionList {
|
||||
is_incomplete: false,
|
||||
items: completion_items
|
||||
|
@ -217,6 +217,17 @@ fn make_primitives_instantiation_code(text: &str) -> String {
|
||||
}).collect::<Vec<String>>().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 {
|
||||
// makeVlogParamAssignments 参数信息列表
|
||||
@ -298,8 +309,8 @@ fn make_module_completions(
|
||||
let primitive_map = server.srcs.primitive_text.name_to_text.read().unwrap();
|
||||
if let Some(text) = primitive_map.get(&module.name) {
|
||||
(
|
||||
make_primitives_instantiation_code(&text),
|
||||
(*text).clone(),
|
||||
make_primitives_instantiation_code(text),
|
||||
make_primitives_module_profile_code(text),
|
||||
format!("[Definition] Primitive module: {}", module.name)
|
||||
)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user