From a28a9e229b6718c2927742674fffbb239cd72ed5 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 21 Sep 2024 23:36:43 +0200 Subject: [PATCH 1/3] use session-unique region keys for semantic tokens --- plugin/session_buffer.py | 6 +++--- plugin/session_view.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index 06de98ef6..68be5936a 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -681,12 +681,12 @@ def _draw_semantic_tokens_async(self) -> None: if region_key not in scope_regions.keys(): self.semantic_tokens.active_region_keys.remove(region_key) for sv in self.session_views: - sv.view.erase_regions(f"lsp_semantic_{region_key}") + sv.view.erase_regions(f"lsp_semantic_{self.session.config.name}_{region_key}") for region_key, (scope, regions) in scope_regions.items(): if region_key not in self.semantic_tokens.active_region_keys: self.semantic_tokens.active_region_keys.add(region_key) for sv in self.session_views: - sv.view.add_regions(f"lsp_semantic_{region_key}", regions, scope, flags=SEMANTIC_TOKEN_FLAGS) + sv.view.add_regions(f"lsp_semantic_{self.session.config.name}_{region_key}", regions, scope, flags=SEMANTIC_TOKEN_FLAGS) def _get_semantic_region_key_for_scope(self, scope: str) -> int: if scope not in self._semantic_region_keys: @@ -696,7 +696,7 @@ def _get_semantic_region_key_for_scope(self, scope: str) -> int: def _clear_semantic_token_regions(self, view: sublime.View) -> None: for region_key in self.semantic_tokens.active_region_keys: - view.erase_regions(f"lsp_semantic_{region_key}") + view.erase_regions(f"lsp_semantic_{self.session.config.name}_{region_key}") def set_semantic_tokens_pending_refresh(self, needs_refresh: bool = True) -> None: self.semantic_tokens.needs_refresh = needs_refresh diff --git a/plugin/session_view.py b/plugin/session_view.py index 6d4d0c706..cb7bc8acc 100644 --- a/plugin/session_view.py +++ b/plugin/session_view.py @@ -141,7 +141,7 @@ def _initialize_region_keys(self) -> None: line_modes = ["m", "s"] self.view.add_regions(self.CODE_ACTIONS_KEY, r) # code actions lightbulb icon should always be on top for key in range(1, 100): - keys.append(f"lsp_semantic_{key}") + keys.append(f"lsp_semantic_{self.session.config.name}_{key}") if document_highlight_style in ("background", "fill"): for kind in DOCUMENT_HIGHLIGHT_KIND_NAMES.values(): for mode in line_modes: From eec46734aa670fd8091069eb5d790bbe07d6af1f Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 21 Sep 2024 23:45:26 +0200 Subject: [PATCH 2/3] shorten --- plugin/session_buffer.py | 8 +++++--- plugin/session_view.py | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index 68be5936a..1b64b1720 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -677,16 +677,17 @@ def _draw_semantic_tokens_async(self) -> None: # don't update regions if there were additional changes to the buffer in the meantime if self.semantic_tokens.view_change_count != view.change_count(): return + session_name = self.session.config.name for region_key in self.semantic_tokens.active_region_keys.copy(): if region_key not in scope_regions.keys(): self.semantic_tokens.active_region_keys.remove(region_key) for sv in self.session_views: - sv.view.erase_regions(f"lsp_semantic_{self.session.config.name}_{region_key}") + sv.view.erase_regions(f"lsp_semantic_{session_name}_{region_key}") for region_key, (scope, regions) in scope_regions.items(): if region_key not in self.semantic_tokens.active_region_keys: self.semantic_tokens.active_region_keys.add(region_key) for sv in self.session_views: - sv.view.add_regions(f"lsp_semantic_{self.session.config.name}_{region_key}", regions, scope, flags=SEMANTIC_TOKEN_FLAGS) + sv.view.add_regions(f"lsp_semantic_{session_name}_{region_key}", regions, scope, flags=SEMANTIC_TOKEN_FLAGS) def _get_semantic_region_key_for_scope(self, scope: str) -> int: if scope not in self._semantic_region_keys: @@ -695,8 +696,9 @@ def _get_semantic_region_key_for_scope(self, scope: str) -> int: return self._semantic_region_keys[scope] def _clear_semantic_token_regions(self, view: sublime.View) -> None: + session_name = self.session.config.name for region_key in self.semantic_tokens.active_region_keys: - view.erase_regions(f"lsp_semantic_{self.session.config.name}_{region_key}") + view.erase_regions(f"lsp_semantic_{session_name}_{region_key}") def set_semantic_tokens_pending_refresh(self, needs_refresh: bool = True) -> None: self.semantic_tokens.needs_refresh = needs_refresh diff --git a/plugin/session_view.py b/plugin/session_view.py index cb7bc8acc..94296b6cc 100644 --- a/plugin/session_view.py +++ b/plugin/session_view.py @@ -140,8 +140,9 @@ def _initialize_region_keys(self) -> None: hover_highlight_style = userprefs().hover_highlight_style line_modes = ["m", "s"] self.view.add_regions(self.CODE_ACTIONS_KEY, r) # code actions lightbulb icon should always be on top + session_name = self.session.config.name for key in range(1, 100): - keys.append(f"lsp_semantic_{self.session.config.name}_{key}") + keys.append(f"lsp_semantic_{session_name}_{key}") if document_highlight_style in ("background", "fill"): for kind in DOCUMENT_HIGHLIGHT_KIND_NAMES.values(): for mode in line_modes: @@ -151,14 +152,14 @@ def _initialize_region_keys(self) -> None: for severity in range(1, 5): for mode in line_modes: for tag in range(1, 3): - keys.append(f"lsp{self.session.config.name}d{mode}{severity}_tags_{tag}") + keys.append(f"lsp{session_name}d{mode}{severity}_tags_{tag}") keys.append("lsp_document_link") for severity in range(1, 5): for mode in line_modes: - keys.append(f"lsp{self.session.config.name}d{mode}{severity}_icon") + keys.append(f"lsp{session_name}d{mode}{severity}_icon") for severity in range(4, 0, -1): for mode in line_modes: - keys.append(f"lsp{self.session.config.name}d{mode}{severity}_underline") + keys.append(f"lsp{session_name}d{mode}{severity}_underline") if document_highlight_style in ("underline", "stippled"): for kind in DOCUMENT_HIGHLIGHT_KIND_NAMES.values(): for mode in line_modes: From 83d83f55407faced4b7665cc24501562e216138b Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 21 Sep 2024 23:46:56 +0200 Subject: [PATCH 3/3] wrap --- plugin/session_buffer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index 1b64b1720..cf432e6af 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -687,7 +687,8 @@ def _draw_semantic_tokens_async(self) -> None: if region_key not in self.semantic_tokens.active_region_keys: self.semantic_tokens.active_region_keys.add(region_key) for sv in self.session_views: - sv.view.add_regions(f"lsp_semantic_{session_name}_{region_key}", regions, scope, flags=SEMANTIC_TOKEN_FLAGS) + sv.view.add_regions( + f"lsp_semantic_{session_name}_{region_key}", regions, scope, flags=SEMANTIC_TOKEN_FLAGS) def _get_semantic_region_key_for_scope(self, scope: str) -> int: if scope not in self._semantic_region_keys: