@@ -635,23 +635,26 @@ def generate_source_page(ctx, q, project, version, path):
635
635
# type: type of the symbol
636
636
# path: path of the file that contains the symbol
637
637
# line: list of LineWithURL
638
- SymbolEntry = namedtuple ('SymbolEntry' , 'type, path, lines' )
638
+ # peeks: map of code line previews for this path
639
+ SymbolEntry = namedtuple ('SymbolEntry' , 'type, path, lines, peeks' )
639
640
640
641
# Converts SymbolInstance into SymbolEntry
641
642
# path of SymbolInstance will be appended to base_url
642
- def symbol_instance_to_entry (base_url , symbol ):
643
+ def symbol_instance_to_entry (base_url , symbol , peeks ):
643
644
# TODO this should be a responsibility of Query
644
645
if type (symbol .line ) is str :
645
646
line_numbers = symbol .line .split (',' )
646
647
else :
647
648
line_numbers = [symbol .line ]
648
649
649
650
lines = [
650
- LineWithURL (l , f'{ base_url } /{ symbol .path } #L{ l } ' )
651
+ LineWithURL (int ( l ) , f'{ base_url } /{ symbol .path } #L{ l } ' )
651
652
for l in line_numbers
652
653
]
653
654
654
- return SymbolEntry (symbol .type , symbol .path , lines )
655
+ current_peeks = peeks .get (symbol .path , {})
656
+
657
+ return SymbolEntry (symbol .type , symbol .path , lines , current_peeks )
655
658
656
659
# Generates response (status code and optionally HTML) of the `ident` route
657
660
# ctx: RequestContext
@@ -662,15 +665,16 @@ def generate_ident_page(ctx, q, project, version, family, ident):
662
665
663
666
source_base_url = get_source_base_url (project , version )
664
667
665
- symbol_definitions , symbol_references , symbol_doccomments = q .query ('ident' , version , ident , family )
668
+ symbol_definitions , symbol_references , symbol_doccomments , peeks = q .query ('ident' , version , ident , family )
666
669
667
670
symbol_sections = []
671
+ empty_peeks = {}
668
672
669
673
if len (symbol_definitions ) or len (symbol_references ):
670
674
if len (symbol_doccomments ):
671
675
symbol_sections .append ({
672
676
'title' : 'Documented' ,
673
- 'symbols' : {'_unknown' : [symbol_instance_to_entry (source_base_url , sym ) for sym in symbol_doccomments ]},
677
+ 'symbols' : {'_unknown' : [symbol_instance_to_entry (source_base_url , sym , empty_peeks ) for sym in symbol_doccomments ]},
674
678
})
675
679
676
680
if len (symbol_definitions ):
@@ -679,9 +683,9 @@ def generate_ident_page(ctx, q, project, version, family, ident):
679
683
# TODO this should be a responsibility of Query
680
684
for sym in symbol_definitions :
681
685
if sym .type not in defs_by_type :
682
- defs_by_type [sym .type ] = [symbol_instance_to_entry (source_base_url , sym )]
686
+ defs_by_type [sym .type ] = [symbol_instance_to_entry (source_base_url , sym , peeks )]
683
687
else :
684
- defs_by_type [sym .type ].append (symbol_instance_to_entry (source_base_url , sym ))
688
+ defs_by_type [sym .type ].append (symbol_instance_to_entry (source_base_url , sym , peeks ))
685
689
686
690
symbol_sections .append ({
687
691
'title' : 'Defined' ,
@@ -695,7 +699,7 @@ def generate_ident_page(ctx, q, project, version, family, ident):
695
699
if len (symbol_references ):
696
700
symbol_sections .append ({
697
701
'title' : 'Referenced' ,
698
- 'symbols' : {'_unknown' : [symbol_instance_to_entry (source_base_url , sym ) for sym in symbol_references ]},
702
+ 'symbols' : {'_unknown' : [symbol_instance_to_entry (source_base_url , sym , peeks ) for sym in symbol_references ]},
699
703
})
700
704
else :
701
705
symbol_sections .append ({
0 commit comments