Skip to content

Commit

Permalink
Rename and move dict for DocumentHighlight region keys part into cons…
Browse files Browse the repository at this point in the history
…tants module
  • Loading branch information
jwortmann committed Nov 27, 2023
1 parent e51c2cb commit a838cd2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
8 changes: 8 additions & 0 deletions plugin/core/constants.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
6 changes: 0 additions & 6 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
6 changes: 3 additions & 3 deletions plugin/session_view.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"):
Expand All @@ -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"):
Expand Down

0 comments on commit a838cd2

Please sign in to comment.