auto_lsp_core/parsers.rs
1/*
2This file is part of auto-lsp.
3Copyright (C) 2025 CLAUZEL Adrien
4
5auto-lsp is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>
17*/
18use crate::ast::AstNode;
19use crate::document::Document;
20use crate::errors::ParseError;
21use parking_lot::RwLock;
22use std::sync::Arc;
23use tree_sitter::{Language, Parser};
24
25pub struct Parsers {
26 /// The underlying parser, protected by [`RwLock`] for safe concurrent access.
27 pub parser: RwLock<Parser>,
28 /// The language configuration for this parser.
29 pub language: Language,
30 /// Function to invoke the AST parser.
31 pub ast_parser: InvokeParserFn,
32}
33
34impl std::fmt::Debug for Parsers {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 f.debug_struct("parsers")
37 .field("language", &self.language)
38 .finish()
39 }
40}
41
42pub type InvokeParserFn =
43 fn(&dyn salsa::Database, &Document) -> Result<Vec<Arc<dyn AstNode>>, ParseError>;