@@ -635,23 +635,26 @@ def generate_source_page(ctx, q, project, version, path):
635635# type: type of the symbol
636636# path: path of the file that contains the symbol
637637# 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' )
639640
640641# Converts SymbolInstance into SymbolEntry
641642# 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 ):
643644 # TODO this should be a responsibility of Query
644645 if type (symbol .line ) is str :
645646 line_numbers = symbol .line .split (',' )
646647 else :
647648 line_numbers = [symbol .line ]
648649
649650 lines = [
650- LineWithURL (l , f'{ base_url } /{ symbol .path } #L{ l } ' )
651+ LineWithURL (int ( l ) , f'{ base_url } /{ symbol .path } #L{ l } ' )
651652 for l in line_numbers
652653 ]
653654
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 )
655658
656659# Generates response (status code and optionally HTML) of the `ident` route
657660# ctx: RequestContext
@@ -662,15 +665,16 @@ def generate_ident_page(ctx, q, project, version, family, ident):
662665
663666 source_base_url = get_source_base_url (project , version )
664667
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 )
666669
667670 symbol_sections = []
671+ empty_peeks = {}
668672
669673 if len (symbol_definitions ) or len (symbol_references ):
670674 if len (symbol_doccomments ):
671675 symbol_sections .append ({
672676 '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 ]},
674678 })
675679
676680 if len (symbol_definitions ):
@@ -679,9 +683,9 @@ def generate_ident_page(ctx, q, project, version, family, ident):
679683 # TODO this should be a responsibility of Query
680684 for sym in symbol_definitions :
681685 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 )]
683687 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 ))
685689
686690 symbol_sections .append ({
687691 'title' : 'Defined' ,
@@ -695,7 +699,7 @@ def generate_ident_page(ctx, q, project, version, family, ident):
695699 if len (symbol_references ):
696700 symbol_sections .append ({
697701 '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 ]},
699703 })
700704 else :
701705 symbol_sections .append ({
0 commit comments