Skip to content

Commit 608135a

Browse files
author
damc
committed
api Allow use of plugins via .svls.toml
1 parent e255e64 commit 608135a

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

src/backend.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,42 @@ impl Backend {
6161
} else {
6262
PathBuf::from("")
6363
};
64+
let mut linter = self.linter.write().unwrap();
65+
if let Some(ref mut linter) = *linter {
6466

65-
let config = self.config.read().unwrap();
66-
let mut include_paths = Vec::new();
67-
let mut defines = HashMap::new();
68-
if let Some(ref config) = *config {
69-
for path in &config.verilog.include_paths {
70-
let mut p = root_uri.clone();
71-
p.push(PathBuf::from(path));
72-
include_paths.push(p);
73-
}
74-
for define in &config.verilog.defines {
75-
let mut define = define.splitn(2, '=');
76-
let ident = String::from(define.next().unwrap());
77-
let text = define
78-
.next()
79-
.and_then(|x| enquote::unescape(x, None).ok())
80-
.map(|x| DefineText::new(x, None));
81-
let define = Define::new(ident.clone(), vec![], text);
82-
defines.insert(ident, Some(define));
83-
}
84-
};
85-
debug!("include_paths: {:?}", include_paths);
86-
debug!("defines: {:?}", defines);
67+
let config = self.config.read().unwrap();
68+
let mut include_paths = Vec::new();
69+
let mut defines = HashMap::new();
70+
if let Some(ref config) = *config {
71+
for path in &config.verilog.include_paths {
72+
let mut p = root_uri.clone();
73+
p.push(PathBuf::from(path));
74+
include_paths.push(p);
75+
}
76+
for define in &config.verilog.defines {
77+
let mut define = define.splitn(2, '=');
78+
let ident = String::from(define.next().unwrap());
79+
let text = define
80+
.next()
81+
.and_then(|x| enquote::unescape(x, None).ok())
82+
.map(|x| DefineText::new(x, None));
83+
let define = Define::new(ident.clone(), vec![], text);
84+
defines.insert(ident, Some(define));
85+
}
86+
for plugin in &config.verilog.plugins {
87+
debug!("plugin: {:?}", &plugin);
88+
linter.load(&plugin).unwrap();
89+
}
90+
};
91+
debug!("include_paths: {:?}", include_paths);
92+
debug!("defines: {:?}", defines);
8793

88-
let src_path = if let Ok(x) = path.strip_prefix(root_uri) {
89-
x.to_path_buf()
90-
} else {
91-
PathBuf::from("")
92-
};
94+
let src_path = if let Ok(x) = path.strip_prefix(root_uri) {
95+
x.to_path_buf()
96+
} else {
97+
PathBuf::from("")
98+
};
9399

94-
let mut linter = self.linter.write().unwrap();
95-
if let Some(ref mut linter) = *linter {
96100
// Iterate over lines in the file, applying each textrule to each line
97101
// in turn.
98102
let mut beg: usize = 0;

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub struct ConfigVerilog {
2121
pub include_paths: Vec<PathBuf>,
2222
#[serde(default)]
2323
pub defines: Vec<String>,
24+
#[serde(default)]
25+
pub plugins: Vec<PathBuf>,
2426
}
2527

2628
impl Default for Config {

0 commit comments

Comments
 (0)