add pyo3 as a feature flag for python bindings (#2710)

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* thing

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add feature flag for pyo3 for gregs stuff;

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add more

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2024-06-19 17:32:08 -07:00
committed by GitHub
parent dc226d3270
commit f1ef9d5200
10 changed files with 155 additions and 32 deletions

View File

@ -1,14 +1,7 @@
use std::sync::{Arc, Mutex};
use anyhow::Result;
use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity};
use crate::{
ast::types::Program,
executor::SourceRange,
lint::{walk, Node},
lsp::IntoDiagnostic,
};
use crate::{executor::SourceRange, lint::Node, lsp::IntoDiagnostic};
/// Check the provided AST for any found rule violations.
///
@ -30,6 +23,7 @@ where
/// Specific discovered lint rule Violation of a particular Finding.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "pyo3", pyo3::pyclass)]
pub struct Discovered {
/// Zoo Lint Finding information.
pub finding: Finding,
@ -66,6 +60,7 @@ impl IntoDiagnostic for Discovered {
/// Abstract lint problem type.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "pyo3", pyo3::pyclass)]
pub struct Finding {
/// Unique identifier for this particular issue.
pub code: &'static str,
@ -114,21 +109,6 @@ pub(crate) use finding;
#[cfg(test)]
pub(crate) use test::{assert_finding, assert_no_finding, test_finding, test_no_finding};
/// Check the provided Program for any Findings.
pub fn lint<'a, RuleT>(prog: &'a Program, rule: RuleT) -> Result<Vec<Discovered>>
where
RuleT: Rule<'a>,
{
let v = Arc::new(Mutex::new(vec![]));
walk(prog, &|node: Node<'a>| {
let mut findings = v.lock().map_err(|_| anyhow::anyhow!("mutex"))?;
findings.append(&mut rule.check(node)?);
Ok(true)
})?;
let x = v.lock().unwrap();
Ok(x.clone())
}
#[cfg(test)]
mod test {
@ -137,7 +117,7 @@ mod test {
let tokens = $crate::token::lexer($kcl).unwrap();
let parser = $crate::parser::Parser::new(tokens);
let prog = parser.ast().unwrap();
for discovered_finding in $crate::lint::lint(&prog, $check).unwrap() {
for discovered_finding in prog.lint($check).unwrap() {
if discovered_finding.finding == $finding {
assert!(false, "Finding {:?} was emitted", $finding.code);
}
@ -151,7 +131,7 @@ mod test {
let parser = $crate::parser::Parser::new(tokens);
let prog = parser.ast().unwrap();
for discovered_finding in $crate::lint::lint(&prog, $check).unwrap() {
for discovered_finding in prog.lint($check).unwrap() {
if discovered_finding.finding == $finding {
return;
}