-
Notifications
You must be signed in to change notification settings - Fork 27
[IMP] Implement Phase 1 of Go To References (#466) #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: alpha-references-fda
Are you sure you want to change the base?
[IMP] Implement Phase 1 of Go To References (#466) #519
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your pull request, it's a pleasure to see people suggesting new features or functionnalities!
I checked rapidly what you did as this is a "part 1" PR, to be sure you are on the right track!
And indeed it seems really good. I put some comments about things I'm not sure about, but the execution is efficient!
I guess moving to the "part 2" and searching in other files will be more difficult, if you don't want to browse all files. The idea that comes in my mind would be to only execute your algorithm in files that are importing the current file. Because if they do, they maybe use your symbol.
By chance, each file already knows who is importing them, by the "dependents" variable. You'll see that this field is sorting files in function of the depending step:
ARCH, ARCH_EVAL or VALIDATION.
I think (but I can miss something here) that you should only take files in the ARCH (but it would be easy to change if I forget something)
If you have any question, I'll stay available !
|
|
||
| let (analyse_ast_result, _range, _call_expr) = AstUtils::get_symbols(session, file_symbol, file_info, offset as u32); | ||
|
|
||
| if analyse_ast_result.evaluations.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems wrong, but I don't know what you are trying to prevent.
This 'if' will prevent any variable without evaluation, classes or function to get the 'reference' feature working.
| return None; | ||
| } | ||
|
|
||
| let eval = &analyse_ast_result.evaluations[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a misunderstanding on the meaning of "evaluations".
An evaluation is the different values a variable/function can take (inferred with code or signature).
For example:
a = 5
def test():
return athe variable "a" will have an evaluation to the value "5" (of type int)
and the function "test" will have an evaluation to "a" (that has the previous evaluation to "5")
Taking the evaluation[0] here would mean that you are trying to find all references to "5" if you do it on "a".
| // infer name | ||
| let match_offset = match_range.start().to_u32(); | ||
| let scope = Symbol::get_scope_symbol(file_symbol.clone(), match_offset, false); | ||
| AstUtils::build_scope(session, &scope); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice thing to do here!
CachedModel is not required to define Odoo models, so we should not fail to detect models if CachedModel is not found in the Odoo source code. Treat `Model` and `TransientModel` similarly. only exit if `BaseModel` does not exist.
While validating search domain, for relational fields, i.e. "m2ofield.normalfield", we should check all the symbols m2ofield on the model, not just one, so we set true on get member symbol
We are trying to do that by checking _register = False. The check was failing because we handled only one evaluation. However, in latest versions we also have a type hint, which is its own evaluation. For that, we implement here a smarter search that only looks are evaluations with values. In that case, we should be more generic in catching cases. Consider using this as the check, instead of checking symbol trees
Check if class model is in a module, otherwise do not mark it as a model This is to avoid crashing later due to the class not being in a model. The crash to avoid is in `core.model.Model.get_symbols`
The base model's search method should have an evaluation of EvaluationSymbolPtr::SELF. This used to be the case, but it got lost in a refactor ([1]). [1]: odoo@ca26c3e
Before we were checking if inverse_name arg points to a M2O field, but it can also be a Many2oneReference Fixed false positives for OLS03022
__init_subclass__ and __class_getitem__ have a special behavior where they are implicitly classmethods without the decorator This is added here to avoid, for example, wrong diagnostics
Fix arg index to account for is on instance if it is true
|
@MihaiStreames Hello! |
|
New Pull request: #531 |
|
Hey @fda-odoo! Sorry for the late reply, was on vacation and then swamped with exams. Thanks for the review and for taking this forward! Your comments make total sense:
Glad you're building on this for 1.3.0! I don't have any Part 2 work done yet. Happy to help test or review if useful 👍 |
a776bf4 to
b0ea6b5
Compare
Summary
Closes #466 (partially - Phase 1 only)
Future work
See TODOs in
server/src/features/references.rs: