add primitives auto instantiation
This commit is contained in:
parent
290d1aec05
commit
82b4f6f092
@ -199,6 +199,23 @@ 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::<Vec<&str>>();
|
||||
// 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::<Vec<String>>().join("\n")
|
||||
}
|
||||
|
||||
|
||||
fn make_instantiation_code(module: &crate::core::hdlparam::Module) -> String {
|
||||
@ -277,20 +294,34 @@ fn make_module_completions(
|
||||
if !module.name.to_string().to_lowercase().starts_with(&prefix) {
|
||||
continue;
|
||||
}
|
||||
let insert_text = make_instantiation_code(module);
|
||||
let module_profile = make_module_profile_code(module);
|
||||
let (insert_text, module_profile, define_info) = if hdl_file.fast.file_type == "primitives" {
|
||||
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(),
|
||||
format!("[Definition] Primitive module: {}", module.name)
|
||||
)
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
let path_uri = Url::from_file_path(path_string.to_string()).unwrap().to_string();
|
||||
let def_row = module.range.start.line;
|
||||
let def_col = module.range.start.character;
|
||||
|
||||
let path_uri = Url::from_file_path(path_string.to_string()).unwrap().to_string();
|
||||
let def_row = module.range.start.line;
|
||||
let def_col = module.range.start.character;
|
||||
let define_info = format!("Go to [Definition]({path_uri}#L{def_row}:{def_col})");
|
||||
(
|
||||
make_instantiation_code(module),
|
||||
make_module_profile_code(module),
|
||||
format!("Go to [Definition]({path_uri}#L{def_row}:{def_col})")
|
||||
)
|
||||
};
|
||||
|
||||
let module_profile = MarkupContent {
|
||||
kind: MarkupKind::Markdown,
|
||||
value: format!("```{}\n{}\n```\n{}", language_id, module_profile, define_info)
|
||||
};
|
||||
|
||||
|
||||
let item = CompletionItem {
|
||||
label: module.name.to_string(),
|
||||
detail: Some("module instantiation".to_string()),
|
||||
|
Loading…
x
Reference in New Issue
Block a user