Skip to content

Commit

Permalink
add NO_UNDO flags to all regions
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Dec 4, 2023
1 parent a83e4e8 commit 66a892c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
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
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

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

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
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

_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
3 changes: 2 additions & 1 deletion plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from .core.views import MissingUriError
from .core.views import range_to_region
from .core.views import region_to_range
from .core.views import SEMANTIC_TOKEN_FLAGS
from .core.views import text_document_identifier
from .core.views import will_save
from .inlay_hint import inlay_hint_to_phantom
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

0 comments on commit 66a892c

Please sign in to comment.