Skip to content

Commit

Permalink
Remove duplicate references response.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Jul 7, 2023
1 parent 25be1a2 commit 56334a3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/handler/find_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ def process_request(self, position) -> dict:
context=dict(includeDeclaration=False)
)

def process_response(self, response: dict) -> None:
def process_response(self, response) -> None:
if response is None:
eval_in_emacs("lsp-bridge-find-ref-fallback", self.pos)
else:
response = self.remove_duplicate_references(response)

references_dict = {}
for uri_info in response:
path = uri_to_path(uri_info["uri"])
Expand Down Expand Up @@ -51,3 +53,13 @@ def process_response(self, response: dict) -> None:
linecache.clearcache() # clear line cache

eval_in_emacs("lsp-bridge-references--popup", references_content, references_counter, self.pos)

def remove_duplicate_references(self, data):
seen = set()
result = []
for item in data:
t_item = (item["uri"], tuple(item["range"]["start"].items()), tuple(item["range"]["end"].items()))
if t_item not in seen:
seen.add(t_item)
result.append(item)
return result

0 comments on commit 56334a3

Please sign in to comment.