Skip to content

Conversation

@cammarosano
Copy link
Collaborator

No description provided.

@cammarosano cammarosano self-assigned this Nov 21, 2025
@fda-odoo fda-odoo self-requested a review November 21, 2025 17:13
@fda-odoo fda-odoo added the enhancement New feature or request label Nov 21, 2025
@fda-odoo fda-odoo added this to the 1.1.1 milestone Nov 21, 2025
}

#[test]
fn test_hover_on_namespace_and_module() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I placed this test here is the similarities with the test above (test_hover_on_model_field_and_method).
But should we have a test file per feature, both tests would end up in a test_hover file.

@cammarosano cammarosano force-pushed the alpha-list_namespace_dirs-rcdl branch from ce4bf39 to 9bf1d43 Compare November 21, 2025 17:28

pub fn find_module(session: &mut SessionInfo, odoo_addons: Rc<RefCell<Symbol>>, name: &OYarn) -> Option<Rc<RefCell<Symbol>>> {
let paths = (*odoo_addons).borrow().paths().clone();
let paths = (*odoo_addons).borrow().path().as_vec();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or .as_multiple, if we're sure that odoo_addons is a namespace?

Comment on lines +472 to +478
let SymbolPath::Multiple(addons_paths) = addons_symbol.borrow().path() else {
panic!("Odoo addons symbol paths should be a namespace");
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fda-odoo we wrote this together.
But since then SymbolPath::as_multiple has been introduced.
Shall I replace this by simply let addon_paths = addons_symbol.borrow().path().as_multiple()?

pub fn add_to_rebuild_arch(&mut self, symbol: Rc<RefCell<Symbol>>) {
if DEBUG_THREADS {
trace!("ADDED TO ARCH - {}", symbol.borrow().paths().first().unwrap_or(&symbol.borrow().name().to_string()));
trace!("ADDED TO ARCH - {} - {:?}", symbol.borrow().name(), symbol.borrow().path());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fda-odoo I had shown you a Symbol::debug_paths() just for this cases.
But I decided to drop it , and use this instead (leveraging the derived debug trait on SymbolPath and always displaying the symbol's name anyway). What do you think?

Comment on lines 88 to 89
// source_file_symbol is either a file or a namespace with a single path
let source_path = source_file_symbol.borrow().path().as_vec()[0].clone();
Copy link
Collaborator Author

@cammarosano cammarosano Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This simply keeps the old behavior. But it feels dodgy. What do think?
See also: the previous comment

};
let source_path = source_file_symbol.borrow().paths()[0].clone();
// source_file_symbol is either a file or a namespace with a single path
let source_path = source_file_symbol.borrow().path().as_vec()[0].clone();
Copy link
Collaborator Author

@cammarosano cammarosano Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above (preserves the original behavior). Dodgy?
See also: manual_import

Comment on lines 60 to 62
if source_file_symbol.borrow().path().as_vec().len() > 1 {
panic!("Importing from a multi-path namespace symbol is not supported in manual_import");
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a reminder: this makes it possible that source_file_symbol is a namespace symbol (thus, with Multiple paths) in resolve_from_stmt and resolve_import_stmt

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.

First part review, I didn't review the usages already, only the first 4 commits and the struct SymbolPath.
I'll continue newt week

// Possibly add more links in the future
let Some(typ) = typ.upgrade_weak() else {
return S!("")
return S!("");
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 not useful :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, sorry, automatic formatting (rust-fmt) 😬

}

impl SymbolPath {
pub fn as_single(self) -> String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not really intuitive that "as_single" returns a String, and not a Single struct.
If we want a String, maybe

pub fn as_string(self) {
    self.as_single().map(|s| s.to_owned())
}

would be nice to add? or a match in as_string is ok too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could rename as_single to get_single_string

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to what we discussed live, iirc you suggested to rename it to "as_single_string", and @mmahrouss suggested "to_single_string", because "as_" suggests returning a reference.
So the last push has "to_single_string" the as name for this method.
I'm fine with both, but I'd probably name it unwrap_single, as it closely relates to Options and Results's unwrap, in which you unwrap the Some/Ok value or panic. In our case, because we have more than one alternative to None (Single and Multiple), we'd have to be specific about what we're unwrapping (unwrap_single or unwrap_multiple).

matches!(self, Self::Single(_))
}

pub fn as_multiple(self) -> Vec<String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, maybe get_multiple_vector?

matches!(self, Self::Multiple(_))
}

pub fn as_vec(self) -> Vec<String> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables us to use the result of .path() just like the old paths() - which is probably a bad thing. 😬

Comment on lines 3182 to 3187
pub fn as_single(self) -> String {
match self {
Self::Single(s) => s,
_ => panic!("Not a Single"),
}
}
Copy link
Collaborator Author

@cammarosano cammarosano Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This consumes self and returns the String. Which is usually what we want when chaining with .path() (right?).
But then this clashes with Rust's convention of returning references for methods called as_*.
Maybe this should be called to_single or unwrap_single or something like this?
I don't particularly like those names, but it feels closely related to what Option::unwrap does.
Alternatively, should this be returning a &String (in which case Symbol::paths should probably also return &String)?

@cammarosano cammarosano force-pushed the alpha-list_namespace_dirs-rcdl branch from 9bf1d43 to 774838c Compare November 25, 2025 12:34
Instead of displaying the "See also" link, we now list the namespace
directories when hovering over a namespace symbol.

We also make sure that the documentation section appears before the
useful links/directories list section.
The `paths` field in `RootSymbol` has no purpose and is always an empty
vector.
Among all symbol variants, adding a path is only relevant for
`NamespaceSymbol`. Therefore this commits moved the `add_path` method
from the generic `Symbol` enum to the specific `NamespaceSymbol` struct.
Package symbols only have a single path.

Before this commit, the `PackageSymbol::paths` method always returned a
single-element Vec<String>.

This commit renames it to `path` (singular) and  makes it return the
single path instead.
This commit replaces the Vec<String> return type in Symbol::paths() (now
renamed to path) with a new SymbolPath enum that explicitly represents
three cases: Single path, Multiple paths, or None.

The purpose of this change is to force the caller handle the different
cases explicitly, rather than doing [0] on the vector previously
returned by paths().

This commit also renames get_symbol_first_path() to get_file_path() for
clarity, as it only applies to file types (File, Package, XMLFile and
CSVFile) and specifically returns the actual file path including
__init__.py for packages.
@cammarosano cammarosano force-pushed the alpha-list_namespace_dirs-rcdl branch from 774838c to 77d6151 Compare November 25, 2025 12:46
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.

2 participants