2929{type_declaration}
3030"""
3131
32- REFERENCES_TEMPLATE = \
32+ INDEX_REFERENCES_TEMPLATE = \
3333 """### References: <small><small>(from sublime index)</small></small>
34- {type_references}
34+
35+ {references}
36+ """
37+
38+ OPEN_FILES_REFERENCES_TEMPLATE = \
39+ """### References: <small><small>(from open files)</small></small>
40+
41+ {references}
3542"""
3643
3744BRIEF_DOC_TEMPLATE = """### Brief documentation:
@@ -173,25 +180,8 @@ def info(cursor, cindex, settings):
173180 type_declaration = markupsafe .escape (declaration_text ))
174181
175182 if settings .show_index_references :
176- index = sublime .active_window ().lookup_symbol_in_index (
177- cursor .spelling )
178- index_references = []
179- for location_tuple in index :
180- location = IndexLocation (filename = location_tuple [0 ],
181- line = location_tuple [2 ][0 ],
182- column = location_tuple [2 ][1 ])
183- index_references .append (
184- "{reference}: `{file}:{line}:{col}`" .format (
185- reference = Popup .link_from_location (location ,
186- cursor .spelling ),
187- file = location .file .short_name ,
188- line = location .line ,
189- col = location .column ))
190- log .debug ("references from index: %s" , index_references )
191- if index_references :
192- popup .__text += REFERENCES_TEMPLATE .format (
193- type_references = markupsafe .escape (
194- "\n " .join (index_references )))
183+ popup .__text += Popup .__lookup_in_sublime_index (
184+ sublime .active_window (), cursor .spelling )
195185
196186 # Doxygen comments
197187 if cursor .brief_comment :
@@ -218,6 +208,33 @@ def info(cursor, cindex, settings):
218208 content = CODE_TEMPLATE .format (lang = "c++" , code = body ))
219209 return popup
220210
211+ @staticmethod
212+ def __lookup_in_sublime_index (window , spelling ):
213+ def lookup (lookup_function , spelling ):
214+ index = lookup_function (spelling )
215+ references = []
216+ for location_tuple in index :
217+ location = IndexLocation (filename = location_tuple [0 ],
218+ line = location_tuple [2 ][0 ],
219+ column = location_tuple [2 ][1 ])
220+ references .append (
221+ "{reference}: `{file}:{line}:{col}`" .format (
222+ reference = Popup .link_from_location (location , spelling ),
223+ file = location .file .short_name ,
224+ line = location .line ,
225+ col = location .column ))
226+ return markupsafe .escape ("\n - " .join (references ))
227+ index_references = lookup (window .lookup_symbol_in_index , spelling )
228+ usage_references = lookup (window .lookup_symbol_in_open_files , spelling )
229+ output_text = ""
230+ if index_references :
231+ output_text += INDEX_REFERENCES_TEMPLATE .format (
232+ references = " - " + index_references )
233+ if usage_references :
234+ output_text += OPEN_FILES_REFERENCES_TEMPLATE .format (
235+ references = " - " + usage_references )
236+ return output_text
237+
221238 def info_objc (cursor , cindex , settings ):
222239 """Provide information about Objective C cursors."""
223240 popup = Popup ((
0 commit comments