@@ -4,10 +4,9 @@ use ruff_text_size::{Ranged, TextRange, TextSize};
44use crate :: core:: file_mgr:: FileMgr ;
55use crate :: core:: odoo:: SyncOdoo ;
66use crate :: core:: symbols:: function_symbol:: Argument ;
7- use crate :: utils:: { compare_semver, PathSanitizer } ;
7+ use crate :: utils:: compare_semver;
88use std:: cmp:: Ordering ;
99use std:: collections:: HashMap ;
10- use std:: path:: PathBuf ;
1110use std:: rc:: Weak ;
1211use std:: { cell:: RefCell , rc:: Rc } ;
1312
@@ -507,12 +506,12 @@ impl FeaturesUtils {
507506 let from_modules = info_pieces. iter ( ) . filter_map ( |info| info. from_module . clone ( ) . map ( |module_rc| module_rc. borrow ( ) . name ( ) . clone ( ) ) ) . unique ( ) . collect :: < Vec < _ > > ( ) ;
508507 // BLOCK 1: (type) **name** -> inferred_type
509508 block += FeaturesUtils :: build_block_1 ( session, id. type_ , & id. name , sym_type_tag, & inferred_types) . as_str ( ) ;
510- // BLOCK 2: useful links
511- block += inferred_types. iter ( ) . map ( |typ| FeaturesUtils :: get_useful_link ( session, & typ. eval_ptr ) ) . collect :: < String > ( ) . as_str ( ) ;
512- // BLOCK 3: documentation
509+ // BLOCK 2: documentation
513510 if let Some ( documentation_block) = FeaturesUtils :: get_documentation_block ( session, & from_modules, & inferred_types) {
514511 block = block + " \n *** \n " + & documentation_block;
515512 }
513+ // BLOCK 3: useful links or directory paths
514+ block += inferred_types. iter ( ) . map ( |typ| FeaturesUtils :: get_location_info ( session, & typ. eval_ptr ) ) . collect :: < String > ( ) . as_str ( ) ;
516515 blocks. push ( block) ;
517516 }
518517 blocks. iter ( ) . join ( " \n *** \n " )
@@ -674,24 +673,41 @@ impl FeaturesUtils {
674673
675674 }
676675
677- /// Finds and returns useful links for an evaluation
678- fn get_useful_link ( _session : & mut SessionInfo , typ : & EvaluationSymbolPtr ) -> String {
676+ /// Finds and returns useful links or directory locations for an evaluation
677+ fn get_location_info ( _session : & mut SessionInfo , typ : & EvaluationSymbolPtr ) -> String {
679678 // Possibly add more links in the future
680679 let Some ( typ) = typ. upgrade_weak ( ) else {
681- return S ! ( "" )
680+ return S ! ( "" ) ;
682681 } ;
683- let paths = & typ. borrow ( ) . paths ( ) ;
684- if paths. len ( ) == 1 { //we won't put a link to a namespace
685- let type_ref = typ. borrow ( ) ;
686- let base_path = match type_ref. typ ( ) {
687- SymType :: PACKAGE ( _) => PathBuf :: from ( paths. first ( ) . unwrap ( ) . clone ( ) ) . join ( format ! ( "__init__.py{}" , type_ref. as_package( ) . i_ext( ) ) ) . sanitize ( ) ,
688- _ => paths. first ( ) . unwrap ( ) . clone ( )
689- } ;
690- let path = FileMgr :: pathname2uri ( & base_path) ;
691- let range = if type_ref. is_file_content ( ) { type_ref. range ( ) . start ( ) . to_u32 ( ) } else { 0 } ;
692- format ! ( " \n *** \n See also: [{}]({}#{}){}" , type_ref. name( ) . as_str( ) , path. as_str( ) , range, " \n " )
693- } else {
694- S ! ( "" )
682+ let symbol = & * typ. borrow ( ) ;
683+ let lb = FeaturesUtils :: get_line_break ( _session) ;
684+ match symbol {
685+ Symbol :: Namespace ( ns) => {
686+ // List namespace directories
687+ let paths = ns. paths ( ) ;
688+ let name = & ns. name ;
689+ match paths. len ( ) {
690+ 0 => S ! ( "" ) ,
691+ 1 => format ! ( " \n *** \n `{name}` namespace directory: `{}`{lb}" , paths[ 0 ] ) ,
692+ _ => {
693+ let path_list = paths. iter ( ) . map ( |p| format ! ( "- `{p}`" ) ) . join ( lb) ;
694+ format ! ( " \n *** \n `{name}` namespace directories:{lb}{path_list}{lb}" )
695+ }
696+ }
697+ }
698+ Symbol :: Package ( _)
699+ | Symbol :: File ( _)
700+ | Symbol :: XmlFileSymbol ( _)
701+ | Symbol :: CsvFileSymbol ( _) => {
702+ // Get useful link
703+ let uri = FileMgr :: pathname2uri ( & symbol. get_symbol_first_path ( ) ) ;
704+ let range = if symbol. is_file_content ( ) { symbol. range ( ) . start ( ) . to_u32 ( ) } else { 0 } ;
705+ format ! ( " \n *** \n See also: [{}]({}#{}){lb}" , symbol. name( ) , uri. as_str( ) , range)
706+ }
707+ Symbol :: Compiled ( c) => {
708+ format ! ( " \n *** \n `{}` is a binary at `{}`{lb}" , c. name, c. path)
709+ }
710+ _ => S ! ( "" ) ,
695711 }
696712 }
697713
0 commit comments