List namespace paths on hover + path-related refactors#484
List namespace paths on hover + path-related refactors#484cammarosano wants to merge 21 commits intoalphafrom
Conversation
| } | ||
|
|
||
| #[test] | ||
| fn test_hover_on_namespace_and_module() { |
There was a problem hiding this comment.
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.
ce4bf39 to
9bf1d43
Compare
server/src/core/import_resolver.rs
Outdated
|
|
||
| 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(); |
There was a problem hiding this comment.
or .as_multiple, if we're sure that odoo_addons is a namespace?
| let SymbolPath::Multiple(addons_paths) = addons_symbol.borrow().path() else { | ||
| panic!("Odoo addons symbol paths should be a namespace"); | ||
| }; |
There was a problem hiding this comment.
@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()); |
There was a problem hiding this comment.
@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?
server/src/core/import_resolver.rs
Outdated
| // 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(); |
There was a problem hiding this comment.
This simply keeps the old behavior. But it feels dodgy. What do think?
See also: the previous comment
server/src/core/import_resolver.rs
Outdated
| }; | ||
| 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(); |
There was a problem hiding this comment.
Same as above (preserves the original behavior). Dodgy?
See also: manual_import
server/src/core/import_resolver.rs
Outdated
| if source_file_symbol.borrow().path().as_vec().len() > 1 { | ||
| panic!("Importing from a multi-path namespace symbol is not supported in manual_import"); | ||
| } |
There was a problem hiding this comment.
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
fda-odoo
left a comment
There was a problem hiding this comment.
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!(""); |
There was a problem hiding this comment.
oops, sorry, automatic formatting (rust-fmt) 😬
server/src/core/symbols/symbol.rs
Outdated
| } | ||
|
|
||
| impl SymbolPath { | ||
| pub fn as_single(self) -> String { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Or we could rename as_single to get_single_string
There was a problem hiding this comment.
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).
server/src/core/symbols/symbol.rs
Outdated
| matches!(self, Self::Single(_)) | ||
| } | ||
|
|
||
| pub fn as_multiple(self) -> Vec<String> { |
There was a problem hiding this comment.
Same, maybe get_multiple_vector?
server/src/core/symbols/symbol.rs
Outdated
| matches!(self, Self::Multiple(_)) | ||
| } | ||
|
|
||
| pub fn as_vec(self) -> Vec<String> { |
There was a problem hiding this comment.
This enables us to use the result of .path() just like the old paths() - which is probably a bad thing. 😬
server/src/core/symbols/symbol.rs
Outdated
| pub fn as_single(self) -> String { | ||
| match self { | ||
| Self::Single(s) => s, | ||
| _ => panic!("Not a Single"), | ||
| } | ||
| } |
There was a problem hiding this comment.
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)?
774838c to
77d6151
Compare
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]: 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
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.
77d6151 to
6a4db3d
Compare
No description provided.