Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/document highlight cache #1409

Merged
merged 6 commits into from
Nov 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ def _do_highlights_async(self) -> None:
session.send_request_async(request, self._on_highlights)

def _on_highlights(self, response: Optional[List]) -> None:
self._clear_highlight_regions()
if not response:
self._clear_highlight_regions()
return
kind2regions = {} # type: Dict[str, List[sublime.Region]]
for kind in range(0, 4):
Expand All @@ -511,12 +511,17 @@ def _on_highlights(self, response: Optional[List]) -> None:
kind = highlight.get("kind", DocumentHighlightKind.Unknown)
if kind is not None:
kind2regions[_kind2name[kind]].append(r)
flags = userprefs().document_highlight_style_to_add_regions_flags()
for kind_str, regions in kind2regions.items():
if regions:
scope = userprefs().document_highlight_scopes.get(kind_str, None)
if scope:
self.view.add_regions("lsp_highlight_{}".format(kind_str), regions, scope=scope, flags=flags)

def render_highlights_on_main_thread() -> None:
self._clear_highlight_regions()
flags = userprefs().document_highlight_style_to_add_regions_flags()
for kind_str, regions in kind2regions.items():
if regions:
scope = userprefs().document_highlight_scopes.get(kind_str, None)
if scope:
self.view.add_regions("lsp_highlight_{}".format(kind_str), regions, scope=scope, flags=flags)

sublime.set_timeout(render_highlights_on_main_thread)

# --- textDocument/complete ----------------------------------------------------------------------------------------

Expand Down