use super::sources::{FileId, Source, SourceType};
use crate::hir::TypeSystem;
use std::sync::Arc;
#[salsa::query_group(InputStorage)]
pub trait InputDatabase {
#[salsa::input]
fn recursion_limit(&self) -> Option<usize>;
#[salsa::input]
fn type_system_hir_input(&self) -> Option<Arc<TypeSystem>>;
#[salsa::input]
fn input(&self, file_id: FileId) -> Source;
fn source_code(&self, file_id: FileId) -> Arc<str>;
fn source_type(&self, file_id: FileId) -> SourceType;
#[salsa::input]
fn source_files(&self) -> Vec<FileId>;
fn type_definition_files(&self) -> Vec<FileId>;
fn executable_definition_files(&self) -> Vec<FileId>;
}
fn source_code(db: &dyn InputDatabase, file_id: FileId) -> Arc<str> {
if let Some(precomputed) = db.type_system_hir_input() {
if let Some(source) = precomputed.inputs.get(&file_id) {
return source.text();
}
}
db.input(file_id).text()
}
fn source_type(db: &dyn InputDatabase, file_id: FileId) -> SourceType {
db.input(file_id).source_type()
}
fn type_definition_files(db: &dyn InputDatabase) -> Vec<FileId> {
db.source_files()
.into_iter()
.filter(|source| {
matches!(
db.source_type(*source),
SourceType::Schema | SourceType::Document
)
})
.collect()
}
fn executable_definition_files(db: &dyn InputDatabase) -> Vec<FileId> {
db.source_files()
.into_iter()
.filter(|source| {
matches!(
db.source_type(*source),
SourceType::Query | SourceType::Document
)
})
.collect()
}