Skip to content

Commit b7ffe44

Browse files
committed
[IMP] features: improve line return dependning on client capabilities
On Pycharm ` \n` are not supported in documentation, but `<br/>` is. On VsCode `<br/>` is escaped, so we must keep ` \n`
1 parent fdce10e commit b7ffe44

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

server/src/features/features_utils.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl FeaturesUtils {
389389
for main_class_rc in main_classes.iter() {
390390
let main_class = main_class_rc.borrow();
391391
if let Some(main_class_module) = main_class.find_module() {
392-
block += format!("Model in {}: {} \n", main_class_module.borrow().name(), main_class.name()).as_str();
392+
block += format!("Model in {}: {}", main_class_module.borrow().name(), main_class.name()).as_str();
393393
if main_class.doc_string().is_some() {
394394
block = block + " \n*** \n" + main_class.doc_string().as_ref().unwrap();
395395
}
@@ -413,8 +413,8 @@ impl FeaturesUtils {
413413
})
414414
.map(|(mod_name, needed_module)| {
415415
match needed_module {
416-
Some(module) => format!("inherited in {} (require {}) \n", mod_name, module),
417-
None => format!("inherited in {} \n", mod_name)
416+
Some(module) => format!("inherited in {} (require {}){}", mod_name, module, FeaturesUtils::get_line_break(session)),
417+
None => format!("inherited in {}{}", mod_name, FeaturesUtils::get_line_break(session))
418418
}
419419
}).collect::<String>();
420420
}
@@ -454,11 +454,11 @@ impl FeaturesUtils {
454454
let inferred_types = info_pieces.iter().flat_map(|info| info.inferred_types.clone()).collect::<Vec<_>>();
455455
let from_modules = info_pieces.iter().filter_map(|info| info.from_module.clone().map(|module_rc| module_rc.borrow().name().clone())).unique().collect::<Vec<_>>();
456456
// BLOCK 1: (type) **name** -> inferred_type
457-
block += FeaturesUtils::build_block_1(id.type_, &id.name, sym_type_tag, &inferred_types).as_str();
457+
block += FeaturesUtils::build_block_1(session, id.type_, &id.name, sym_type_tag, &inferred_types).as_str();
458458
// BLOCK 2: useful links
459-
block += inferred_types.iter().map(|typ| FeaturesUtils::get_useful_link(&typ.eval_ptr)).collect::<String>().as_str();
459+
block += inferred_types.iter().map(|typ| FeaturesUtils::get_useful_link(session, &typ.eval_ptr)).collect::<String>().as_str();
460460
// BLOCK 3: documentation
461-
if let Some(documentation_block) = FeaturesUtils::get_documentation_block(&from_modules, &inferred_types){
461+
if let Some(documentation_block) = FeaturesUtils::get_documentation_block(session, &from_modules, &inferred_types){
462462
block = block + " \n*** \n" + &documentation_block;
463463
}
464464
blocks.push(block);
@@ -564,9 +564,9 @@ impl FeaturesUtils {
564564
parameters: (type_sym) symbol: inferred_types
565565
For example: "(parameter) self: type[Self@ResPartner]"
566566
*/
567-
fn build_block_1(symbol_type: SymType, symbol_name: &OYarn, type_sym: Vec<String>, inferred_types: &Vec<InferredType>) -> String {
567+
fn build_block_1(session: &mut SessionInfo, symbol_type: SymType, symbol_name: &OYarn, type_sym: Vec<String>, inferred_types: &Vec<InferredType>) -> String {
568568
//python code balise
569-
let mut value = S!("```python \n");
569+
let mut value = S!(format!("```python{}", FeaturesUtils::get_line_break(session)));
570570
//type name
571571
value += &format!("({}) ", type_sym.iter().join(" | "));
572572
let mut single_func_eval = false;
@@ -597,7 +597,7 @@ impl FeaturesUtils {
597597
},
598598
TypeInfo::VALUE(value) => value.clone(),
599599
}).unique().collect::<Vec<_>>();
600-
value += &format!("{} \n```", FeaturesUtils::represent_return_types(return_types_string));
600+
value += &format!("{}{}```", FeaturesUtils::represent_return_types(return_types_string), FeaturesUtils::get_line_break(session));
601601
//end block
602602
value
603603
}
@@ -622,7 +622,7 @@ impl FeaturesUtils {
622622
}
623623

624624
/// Finds and returns useful links for an evaluation
625-
fn get_useful_link(typ: &EvaluationSymbolPtr) -> String {
625+
fn get_useful_link(session: &mut SessionInfo, typ: &EvaluationSymbolPtr) -> String {
626626
// Possibly add more links in the future
627627
let Some(typ) = typ.upgrade_weak() else {
628628
return S!("")
@@ -636,14 +636,14 @@ impl FeaturesUtils {
636636
};
637637
let path = FileMgr::pathname2uri(&base_path);
638638
let range = if type_ref.is_file_content() { type_ref.range().start().to_u32() } else { 0 };
639-
format!(" \n*** \nSee also: [{}]({}#{}) \n", type_ref.name().as_str(), path.as_str(), range)
639+
format!(" \n*** \nSee also: [{}]({}#{}){}", type_ref.name().as_str(), path.as_str(), range, FeaturesUtils::get_line_break(session))
640640
} else {
641641
S!("")
642642
}
643643
}
644644

645645
/// Documentation block that includes the source module(s) and docstrings if found
646-
fn get_documentation_block(from_modules: &Vec<OYarn>, type_refs: &Vec<InferredType>) -> Option<String> {
646+
fn get_documentation_block(session: &mut SessionInfo, from_modules: &Vec<OYarn>, type_refs: &Vec<InferredType>) -> Option<String> {
647647
let mut documentation_block = None;
648648
if !from_modules.is_empty(){
649649
documentation_block = Some(
@@ -665,14 +665,22 @@ impl FeaturesUtils {
665665
format!("{}{}", nbsp_replacement, &line[leading_spaces..])
666666
})
667667
.collect::<Vec<String>>()
668-
.join(" \n");
668+
.join(FeaturesUtils::get_line_break(session));
669669
documentation_block = match documentation_block {
670-
Some(from_module_str) => Some(from_module_str + " \n" + &ds),
670+
Some(from_module_str) => Some(from_module_str + "<br/>" + &ds),
671671
None => Some(ds)
672672
};
673673
}
674674
}
675675
}
676676
documentation_block
677677
}
678+
679+
pub fn get_line_break(session: &mut SessionInfo<'_>) -> &'static str {
680+
if session.sync_odoo.capabilities.general.is_none() ||
681+
session.sync_odoo.capabilities.general.as_ref().unwrap().markdown.is_none() {
682+
return "<br/>"
683+
}
684+
" \n"
685+
}
678686
}

0 commit comments

Comments
 (0)