修复 verilator 找不到文件的问题

This commit is contained in:
锦恢 2025-01-05 16:04:31 +08:00
parent ff1037f0d3
commit 229fe4dc97

View File

@ -2,9 +2,9 @@ use log::info;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use regex::Regex; use regex::Regex;
use ropey::Rope; use ropey::Rope;
use std::process::{Command, Stdio}; use std::{collections::HashSet, path::{Path, PathBuf}, process::{Command, Stdio}, str::FromStr};
use tower_lsp::lsp_types::*; use tower_lsp::lsp_types::*;
use crate::server::LspServer; use crate::{server::LspServer, utils::from_uri_to_escape_path_string};
use super::AbstractLinterConfiguration; use super::AbstractLinterConfiguration;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -68,11 +68,14 @@ impl AbstractLinterConfiguration for VerilatorConfiguration {
let pathbuf = uri.to_file_path().unwrap(); let pathbuf = uri.to_file_path().unwrap();
let path_string = pathbuf.to_str().unwrap(); let path_string = pathbuf.to_str().unwrap();
let include_args = make_include_args(server, path_string);
let child = Command::new(&invoke_name) let child = Command::new(&invoke_name)
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stderr(Stdio::piped()) .stderr(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.args(&self.linter.args) .args(&self.linter.args)
.args(include_args)
.arg(path_string) .arg(path_string)
.spawn() .spawn()
.ok()?; .ok()?;
@ -206,4 +209,35 @@ fn match_not_module_found(error_line: &str) -> Option<String> {
} }
None None
}
fn make_include_args(
server: &LspServer,
path_string: &str
) -> Vec::<String> {
let mut include_paths = HashSet::<String>::new();
let configuration = server.configuration.read().unwrap();
let workspace = configuration.workspace_folder.clone().unwrap();
let path = Path::new(path_string);
if let Some(parent) = path.parent() {
let folder_string = parent.to_str().unwrap();
include_paths.insert(format!("-I{}", folder_string));
}
let workspace_path = from_uri_to_escape_path_string(&workspace);
if let Some(workspace_path) = workspace_path {
let workspace = PathBuf::from_str(&workspace_path).unwrap();
let src_path = workspace.join("user").join("src");
let sim_path = workspace.join("user").join("sim");
include_paths.insert(src_path.to_str().unwrap().to_string());
include_paths.insert(sim_path.to_str().unwrap().to_string());
include_paths.insert(workspace_path);
}
let mut include_args = Vec::<String>::new();
for path in include_paths {
include_args.push(format!("-I{}", path));
}
include_args
} }