|
1 | 1 | use emmylua_parser::{ |
2 | | - BinaryOperator, LuaAst, LuaAstNode, LuaAstToken, LuaBlock, LuaDocDescriptionOwner, LuaDocTagAs, |
3 | | - LuaDocTagCast, LuaDocTagModule, LuaDocTagOther, LuaDocTagOverload, LuaDocTagParam, |
4 | | - LuaDocTagReturn, LuaDocTagReturnCast, LuaDocTagSee, LuaDocTagType, LuaExpr, LuaLocalName, |
5 | | - LuaTokenKind, LuaVarExpr, |
| 2 | + LuaAst, LuaAstNode, LuaAstToken, LuaBlock, LuaDocDescriptionOwner, LuaDocTagAs, LuaDocTagCast, |
| 3 | + LuaDocTagModule, LuaDocTagOther, LuaDocTagOverload, LuaDocTagParam, LuaDocTagReturn, |
| 4 | + LuaDocTagReturnCast, LuaDocTagSee, LuaDocTagType, LuaExpr, LuaLocalName, LuaTokenKind, |
| 5 | + LuaVarExpr, |
6 | 6 | }; |
7 | 7 |
|
8 | 8 | use crate::{ |
@@ -186,73 +186,24 @@ pub fn analyze_return(analyzer: &mut DocAnalyzer, tag: LuaDocTagReturn) -> Optio |
186 | 186 | Some(()) |
187 | 187 | } |
188 | 188 |
|
189 | | -enum CastAction { |
190 | | - Add, |
191 | | - Remove, |
192 | | - Force, |
193 | | -} |
194 | | - |
195 | | -#[allow(unused)] |
196 | 189 | pub fn analyze_return_cast(analyzer: &mut DocAnalyzer, tag: LuaDocTagReturnCast) -> Option<()> { |
197 | 190 | if let Some(LuaSemanticDeclId::Signature(signature_id)) = get_owner_id(analyzer) { |
198 | 191 | let name_token = tag.get_name_token()?; |
199 | 192 | let name = name_token.get_name_text(); |
200 | 193 | let cast_op_type = tag.get_op_type()?; |
201 | | - let action = match cast_op_type.get_op() { |
202 | | - Some(op) => { |
203 | | - if op.get_op() == BinaryOperator::OpAdd { |
204 | | - CastAction::Add |
205 | | - } else { |
206 | | - CastAction::Remove |
207 | | - } |
208 | | - } |
209 | | - None => CastAction::Force, |
| 194 | + if let Some(node_type) = cast_op_type.get_type() { |
| 195 | + let typ = infer_type(analyzer, node_type.clone()); |
| 196 | + let infiled_syntax_id = InFiled::new(analyzer.file_id, node_type.get_syntax_id()); |
| 197 | + let type_owner = LuaTypeOwner::SyntaxId(infiled_syntax_id); |
| 198 | + bind_type(analyzer.db, type_owner, LuaTypeCache::DocType(typ)); |
210 | 199 | }; |
211 | 200 |
|
212 | | - if cast_op_type.is_nullable() { |
213 | | - // match action { |
214 | | - // CastAction::Add => { |
215 | | - // analyzer.db.get_flow_index_mut().add_call_cast( |
216 | | - // signature_id, |
217 | | - // name, |
218 | | - // TypeAssertion::Add(LuaType::Nil), |
219 | | - // ); |
220 | | - // } |
221 | | - // CastAction::Remove => { |
222 | | - // analyzer.db.get_flow_index_mut().add_call_cast( |
223 | | - // signature_id, |
224 | | - // name, |
225 | | - // TypeAssertion::Remove(LuaType::Nil), |
226 | | - // ); |
227 | | - // } |
228 | | - // _ => {} |
229 | | - // } |
230 | | - // } else if let Some(doc_type) = cast_op_type.get_type() { |
231 | | - // let typ = infer_type(analyzer, doc_type.clone()); |
232 | | - // match action { |
233 | | - // CastAction::Add => { |
234 | | - // analyzer.db.get_flow_index_mut().add_call_cast( |
235 | | - // signature_id, |
236 | | - // name, |
237 | | - // TypeAssertion::Add(typ), |
238 | | - // ); |
239 | | - // } |
240 | | - // CastAction::Remove => { |
241 | | - // analyzer.db.get_flow_index_mut().add_call_cast( |
242 | | - // signature_id, |
243 | | - // name, |
244 | | - // TypeAssertion::Remove(typ), |
245 | | - // ); |
246 | | - // } |
247 | | - // CastAction::Force => { |
248 | | - // analyzer.db.get_flow_index_mut().add_call_cast( |
249 | | - // signature_id, |
250 | | - // name, |
251 | | - // TypeAssertion::Force(typ), |
252 | | - // ); |
253 | | - // } |
254 | | - // } |
255 | | - } |
| 201 | + analyzer.db.get_flow_index_mut().add_signature_cast( |
| 202 | + analyzer.file_id, |
| 203 | + signature_id, |
| 204 | + name.to_string(), |
| 205 | + cast_op_type.to_ptr(), |
| 206 | + ); |
256 | 207 | } |
257 | 208 |
|
258 | 209 | Some(()) |
|
0 commit comments