rue_compiler/
syntax_map.rs

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