teo_parser/search/search_unit_for_auto_completion.rs
1use crate::ast::argument_list::ArgumentList;
2use crate::availability::Availability;
3use crate::ast::schema::Schema;
4use crate::ast::source::Source;
5use crate::ast::subscript::Subscript;
6use crate::ast::unit::Unit;
7
8pub fn search_unit_for_auto_completion<HAL, HS, HI, OUTPUT>(
9 _schema: &Schema,
10 _source: &Source,
11 _unit: &Unit,
12 _namespace_path: &Vec<&str>,
13 _line_col: (usize, usize),
14 _handle_argument_list: HAL,
15 _handle_subscript: HS,
16 _handle_identifier: HI,
17 default: OUTPUT,
18 _availability: Availability,
19) -> OUTPUT where
20 HAL: Fn(&ArgumentList, &Vec<Vec<&str>>) -> OUTPUT,
21 HS: Fn(&Subscript) -> OUTPUT,
22 HI: Fn(&Vec<&str>, Option<&Vec<usize>>) -> OUTPUT,
23{
24 // let mut current: Option<UnitSearchResult> = None;
25 // for (index, expression) in unit.expressions().enumerate() {
26 // if index == 0 {
27 // current = Some(if let Some(identifier) = expression.kind.as_identifier() {
28 // if expression.span().contains_line_col(line_col) {
29 // return handle_identifier(&vec![], None);
30 // }
31 // if let Some(path) = search_identifier_path_names_with_filter(
32 // schema,
33 // source,
34 // namespace_path,
35 // &vec![identifier.name()],
36 // &top_filter_for_reference_type(ReferenceType::Default),
37 // availability,
38 // ) {
39 // UnitSearchResult::Reference(path)
40 // } else {
41 // UnitSearchResult::Type(Type::Undetermined)
42 // }
43 // } else {
44 // if expression.span().contains_line_col(line_col) {
45 // return default;
46 // }
47 // UnitSearchResult::Type(expression.resolved().r#type().clone())
48 // });
49 // if current.is_some() && current.as_ref().unwrap().is_reference() {
50 // let top = schema.find_top_by_path(current.as_ref().unwrap().as_reference().unwrap()).unwrap();
51 // if top.is_constant() {
52 // current = Some(UnitSearchResult::Type(top.as_constant().unwrap().resolved().expression_resolved.r#type.clone()));
53 // }
54 // }
55 // } else {
56 // let contains = expression.span().contains_line_col(line_col);
57 // if current.as_ref().is_some() {
58 // match current.as_ref().unwrap() {
59 // UnitSearchResult::Type(current_type) => {
60 // if let Some((path, _)) = current_type.as_struct_object() {
61 // match &expression.kind {
62 // ExpressionKind::Identifier(_) => {
63 // if contains {
64 // return handle_identifier(&vec![], Some(path));
65 // }
66 // return default
67 // }
68 // ExpressionKind::Call(call) => {
69 // let struct_declaration = schema.find_top_by_path(path).unwrap().as_struct_declaration().unwrap();
70 // if let Some(function_declaration) = struct_declaration.function_declarations.iter().find(|f| {
71 // f.r#static == false && f.identifier().name() == call.identifier().name()
72 // }) {
73 // if call.identifier().span.contains_line_col(line_col) {
74 // return handle_identifier(&vec![], Some(path));
75 // } else if call.argument_list.span.contains_line_col(line_col) {
76 // return handle_argument_list(&call.argument_list, &struct_declaration.path, Some(call.identifier().name()));
77 // } else {
78 // // going next
79 // current = Some(UnitSearchResult::Type(function_declaration.return_type().resolved().clone()));
80 // }
81 // } else {
82 // return default;
83 // }
84 // }
85 // ExpressionKind::Subscript(subscript) => {
86 // let struct_declaration = schema.find_top_by_path(path).unwrap().as_struct_declaration().unwrap();
87 // if subscript.span.contains_line_col(line_col) {
88 // if subscript.expression().span().contains_line_col(line_col) {
89 // return handle_subscript(&subscript);
90 // } else {
91 // return default;
92 // }
93 // } else {
94 // if let Some(subscript_function) = struct_declaration.function_declarations.iter().find(|f| {
95 // f.r#static == false && f.identifier().name() == "subscript"
96 // }) {
97 // current = Some(UnitSearchResult::Type(subscript_function.return_type().resolved().clone()));
98 // } else {
99 // return default;
100 // }
101 // }
102 // }
103 // _ => unreachable!(),
104 // }
105 // } else {
106 // return default;
107 // }
108 // }
109 // UnitSearchResult::Reference(current_reference) => {
110 // match schema.find_top_by_path(¤t_reference).unwrap() {
111 // Node::StructDeclaration(struct_declaration) => {
112 // match &expression.kind {
113 // ExpressionKind::ArgumentList(argument_list) => {
114 // if let Some(new) = struct_declaration.function_declarations.iter().find(|f| f.r#static && f.identifier().name() == "new") {
115 // if argument_list.span.contains_line_col(line_col) {
116 // return handle_argument_list(argument_list, &struct_declaration.path, Some(new.identifier().name()));
117 // } else {
118 // current = Some(UnitSearchResult::Type(new.return_type().resolved().clone()));
119 // }
120 // } else {
121 // return handle_argument_list(argument_list, &struct_declaration.path, Some(new.identifier().name()));
122 // }
123 // }
124 // ExpressionKind::Call(call) => {
125 // if let Some(function) = struct_declaration.function_declarations.iter().find(|f| f.r#static && f.identifier().name() == call.identifier().name()) {
126 // if call.span.contains_line_col(line_col) {
127 // return handle_identifier(call.identifier().span, struct_declaration.path.as_ref(), Some(function.identifier().name()));
128 // } else if call.argument_list.span.contains_line_col(line_col) {
129 // return handle_argument_list(&call.argument_list, struct_declaration.path.as_ref(), Some(function.identifier().name()));
130 // } else {
131 // return default;
132 // }
133 // } else {
134 // return default;
135 // }
136 // }
137 // ExpressionKind::Subscript(s) => {
138 // return default;
139 // }
140 // ExpressionKind::Identifier(i) => {
141 // return default;
142 // }
143 // _ => unreachable!()
144 // }
145 // },
146 // Node::Config(config) => {
147 // match &expression.kind {
148 // ExpressionKind::Identifier(identifier) => {
149 // if let Some(item) = config.items().find(|i| i.identifier().name() == identifier.name()) {
150 // if identifier.span.contains_line_col(line_col) {
151 // return handle_identifier(identifier.span, config.path.as_ref(), Some(item.identifier().name()));
152 // } else {
153 // current = Some(UnitSearchResult::Type(item.expression.resolved().r#type.clone()));
154 // }
155 // } else {
156 // return default;
157 // }
158 // },
159 // ExpressionKind::ArgumentList(a) => {
160 // return default;
161 // }
162 // ExpressionKind::Call(c) => {
163 // return default;
164 // }
165 // ExpressionKind::Subscript(s) => {
166 // return default;
167 // }
168 // _ => unreachable!()
169 // }
170 // }
171 // Node::Enum(r#enum) => {
172 // match &expression.kind {
173 // ExpressionKind::Identifier(i) => {
174 // if let Some(member) = r#enum.members().find(|m| m.identifier().name() == i.name()) {
175 // if i.span.contains_line_col(line_col) {
176 // return handle_identifier(i.span, r#enum.path.as_ref(), Some(member.identifier().name()));
177 // } else {
178 // return default;
179 // }
180 // } else {
181 // return default;
182 // }
183 // }
184 // ExpressionKind::Call(c) => {
185 // if c.span.contains_line_col(line_col) {
186 // if let Some(member) = r#enum.members().find(|m| m.identifier().name() == c.identifier().name()) {
187 // if c.identifier().span.contains_line_col(line_col) {
188 // return handle_identifier(c.identifier().span, r#enum.path.as_ref(), Some(member.identifier().name()));
189 // } else if c.argument_list.span.contains_line_col(line_col) {
190 // return handle_argument_list(&c.argument_list, r#enum.path.as_ref(), Some(member.identifier().name()));
191 // } else {
192 // return default;
193 // }
194 // } else {
195 // return default;
196 // }
197 // } else {
198 // return default;
199 // }
200 // }
201 // ExpressionKind::ArgumentList(a) => {
202 // return default;
203 // }
204 // ExpressionKind::Subscript(s) => {
205 // return default;
206 // }
207 // _ => unreachable!()
208 // }
209 // }
210 // Node::Model(model) => {
211 // match &expression.kind {
212 // ExpressionKind::Identifier(identifier) => {
213 // if let Some(field) = model.fields().find(|f| f.name() == identifier.name()) {
214 // if identifier.span.contains_line_col(line_col) {
215 // return handle_identifier(identifier.span, model.path.as_ref(), Some(field.name()));
216 // } else {
217 // return default;
218 // }
219 // } else {
220 // return default;
221 // }
222 // },
223 // ExpressionKind::ArgumentList(a) => {
224 // return default;
225 // }
226 // ExpressionKind::Call(c) => {
227 // return default;
228 // }
229 // ExpressionKind::Subscript(s) => {
230 // return default;
231 // }
232 // _ => unreachable!()
233 // }
234 // }
235 // Node::InterfaceDeclaration(interface) => {
236 // match &expression.kind {
237 // ExpressionKind::Identifier(identifier) => {
238 // if let Some(field) = interface.fields().find(|f| f.name() == identifier.name()) {
239 // if identifier.span.contains_line_col(line_col) {
240 // return handle_identifier(identifier.span, interface.path.as_ref(), Some(field.name()));
241 // } else {
242 // return default;
243 // }
244 // } else {
245 // return default;
246 // }
247 // },
248 // ExpressionKind::ArgumentList(a) => {
249 // return default;
250 // }
251 // ExpressionKind::Call(c) => {
252 // return default;
253 // }
254 // ExpressionKind::Subscript(s) => {
255 // return default;
256 // }
257 // _ => unreachable!()
258 // }
259 // }
260 // Node::Namespace(namespace) => {
261 // match &expression.kind {
262 // ExpressionKind::Identifier(identifier) => {
263 // if let Some(top) = namespace.find_top_by_name(identifier.name(), &top_filter_for_reference_type(ReferenceType::Default), availability) {
264 // if identifier.span.contains_line_col(line_col) {
265 // return handle_identifier(identifier.span, top.path(), None);
266 // } else {
267 // return default;
268 // }
269 // } else {
270 // return default;
271 // }
272 // },
273 // ExpressionKind::Call(c) => {
274 // if let Some(top) = namespace.find_top_by_name(c.identifier().name(), &top_filter_for_reference_type(ReferenceType::Default), availability) {
275 // match top {
276 // Node::StructDeclaration(struct_declaration) => {
277 // if let Some(new) = struct_declaration.function_declarations.iter().find(|f| {
278 // f.identifier().name() == "new"
279 // }) {
280 // if c.span.contains_line_col(line_col) {
281 // if c.identifier().span.contains_line_col(line_col) {
282 // return handle_identifier(c.identifier().span, struct_declaration.path.as_ref(), Some("new"));
283 // } else if c.argument_list.span.contains_line_col(line_col) {
284 // return handle_argument_list(&c.argument_list, struct_declaration.path.as_ref(), Some("new"));
285 // } else {
286 // return default;
287 // }
288 // } else {
289 // current = Some(UnitSearchResult::Type(new.return_type().resolved().clone()));
290 // }
291 // } else {
292 // return default;
293 // }
294 // },
295 // _ => return default,
296 // }
297 // } else {
298 // return default;
299 // }
300 // }
301 // ExpressionKind::ArgumentList(a) => {
302 // return default;
303 // }
304 // ExpressionKind::Subscript(s) => {
305 // return default;
306 // }
307 // _ => unreachable!()
308 // }
309 // }
310 // _ => unreachable!()
311 // }
312 // }
313 // }
314 // } else {
315 // return default
316 // }
317 // }
318 // }
319 default
320}