Skip to main content

oak_protobuf/builder/
mod.rs

1use crate::{ast::ProtobufRoot, language::ProtobufLanguage, parser::ProtobufParser};
2
3use oak_core::{
4    OakDiagnostics,
5    builder::{BuildOutput, Builder, BuilderCache},
6    parser::Parser,
7    source::{Source, TextEdit},
8};
9
10pub struct ProtobufBuilder<'config> {
11    config: &'config ProtobufLanguage,
12}
13
14impl<'config> ProtobufBuilder<'config> {
15    pub fn new(config: &'config ProtobufLanguage) -> Self {
16        Self { config }
17    }
18}
19
20impl<'config> Builder<ProtobufLanguage> for ProtobufBuilder<'config> {
21    fn build<'a, S: Source + ?Sized>(&self, source: &S, edits: &[TextEdit], _cache: &'a mut impl BuilderCache<ProtobufLanguage>) -> BuildOutput<ProtobufLanguage> {
22        let parser = ProtobufParser::new(self.config);
23        let mut cache = oak_core::parser::session::ParseSession::<ProtobufLanguage>::default();
24        let parse_result = parser.parse(source, edits, &mut cache);
25
26        match parse_result.result {
27            Ok(_) => {
28                // Placeholder for actual AST building
29                OakDiagnostics { result: Ok(ProtobufRoot {}), diagnostics: parse_result.diagnostics }
30            }
31            Err(e) => OakDiagnostics { result: Err(e), diagnostics: parse_result.diagnostics },
32        }
33    }
34}