Skip to content

Conversation

@MihaiStreames
Copy link

Summary

  • Implements same-file Go To References for Python files
  • Adds scope-aware symbol validation to handle variable shadowing
  • Includes tests for classes, variables, imports, and self parameter

Closes #466 (partially - Phase 1 only)

Future work

See TODOs in server/src/features/references.rs:

  • Cross-file references within module
  • Workspace-wide references
  • Odoo-specific: XML field refs, string-based model refs

@fda-odoo fda-odoo self-requested a review January 18, 2026 15:06
@fda-odoo fda-odoo added the enhancement New feature or request label Jan 18, 2026
Copy link
Collaborator

@fda-odoo fda-odoo left a 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() {
Copy link
Collaborator

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];
Copy link
Collaborator

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 a

the 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);
Copy link
Collaborator

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!

mmahrouss and others added 17 commits January 27, 2026 11:47
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
@fda-odoo fda-odoo changed the base branch from release to alpha-references-fda January 28, 2026 10:08
@fda-odoo
Copy link
Collaborator

@MihaiStreames Hello!
I don't know if you tried to work on the Part 2 already or not, but this feature was planned for the next version 1.3, so if I'll take the development of it from now on. If you have already some work done, do not hesitate to share it, it would be a pleasure to discuss on it.
I'll start from your commit to include it in the final feature !
Thank you again for your input on this!

@fda-odoo fda-odoo added this to the 1.3.0 milestone Jan 28, 2026
@fda-odoo fda-odoo self-assigned this Jan 28, 2026
@fda-odoo
Copy link
Collaborator

New Pull request: #531

@MihaiStreames
Copy link
Author

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:

  1. The evaluations.is_empty() check was too aggressive, you're right it would block classes/functions without evaluations
  2. Good catch on evaluations[0], I see now that gives you the evaluated value rather than the symbol itself. I was treating it like the Definition feature does but didn't fully understand the evaluation semantics

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 👍

@fda-odoo fda-odoo force-pushed the alpha-references-fda branch 2 times, most recently from a776bf4 to b0ea6b5 Compare February 10, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Field/variable/function references not working

4 participants