Skip to main content

runec/
ide.rs

1//! Editor queries over the same documents and definitions used for compilation.
2//! Locations and edits use UTF-8 byte ranges; `text::LineIndex` converts UTF-16.
3mod actions;
4mod config;
5mod fields;
6mod highlighting;
7mod hints;
8mod hooks;
9mod index;
10mod queries;
11
12use crate::diagnostics::Applicability;
13use crate::project::SourceId;
14use crate::sources::Scope;
15use crate::types::Type;
16use std::collections::{HashMap, HashSet};
17use std::ops::Range;
18
19#[derive(Clone, Debug, PartialEq, Eq)]
20pub struct Location {
21    pub source: SourceId,
22    pub range: Range<usize>,
23}
24
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
26pub enum SymbolKind {
27    Procedure,
28    ClientScript,
29    Trigger,
30    Parameter,
31    Variable,
32    Constant,
33    GameVariable,
34    Command,
35    Config,
36}
37
38#[derive(Clone, Debug)]
39pub struct Symbol {
40    pub name: String,
41    pub kind: SymbolKind,
42    pub detail: String,
43    pub documentation: String,
44    pub value_type: Option<Type>,
45    pub definition: Option<Location>,
46    pub extent: Option<Location>,
47    pub parameters: Vec<(String, Type)>,
48    pub returns: Vec<Type>,
49    pub(crate) container: Option<(SourceId, usize)>,
50    pub(crate) scope: Option<Scope>,
51    pub(crate) key: String,
52}
53
54#[derive(Clone, Debug)]
55pub struct Completion {
56    pub label: String,
57    pub detail: String,
58    pub kind: SymbolKind,
59    pub replacement: Range<usize>,
60}
61
62#[derive(Clone, Debug)]
63pub struct Hover {
64    pub range: Range<usize>,
65    pub kind: SymbolKind,
66    pub detail: String,
67    pub documentation: String,
68}
69
70#[derive(Clone, Debug)]
71pub struct SignatureHelp {
72    pub label: String,
73    pub parameters: Vec<(String, Type)>,
74    pub active_parameter: usize,
75    pub documentation: String,
76}
77
78#[derive(Clone, Debug, PartialEq, Eq)]
79pub struct TextEdit {
80    pub location: Location,
81    pub replacement: String,
82}
83
84#[derive(Clone, Debug)]
85pub struct CodeAction {
86    pub title: String,
87    pub kind: &'static str,
88    pub edits: Vec<TextEdit>,
89    pub applicability: Applicability,
90}
91
92#[derive(Clone, Debug)]
93pub struct InlayHint {
94    pub offset: usize,
95    pub label: String,
96    pub parameter: bool,
97}
98
99#[derive(Clone, Copy, Debug, PartialEq, Eq)]
100pub enum TokenKind {
101    Keyword,
102    Function,
103    Parameter,
104    Variable,
105    Property,
106    Type,
107    Number,
108    String,
109    Comment,
110    Operator,
111    EnumMember,
112    Namespace,
113    Decorator,
114    Macro,
115}
116
117#[derive(Clone, Debug)]
118pub struct SemanticToken {
119    pub range: Range<usize>,
120    pub kind: TokenKind,
121    pub declaration: bool,
122    pub readonly: bool,
123    pub static_: bool,
124    pub default_library: bool,
125}
126
127impl SemanticToken {
128    fn new(range: Range<usize>, kind: TokenKind) -> Self {
129        Self {
130            range,
131            kind,
132            declaration: false,
133            readonly: false,
134            static_: false,
135            default_library: false,
136        }
137    }
138}
139
140pub(crate) struct Reference {
141    location: Location,
142    symbol: usize,
143    declaration: bool,
144}
145
146pub(crate) struct Index {
147    symbols: Vec<Symbol>,
148    references: Vec<Reference>,
149    compounds: HashSet<String>,
150    hooks: HashMap<SourceId, Vec<hooks::Hook>>,
151    config_types: fields::ConfigTypes,
152    config_problems: HashMap<SourceId, Vec<(usize, String)>>,
153}