完成 CodeLens 的支持, Run | Test
This commit is contained in:
parent
348214e42d
commit
9bb54e0327
@ -1,6 +1,6 @@
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
|
||||
use crate::server::LSPServer;
|
||||
use crate::{core, server::LSPServer};
|
||||
#[allow(unused)]
|
||||
use log::info;
|
||||
use tower_lsp::lsp_types::*;
|
||||
@ -21,37 +21,63 @@ pub fn code_lens(
|
||||
let pathbuf = to_escape_path(&pathbuf);
|
||||
let path_string = pathbuf.to_str().unwrap();
|
||||
|
||||
info!("[code_lens] {}", path_string);
|
||||
|
||||
let mut code_lens_array = Vec::<CodeLens>::new();
|
||||
if let Some(hdl_file) = path_to_hdl_file.get(path_string) {
|
||||
for module in &hdl_file.fast.content {
|
||||
// 此处只有 name 和 path 有用
|
||||
let module_data_item: serde_json::Value = serde_json::json!({
|
||||
"icon": "",
|
||||
"name": module.name.to_string(),
|
||||
"type": "",
|
||||
"doFastFileType": "common",
|
||||
"range": null,
|
||||
"path": path_string.to_string(),
|
||||
"parent": null
|
||||
});
|
||||
|
||||
let command = Command {
|
||||
title: "Simulate".to_string(),
|
||||
command: "digital-ide.tool.icarus.simulateFile".to_string(),
|
||||
arguments: Some(vec![module_data_item])
|
||||
};
|
||||
let code_lens = CodeLens {
|
||||
range: module.range.to_lsp_range(),
|
||||
command: Some(command),
|
||||
data: None
|
||||
};
|
||||
code_lens_array.push(code_lens);
|
||||
code_lens_array.push(make_run_code_lens(path_string, module));
|
||||
code_lens_array.push(make_test_code_lens(path_string, module));
|
||||
}
|
||||
|
||||
return Some(code_lens_array);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// 快速仿真用的 按钮
|
||||
fn make_test_code_lens(
|
||||
path_string: &str,
|
||||
module: &core::hdlparam::Module
|
||||
) -> CodeLens {
|
||||
// 此处只有 name 和 path 有用
|
||||
let module_data_item: serde_json::Value = serde_json::json!({
|
||||
"icon": "",
|
||||
"name": module.name.to_string(),
|
||||
"type": "",
|
||||
"doFastFileType": "common",
|
||||
"range": null,
|
||||
"path": path_string.to_string(),
|
||||
"parent": null
|
||||
});
|
||||
let command = Command {
|
||||
title: "Test".to_string(),
|
||||
command: "digital-ide.tool.icarus.simulateFile".to_string(),
|
||||
arguments: Some(vec![module_data_item])
|
||||
};
|
||||
let code_lens = CodeLens {
|
||||
range: module.range.to_lsp_range(),
|
||||
command: Some(command),
|
||||
data: None
|
||||
};
|
||||
code_lens
|
||||
}
|
||||
|
||||
|
||||
/// netlist 用的按钮
|
||||
fn make_run_code_lens(
|
||||
path_string: &str,
|
||||
module: &core::hdlparam::Module
|
||||
) -> CodeLens {
|
||||
let file = serde_json::json!(path_string);
|
||||
let command = Command {
|
||||
title: "Run".to_string(),
|
||||
command: "digital-ide.netlist.show".to_string(),
|
||||
arguments: Some(vec![file])
|
||||
};
|
||||
let code_lens = CodeLens {
|
||||
range: module.range.to_lsp_range(),
|
||||
command: Some(command),
|
||||
data: None
|
||||
};
|
||||
code_lens
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user