修复 verilator 找不到文件的问题
This commit is contained in:
parent
ff1037f0d3
commit
229fe4dc97
@ -2,9 +2,9 @@ use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use regex::Regex;
|
||||
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 crate::server::LspServer;
|
||||
use crate::{server::LspServer, utils::from_uri_to_escape_path_string};
|
||||
use super::AbstractLinterConfiguration;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -68,11 +68,14 @@ impl AbstractLinterConfiguration for VerilatorConfiguration {
|
||||
let pathbuf = uri.to_file_path().unwrap();
|
||||
let path_string = pathbuf.to_str().unwrap();
|
||||
|
||||
let include_args = make_include_args(server, path_string);
|
||||
|
||||
let child = Command::new(&invoke_name)
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.args(&self.linter.args)
|
||||
.args(include_args)
|
||||
.arg(path_string)
|
||||
.spawn()
|
||||
.ok()?;
|
||||
@ -206,4 +209,35 @@ fn match_not_module_found(error_line: &str) -> Option<String> {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user