rue_compiler/
syntax_map.rs

1use std::collections::HashSet;
2
3use rowan::TextRange;
4use rue_hir::{ScopeId, SymbolId};
5use rue_types::TypeId;
6
7#[derive(Debug, Default, Clone)]
8pub struct SyntaxMap {
9    items: Vec<SyntaxItem>,
10}
11
12impl SyntaxMap {
13    pub fn new() -> Self {
14        Self::default()
15    }
16
17    pub fn add_item(&mut self, item: SyntaxItem) {
18        self.items.push(item);
19    }
20
21    pub fn items(&self) -> impl Iterator<Item = &SyntaxItem> {
22        self.items.iter()
23    }
24}
25
26#[derive(Debug, Clone)]
27pub struct SyntaxItem {
28    pub kind: SyntaxItemKind,
29    pub span: TextRange,
30}
31
32impl SyntaxItem {
33    pub fn new(kind: SyntaxItemKind, span: TextRange) -> Self {
34        Self { kind, span }
35    }
36}
37
38#[derive(Debug, Clone)]
39pub enum SyntaxItemKind {
40    SymbolDeclaration(SymbolId),
41    SymbolReference(SymbolId),
42    TypeDeclaration(TypeId),
43    TypeReference(TypeId),
44    FieldDeclaration(SyntaxField),
45    FieldReference(SyntaxField),
46    FieldInitializer(SyntaxField),
47    Scope(ScopeId),
48    CompletionContext(CompletionContext),
49}
50
51#[derive(Debug, Clone)]
52pub struct SyntaxField {
53    pub name: String,
54    pub container: TypeId,
55    pub ty: TypeId,
56}
57
58#[derive(Debug, Clone)]
59pub enum CompletionContext {
60    Document,
61    Item,
62    Statement,
63    Type,
64    Expression,
65    StructFields {
66        ty: TypeId,
67        specified_fields: Option<HashSet<String>>,
68    },
69}