-
Notifications
You must be signed in to change notification settings - Fork 23
List namespace paths on hover + path-related refactors #484
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
Are you sure you want to change the base?
Conversation
| } | ||
|
|
||
| #[test] | ||
| fn test_hover_on_namespace_and_module() { |
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.
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.
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?
| 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.
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()); |
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.
@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.
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
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.
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
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.
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
fda-odoo
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not useful :)
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.
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.
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.
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.
Or we could rename as_single to get_single_string
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.
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.
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?
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.
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. 😬
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.
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)?
9bf1d43 to
774838c
Compare
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.
774838c to
77d6151
Compare
No description provided.