Skip to content

Commit

Permalink
Lookup references to symbols in open files (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
niosus authored Dec 22, 2020
1 parent c06a0ef commit 8b66d57
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions messages/6.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Improvements and bug fixes:
end, the picked file is committed to file.
- Details here:
https://niosus.github.io/EasyClangComplete/settings/#autocomplete_includes
- Info popup now also shows references from open files.
- Get rid of a singleton in the thread pool. Use a single instance per
plugin.

Expand Down
59 changes: 38 additions & 21 deletions plugin/error_vis/popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@
{type_declaration}
"""

REFERENCES_TEMPLATE = \
INDEX_REFERENCES_TEMPLATE = \
"""### References: <small><small>(from sublime index)</small></small>
{type_references}
{references}
"""

OPEN_FILES_REFERENCES_TEMPLATE = \
"""### References: <small><small>(from open files)</small></small>
{references}
"""

BRIEF_DOC_TEMPLATE = """### Brief documentation:
Expand Down Expand Up @@ -173,25 +180,8 @@ def info(cursor, cindex, settings):
type_declaration=markupsafe.escape(declaration_text))

if settings.show_index_references:
index = sublime.active_window().lookup_symbol_in_index(
cursor.spelling)
index_references = []
for location_tuple in index:
location = IndexLocation(filename=location_tuple[0],
line=location_tuple[2][0],
column=location_tuple[2][1])
index_references.append(
"{reference}: `{file}:{line}:{col}`".format(
reference=Popup.link_from_location(location,
cursor.spelling),
file=location.file.short_name,
line=location.line,
col=location.column))
log.debug("references from index: %s", index_references)
if index_references:
popup.__text += REFERENCES_TEMPLATE.format(
type_references=markupsafe.escape(
"\n".join(index_references)))
popup.__text += Popup.__lookup_in_sublime_index(
sublime.active_window(), cursor.spelling)

# Doxygen comments
if cursor.brief_comment:
Expand All @@ -218,6 +208,33 @@ def info(cursor, cindex, settings):
content=CODE_TEMPLATE.format(lang="c++", code=body))
return popup

@staticmethod
def __lookup_in_sublime_index(window, spelling):
def lookup(lookup_function, spelling):
index = lookup_function(spelling)
references = []
for location_tuple in index:
location = IndexLocation(filename=location_tuple[0],
line=location_tuple[2][0],
column=location_tuple[2][1])
references.append(
"{reference}: `{file}:{line}:{col}`".format(
reference=Popup.link_from_location(location, spelling),
file=location.file.short_name,
line=location.line,
col=location.column))
return markupsafe.escape("\n - ".join(references))
index_references = lookup(window.lookup_symbol_in_index, spelling)
usage_references = lookup(window.lookup_symbol_in_open_files, spelling)
output_text = ""
if index_references:
output_text += INDEX_REFERENCES_TEMPLATE.format(
references=" - " + index_references)
if usage_references:
output_text += OPEN_FILES_REFERENCES_TEMPLATE.format(
references=" - " + usage_references)
return output_text

def info_objc(cursor, cindex, settings):
"""Provide information about Objective C cursors."""
popup = Popup((
Expand Down

0 comments on commit 8b66d57

Please sign in to comment.