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

add NO_UNDO flags to all regions #2370

Merged
merged 12 commits into from
Dec 13, 2023
3 changes: 2 additions & 1 deletion plugin/code_lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ def render(self, mode: str) -> None:
self._phantom.update(phantoms)
else: # 'annotation'
self._clear_annotations()
flags = sublime.NO_UNDO
accent = self.view.style_for_scope("region.greenish markup.accent.codelens.lsp")["foreground"]
for index, lens in enumerate(self._flat_iteration()):
self.view.add_regions(
self._region_key(lens.session_name, index), [lens.region], "", "", 0, [lens.small_html], accent)
self._region_key(lens.session_name, index), [lens.region], "", "", flags, [lens.small_html], accent)

def get_resolved_code_lenses_for_region(self, region: sublime.Region) -> Generator[CodeLensExtended, None, None]:
region = self.view.line(region)
Expand Down
4 changes: 4 additions & 0 deletions plugin/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
HOVER_PROVIDER_COUNT_KEY = 'lsp_hover_provider_count'
SHOW_DEFINITIONS_KEY = 'show_definitions'

# Region flags
DOCUMENT_LINK_FLAGS = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE | sublime.NO_UNDO # noqa: E501
SEMANTIC_TOKEN_FLAGS = sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO

# sublime.Kind tuples for sublime.CompletionItem, sublime.QuickPanelItem, sublime.ListInputItem
# https://www.sublimetext.com/docs/api_reference.html#sublime.Kind
KIND_ARRAY = (sublime.KIND_ID_TYPE, "a", "Array")
Expand Down
40 changes: 21 additions & 19 deletions plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,31 +320,33 @@ def r(name: str, default: Union[bool, int, str, list, dict]) -> None:
set_debug_logging(self.log_debug)

def highlight_style_region_flags(self, style_str: str) -> Tuple[int, int]:
default = sublime.NO_UNDO
if style_str in ("background", "fill"): # Backwards-compatible with "fill"
return sublime.DRAW_NO_OUTLINE, sublime.DRAW_NO_OUTLINE
elif style_str == "outline":
return sublime.DRAW_NO_FILL, sublime.DRAW_NO_FILL
elif style_str == "stippled":
return sublime.DRAW_NO_FILL, sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_STIPPLED_UNDERLINE # noqa: E501
else:
return sublime.DRAW_NO_FILL, sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE # noqa: E501
style = default | sublime.DRAW_NO_OUTLINE
return style, style
if style_str == "outline":
style = default | sublime.DRAW_NO_FILL
return style, style
if style_str == "stippled":
return default | sublime.DRAW_NO_FILL, default | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_STIPPLED_UNDERLINE # noqa: E501
return default | sublime.DRAW_NO_FILL, default | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE # noqa: E501

@staticmethod
def _style_str_to_flag(style_str: str) -> Optional[int]:
default = sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_NO_FILL | sublime.NO_UNDO
# This method could be a dict or lru_cache
if style_str == "":
return sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
elif style_str == "box":
return sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_NO_FILL
elif style_str == "underline":
return sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE # noqa: E501
elif style_str == "stippled":
return sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_STIPPLED_UNDERLINE # noqa: E501
elif style_str == "squiggly":
return sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SQUIGGLY_UNDERLINE # noqa: E501
else:
# default style
return None
return default | sublime.DRAW_NO_OUTLINE
if style_str == "box":
return default
if style_str == "underline":
return default | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE
if style_str == "stippled":
return default | sublime.DRAW_NO_OUTLINE | sublime.DRAW_STIPPLED_UNDERLINE
if style_str == "squiggly":
return default | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SQUIGGLY_UNDERLINE
# default style (includes NO_UNDO)
return None
rchl marked this conversation as resolved.
Show resolved Hide resolved

def diagnostics_highlight_style_flags(self) -> List[Optional[int]]:
"""Returns flags for highlighting diagnostics on single lines per severity"""
Expand Down
4 changes: 1 addition & 3 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@

MarkdownLangMap = Dict[str, Tuple[Tuple[str, ...], Tuple[str, ...]]]

DOCUMENT_LINK_FLAGS = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE # noqa: E501

_baseflags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_EMPTY_AS_OVERWRITE
_baseflags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.NO_UNDO

DIAGNOSTIC_SEVERITY = [
# Kind CSS class Scope for color Icon resource add_regions flags for single-line diagnostic multi-line diagnostic # noqa: E501
Expand Down
2 changes: 1 addition & 1 deletion plugin/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _annotation_region_key(self, severity: DiagnosticSeverity) -> str:
return 'lsp_da-{}-{}'.format(severity, self._config_name)

def draw(self, diagnostics: List[Tuple[Diagnostic, sublime.Region]]) -> None:
flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO
max_severity_level = userprefs().show_diagnostics_annotations_severity_level
# To achieve the correct order of annotations (most severe having priority) we have to add regions from the
# most to the least severe.
Expand Down
2 changes: 1 addition & 1 deletion plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def _on_code_actions(self, responses: List[CodeActionsByConfigName]) -> None:
regions = [sublime.Region(region.b, region.a)]
scope = ""
icon = ""
flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO
annotations = []
annotation_color = ""
if userprefs().show_code_actions == 'bulb':
Expand Down
2 changes: 1 addition & 1 deletion plugin/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _show_references_in_output_panel(self, word: str, session: Session, location
})
# highlight all word occurrences
regions = panel.find_all(r"\b{}\b".format(word))
panel.add_regions('ReferenceHighlight', regions, 'comment', flags=sublime.DRAW_NO_FILL)
panel.add_regions('ReferenceHighlight', regions, 'comment', flags=sublime.DRAW_NO_FILL | sublime.NO_UNDO)


def _get_relative_path(base_dir: Optional[str], file_path: str) -> str:
Expand Down
5 changes: 3 additions & 2 deletions plugin/session_buffer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .core.constants import DOCUMENT_LINK_FLAGS
from .core.constants import SEMANTIC_TOKEN_FLAGS
from .core.protocol import ColorInformation
from .core.protocol import Diagnostic
from .core.protocol import DocumentDiagnosticParams
Expand Down Expand Up @@ -34,7 +36,6 @@
from .core.views import did_open
from .core.views import did_save
from .core.views import document_color_params
from .core.views import DOCUMENT_LINK_FLAGS
from .core.views import entire_content_range
from .core.views import lsp_color_to_phantom
from .core.views import MissingUriError
Expand Down Expand Up @@ -668,7 +669,7 @@ 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("lsp_semantic_{}".format(region_key), regions, scope, flags=sublime.DRAW_NO_OUTLINE)
sv.view.add_regions("lsp_semantic_{}".format(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:
Expand Down
7 changes: 4 additions & 3 deletions plugin/session_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def present_diagnostics_async(
self, is_view_visible: bool, data_per_severity: Dict[Tuple[int, bool], DiagnosticSeverityData]
) -> None:
flags = userprefs().diagnostics_highlight_style_flags() # for single lines
multiline_flags = None if userprefs().show_multiline_diagnostics_highlights else sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE # noqa: E501
multiline_flags = sublime.NO_UNDO if userprefs().show_multiline_diagnostics_highlights else sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO # noqa: E501
level = userprefs().show_diagnostics_severity_level
for sev in reversed(range(1, len(DIAGNOSTIC_SEVERITY) + 1)):
self._draw_diagnostics(
Expand All @@ -320,7 +320,7 @@ def _draw_diagnostics(
flags: int,
multiline: bool
) -> None:
ICON_FLAGS = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
ICON_FLAGS = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO
key = self.diagnostics_key(severity, multiline)
tags = {tag: TagData('{}_tags_{}'.format(key, tag)) for tag in DIAGNOSTIC_TAG_VALUES}
data = data_per_severity.get((severity, multiline))
Expand All @@ -341,7 +341,8 @@ def _draw_diagnostics(
self.view.erase_regions("{}_underline".format(key))
for data in tags.values():
if data.regions:
self.view.add_regions(data.key, data.regions, data.scope, flags=sublime.DRAW_NO_OUTLINE)
self.view.add_regions(
data.key, data.regions, data.scope, flags=sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO)
else:
self.view.erase_regions(data.key)

Expand Down