This commit is contained in:
锦恢 2025-01-08 19:32:33 +08:00
parent 1d04a5f1cf
commit f2ccd76a65

View File

@ -158,10 +158,13 @@ impl AbstractLinterConfiguration for VerilatorConfiguration {
_ => "".to_string(), _ => "".to_string(),
}; };
// TODO: 支持更多的报错
let end_pos = refine_end_pos(rope, &message, pos);
let message = format!("{}\n\n{}", message, error_tuple.1); let message = format!("{}\n\n{}", message, error_tuple.1);
let diagnostic = Diagnostic { let diagnostic = Diagnostic {
range: Range::new(pos, pos), range: Range::new(pos, end_pos),
code: None, code: None,
severity, severity,
source: Some("Digital IDE: verilator".to_string()), source: Some("Digital IDE: verilator".to_string()),
@ -201,7 +204,6 @@ fn match_not_module_found(error_line: &str) -> Option<String> {
strings.push(char); strings.push(char);
} }
info!("strings: {:?}", strings);
if strings.starts_with("'") && strings.ends_with("'") { if strings.starts_with("'") && strings.ends_with("'") {
strings = strings[1 .. strings.len() - 1].to_string(); strings = strings[1 .. strings.len() - 1].to_string();
} }
@ -222,7 +224,8 @@ fn make_include_args(
let path = Path::new(path_string); let path = Path::new(path_string);
if let Some(parent) = path.parent() { if let Some(parent) = path.parent() {
let folder_string = parent.to_str().unwrap(); let folder_string = parent.to_str().unwrap();
include_paths.insert(format!("-I{}", folder_string)); // 加入目标文件的 __dirname
include_paths.insert(folder_string.to_string());
} }
let workspace_path = from_uri_to_escape_path_string(&workspace); let workspace_path = from_uri_to_escape_path_string(&workspace);
@ -230,8 +233,11 @@ fn make_include_args(
let workspace = PathBuf::from_str(&workspace_path).unwrap(); let workspace = PathBuf::from_str(&workspace_path).unwrap();
let src_path = workspace.join("user").join("src"); let src_path = workspace.join("user").join("src");
let sim_path = workspace.join("user").join("sim"); let sim_path = workspace.join("user").join("sim");
// 加入 user/src
include_paths.insert(src_path.to_str().unwrap().to_string()); include_paths.insert(src_path.to_str().unwrap().to_string());
// 加入 user/sim
include_paths.insert(sim_path.to_str().unwrap().to_string()); include_paths.insert(sim_path.to_str().unwrap().to_string());
// 加入 workspace
include_paths.insert(workspace_path); include_paths.insert(workspace_path);
} }
@ -241,3 +247,26 @@ fn make_include_args(
} }
include_args include_args
} }
fn refine_end_pos(
rope: &Rope,
message: &str,
pos: Position
) -> Position {
if message.starts_with("Cannot find include file") {
let mut pls = message.split(":");
if let Some(include_name) = pls.nth(1) {
let include_name = include_name.trim();
let line_text = rope.line(pos.line as usize).to_string();
if let Some(index) = line_text.find(include_name) {
let end_character = index + include_name.len() + 1;
let pos = Position {
line: pos.line,
character: end_character as u32
};
return pos;
}
}
}
pos
}