From fdb1ae20c055eac766bb3ada23b52380bc8a1d50 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Sat, 18 Nov 2023 16:09:27 +0100 Subject: [PATCH] Rename and move dict for DocumentHighlight region keys part into constants module --- plugin/core/constants.py | 8 ++++++++ plugin/core/views.py | 6 ------ plugin/documents.py | 4 ++-- plugin/session_view.py | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/plugin/core/constants.py b/plugin/core/constants.py index a4e3e1b79..1db3031d7 100644 --- a/plugin/core/constants.py +++ b/plugin/core/constants.py @@ -1,6 +1,7 @@ from .protocol import CodeActionKind from .protocol import CompletionItemKind from .protocol import DiagnosticSeverity +from .protocol import DocumentHighlightKind from .protocol import SymbolKind from .typing import Dict, Tuple import sublime @@ -133,3 +134,10 @@ CodeActionKind.Refactor: KIND_REFACTOR, CodeActionKind.Source: KIND_SOURCE } # type: Dict[CodeActionKind, SublimeKind] + + +DOCUMENT_HIGHLIGHT_KIND_NAMES = { + DocumentHighlightKind.Text: "text", + DocumentHighlightKind.Read: "read", + DocumentHighlightKind.Write: "write" +} # type: Dict[DocumentHighlightKind, str] diff --git a/plugin/core/views.py b/plugin/core/views.py index 5e77e2d5d..b075d2657 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -76,12 +76,6 @@ sublime.KIND_VARIABLE: "entity.name.constant | constant.other | support.constant | variable.other | variable.parameter | variable.other.member | variable.other.readwrite.member" # noqa: E501 } # type: Dict[SublimeKind, str] -DOCUMENT_HIGHLIGHT_KINDS = { - DocumentHighlightKind.Text: "text", - DocumentHighlightKind.Read: "read", - DocumentHighlightKind.Write: "write" -} # type: Dict[DocumentHighlightKind, str] - DOCUMENT_HIGHLIGHT_KIND_SCOPES = { DocumentHighlightKind.Text: "region.bluish markup.highlight.text.lsp", DocumentHighlightKind.Read: "region.greenish markup.highlight.read.lsp", diff --git a/plugin/documents.py b/plugin/documents.py index 150a65ada..6eea0b2c4 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -2,6 +2,7 @@ from .code_actions import CodeActionOrCommand from .code_actions import CodeActionsByConfigName from .completion import QueryCompletionsTask +from .core.constants import DOCUMENT_HIGHLIGHT_KIND_NAMES from .core.constants import HOVER_ENABLED_KEY from .core.logging import debug from .core.open import open_in_browser @@ -39,7 +40,6 @@ from .core.url import view_to_uri from .core.views import diagnostic_severity from .core.views import DOCUMENT_HIGHLIGHT_KIND_SCOPES -from .core.views import DOCUMENT_HIGHLIGHT_KINDS from .core.views import first_selection_region from .core.views import format_code_actions_for_quick_panel from .core.views import format_diagnostic_for_html @@ -764,7 +764,7 @@ def _resolve_visible_code_lenses_async(self) -> None: # --- textDocument/documentHighlight ------------------------------------------------------------------------------- def _highlights_key(self, kind: DocumentHighlightKind, multiline: bool) -> str: - return "lsp_highlight_{}{}".format(DOCUMENT_HIGHLIGHT_KINDS[kind], "m" if multiline else "s") + return "lsp_highlight_{}{}".format(DOCUMENT_HIGHLIGHT_KIND_NAMES[kind], "m" if multiline else "s") def _clear_highlight_regions(self) -> None: for kind in [DocumentHighlightKind.Text, DocumentHighlightKind.Read, DocumentHighlightKind.Write]: diff --git a/plugin/session_view.py b/plugin/session_view.py index 0e775acb9..f9df622c3 100644 --- a/plugin/session_view.py +++ b/plugin/session_view.py @@ -1,6 +1,7 @@ from .code_lens import CodeLensView from .code_lens import LspToggleCodeLensesCommand from .core.active_request import ActiveRequest +from .core.constants import DOCUMENT_HIGHLIGHT_KIND_NAMES from .core.constants import HOVER_ENABLED_KEY from .core.constants import HOVER_HIGHLIGHT_KEY from .core.constants import HOVER_PROVIDER_COUNT_KEY @@ -135,13 +136,12 @@ def _initialize_region_keys(self) -> None: r = [sublime.Region(0, 0)] document_highlight_style = userprefs().document_highlight_style hover_highlight_style = userprefs().hover_highlight_style - document_highlight_kinds = ["text", "read", "write"] 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): self.view.add_regions("lsp_semantic_{}".format(key), r) if document_highlight_style in ("background", "fill"): - for kind in document_highlight_kinds: + for kind in DOCUMENT_HIGHLIGHT_KIND_NAMES.values(): for mode in line_modes: self.view.add_regions("lsp_highlight_{}{}".format(kind, mode), r) if hover_highlight_style in ("background", "fill"): @@ -158,7 +158,7 @@ def _initialize_region_keys(self) -> None: for mode in line_modes: self.view.add_regions("lsp{}d{}{}_underline".format(self.session.config.name, mode, severity), r) if document_highlight_style in ("underline", "stippled"): - for kind in document_highlight_kinds: + for kind in DOCUMENT_HIGHLIGHT_KIND_NAMES.values(): for mode in line_modes: self.view.add_regions("lsp_highlight_{}{}".format(kind, mode), r) if hover_highlight_style in ("underline", "stippled"):