oak_python/builder/
mod.rs1use crate::{ast::PythonRoot, language::PythonLanguage, parser::PythonParser};
2use oak_core::{Builder, BuilderCache, OakDiagnostics, Parser, TextEdit, builder::BuildOutput, source::Source};
3
4#[derive(Clone)]
5pub struct PythonBuilder<'config> {
6 config: &'config PythonLanguage,
7}
8
9impl<'config> PythonBuilder<'config> {
10 pub fn new(config: &'config PythonLanguage) -> Self {
11 Self { config }
12 }
13}
14
15impl<'config> Builder<PythonLanguage> for PythonBuilder<'config> {
16 fn build<'a, S: Source + ?Sized>(&self, source: &S, edits: &[TextEdit], _cache: &'a mut impl BuilderCache<PythonLanguage>) -> BuildOutput<PythonLanguage> {
17 let parser = PythonParser::new(self.config);
18
19 let mut parse_cache = oak_core::parser::session::ParseSession::<PythonLanguage>::default();
20 let parse_result = parser.parse(source, edits, &mut parse_cache);
21
22 match parse_result.result {
23 Ok(_) => {
24 OakDiagnostics { result: Ok(PythonRoot { items: vec![] }), diagnostics: parse_result.diagnostics }
26 }
27 Err(e) => OakDiagnostics { result: Err(e), diagnostics: parse_result.diagnostics },
28 }
29 }
30}