1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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()
}