From d6815f5bef44c736d3be4658cd10b5aee336d363 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Fri, 25 Oct 2024 18:20:18 +0200 Subject: [PATCH] Use namespaced enum constants --- plugin/code_lens.py | 4 +- plugin/completion.py | 12 ++--- plugin/core/constants.py | 92 +++++++++++++++++++-------------------- plugin/core/open.py | 6 +-- plugin/core/registry.py | 4 +- plugin/core/tree_view.py | 18 ++++---- plugin/core/types.py | 20 ++++----- plugin/core/views.py | 14 +++--- plugin/core/windows.py | 2 +- plugin/diagnostics.py | 2 +- plugin/documents.py | 31 +++++++------ plugin/goto_diagnostic.py | 6 +-- plugin/hierarchy.py | 4 +- plugin/hover.py | 2 +- plugin/inlay_hint.py | 2 +- plugin/locationpicker.py | 18 ++++---- plugin/references.py | 7 ++- plugin/rename.py | 6 +-- plugin/session_view.py | 10 +++-- plugin/symbols.py | 4 +- stubs/sublime.pyi | 4 +- 21 files changed, 141 insertions(+), 127 deletions(-) diff --git a/plugin/code_lens.py b/plugin/code_lens.py index 706e8fa3c..b3aad4cfc 100644 --- a/plugin/code_lens.py +++ b/plugin/code_lens.py @@ -194,11 +194,11 @@ def render(self, mode: str) -> None: phantom_region = self._get_phantom_region(region) html = '{}'.format( '\n|\n'.join(lens.small_html for lens in group)) - phantoms.append(sublime.Phantom(phantom_region, html, sublime.LAYOUT_BELOW)) + phantoms.append(sublime.Phantom(phantom_region, html, sublime.PhantomLayout.BELOW)) self._phantom.update(phantoms) else: # 'annotation' self._clear_annotations() - flags = sublime.NO_UNDO + flags = sublime.RegionFlags.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( diff --git a/plugin/completion.py b/plugin/completion.py index 02fbeba81..6d2e5fdcd 100644 --- a/plugin/completion.py +++ b/plugin/completion.py @@ -103,7 +103,7 @@ def format_completion( annotation, # Not using "sublime.format_command" in a hot path to avoid slow json.dumps. f'lsp_select_completion {{"index":{index},"session_name":"{session_name}"}}', - sublime.COMPLETION_FORMAT_COMMAND, + sublime.CompletionFormat.COMMAND, kind, details=" | ".join(details) ) @@ -215,9 +215,9 @@ def _resolve_completions_async(self, responses: list[ResolvedCompletions]) -> No flags = sublime.AutoCompleteFlags.NONE prefs = userprefs() if prefs.inhibit_snippet_completions: - flags |= sublime.INHIBIT_EXPLICIT_COMPLETIONS + flags |= sublime.AutoCompleteFlags.INHIBIT_EXPLICIT_COMPLETIONS if prefs.inhibit_word_completions: - flags |= sublime.INHIBIT_WORD_COMPLETIONS + flags |= sublime.AutoCompleteFlags.INHIBIT_WORD_COMPLETIONS view_settings = self._view.settings() include_snippets = view_settings.get("auto_complete_include_snippets") and \ (self._triggered_manually or view_settings.get("auto_complete_include_snippets_when_typing")) @@ -233,7 +233,7 @@ def _resolve_completions_async(self, responses: list[ResolvedCompletions]) -> No response_items = response["items"] or [] item_defaults = response.get('itemDefaults') or {} if response.get("isIncomplete", False): - flags |= sublime.DYNAMIC_COMPLETIONS + flags |= sublime.AutoCompleteFlags.DYNAMIC_COMPLETIONS elif isinstance(response, list): response_items = response response_items = sorted(response_items, key=lambda item: item.get("sortText") or item["label"]) @@ -246,7 +246,7 @@ def _resolve_completions_async(self, responses: list[ResolvedCompletions]) -> No for index, response_item in enumerate(response_items) if include_snippets or response_item.get("kind") != CompletionItemKind.Snippet) if items: - flags |= sublime.INHIBIT_REORDER + flags |= sublime.AutoCompleteFlags.INHIBIT_REORDER if errors: error_messages = ", ".join(str(error) for error in errors) sublime.status_message(f'Completion error: {error_messages}') @@ -316,7 +316,7 @@ def run_main() -> None: show_lsp_popup( self.view, minihtml_content, - flags=sublime.COOPERATE_WITH_AUTO_COMPLETE, + flags=sublime.PopupFlags.COOPERATE_WITH_AUTO_COMPLETE, md=False, on_navigate=self._on_navigate) diff --git a/plugin/core/constants.py b/plugin/core/constants.py index a83f345a4..3793d3465 100644 --- a/plugin/core/constants.py +++ b/plugin/core/constants.py @@ -22,55 +22,55 @@ 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 -REGIONS_INITIALIZE_FLAGS = sublime.HIDDEN | sublime.NO_UNDO -SEMANTIC_TOKEN_FLAGS = sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO +DOCUMENT_LINK_FLAGS = sublime.RegionFlags.HIDE_ON_MINIMAP | sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.DRAW_SOLID_UNDERLINE | sublime.RegionFlags.NO_UNDO # noqa: E501 +REGIONS_INITIALIZE_FLAGS = sublime.RegionFlags.HIDDEN | sublime.RegionFlags.NO_UNDO +SEMANTIC_TOKEN_FLAGS = sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.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") -KIND_BOOLEAN = (sublime.KIND_ID_VARIABLE, "b", "Boolean") -KIND_CLASS = (sublime.KIND_ID_TYPE, "c", "Class") -KIND_COLOR = (sublime.KIND_ID_MARKUP, "c", "Color") -KIND_CONSTANT = (sublime.KIND_ID_VARIABLE, "c", "Constant") -KIND_CONSTRUCTOR = (sublime.KIND_ID_FUNCTION, "c", "Constructor") -KIND_ENUM = (sublime.KIND_ID_TYPE, "e", "Enum") -KIND_ENUMMEMBER = (sublime.KIND_ID_VARIABLE, "e", "Enum Member") -KIND_EVENT = (sublime.KIND_ID_FUNCTION, "e", "Event") -KIND_FIELD = (sublime.KIND_ID_VARIABLE, "f", "Field") -KIND_FILE = (sublime.KIND_ID_NAVIGATION, "f", "File") -KIND_FOLDER = (sublime.KIND_ID_NAVIGATION, "f", "Folder") -KIND_FUNCTION = (sublime.KIND_ID_FUNCTION, "f", "Function") -KIND_INTERFACE = (sublime.KIND_ID_TYPE, "i", "Interface") -KIND_KEY = (sublime.KIND_ID_NAVIGATION, "k", "Key") -KIND_KEYWORD = (sublime.KIND_ID_KEYWORD, "k", "Keyword") -KIND_METHOD = (sublime.KIND_ID_FUNCTION, "m", "Method") -KIND_MODULE = (sublime.KIND_ID_NAMESPACE, "m", "Module") -KIND_NAMESPACE = (sublime.KIND_ID_NAMESPACE, "n", "Namespace") -KIND_NULL = (sublime.KIND_ID_VARIABLE, "n", "Null") -KIND_NUMBER = (sublime.KIND_ID_VARIABLE, "n", "Number") -KIND_OBJECT = (sublime.KIND_ID_TYPE, "o", "Object") -KIND_OPERATOR = (sublime.KIND_ID_KEYWORD, "o", "Operator") -KIND_PACKAGE = (sublime.KIND_ID_NAMESPACE, "p", "Package") -KIND_PROPERTY = (sublime.KIND_ID_VARIABLE, "p", "Property") -KIND_REFERENCE = (sublime.KIND_ID_NAVIGATION, "r", "Reference") -KIND_SNIPPET = (sublime.KIND_ID_SNIPPET, "s", "Snippet") -KIND_STRING = (sublime.KIND_ID_VARIABLE, "s", "String") -KIND_STRUCT = (sublime.KIND_ID_TYPE, "s", "Struct") -KIND_TEXT = (sublime.KIND_ID_MARKUP, "t", "Text") -KIND_TYPEPARAMETER = (sublime.KIND_ID_TYPE, "t", "Type Parameter") -KIND_UNIT = (sublime.KIND_ID_VARIABLE, "u", "Unit") -KIND_VALUE = (sublime.KIND_ID_VARIABLE, "v", "Value") -KIND_VARIABLE = (sublime.KIND_ID_VARIABLE, "v", "Variable") - -KIND_ERROR = (sublime.KIND_ID_COLOR_REDISH, "e", "Error") -KIND_WARNING = (sublime.KIND_ID_COLOR_YELLOWISH, "w", "Warning") -KIND_INFORMATION = (sublime.KIND_ID_COLOR_BLUISH, "i", "Information") -KIND_HINT = (sublime.KIND_ID_COLOR_BLUISH, "h", "Hint") - -KIND_QUICKFIX = (sublime.KIND_ID_COLOR_YELLOWISH, "f", "QuickFix") -KIND_REFACTOR = (sublime.KIND_ID_COLOR_CYANISH, "r", "Refactor") -KIND_SOURCE = (sublime.KIND_ID_COLOR_PURPLISH, "s", "Source") +KIND_ARRAY = (sublime.KindId.TYPE, "a", "Array") +KIND_BOOLEAN = (sublime.KindId.VARIABLE, "b", "Boolean") +KIND_CLASS = (sublime.KindId.TYPE, "c", "Class") +KIND_COLOR = (sublime.KindId.MARKUP, "c", "Color") +KIND_CONSTANT = (sublime.KindId.VARIABLE, "c", "Constant") +KIND_CONSTRUCTOR = (sublime.KindId.FUNCTION, "c", "Constructor") +KIND_ENUM = (sublime.KindId.TYPE, "e", "Enum") +KIND_ENUMMEMBER = (sublime.KindId.VARIABLE, "e", "Enum Member") +KIND_EVENT = (sublime.KindId.FUNCTION, "e", "Event") +KIND_FIELD = (sublime.KindId.VARIABLE, "f", "Field") +KIND_FILE = (sublime.KindId.NAVIGATION, "f", "File") +KIND_FOLDER = (sublime.KindId.NAVIGATION, "f", "Folder") +KIND_FUNCTION = (sublime.KindId.FUNCTION, "f", "Function") +KIND_INTERFACE = (sublime.KindId.TYPE, "i", "Interface") +KIND_KEY = (sublime.KindId.NAVIGATION, "k", "Key") +KIND_KEYWORD = (sublime.KindId.KEYWORD, "k", "Keyword") +KIND_METHOD = (sublime.KindId.FUNCTION, "m", "Method") +KIND_MODULE = (sublime.KindId.NAMESPACE, "m", "Module") +KIND_NAMESPACE = (sublime.KindId.NAMESPACE, "n", "Namespace") +KIND_NULL = (sublime.KindId.VARIABLE, "n", "Null") +KIND_NUMBER = (sublime.KindId.VARIABLE, "n", "Number") +KIND_OBJECT = (sublime.KindId.TYPE, "o", "Object") +KIND_OPERATOR = (sublime.KindId.KEYWORD, "o", "Operator") +KIND_PACKAGE = (sublime.KindId.NAMESPACE, "p", "Package") +KIND_PROPERTY = (sublime.KindId.VARIABLE, "p", "Property") +KIND_REFERENCE = (sublime.KindId.NAVIGATION, "r", "Reference") +KIND_SNIPPET = (sublime.KindId.SNIPPET, "s", "Snippet") +KIND_STRING = (sublime.KindId.VARIABLE, "s", "String") +KIND_STRUCT = (sublime.KindId.TYPE, "s", "Struct") +KIND_TEXT = (sublime.KindId.MARKUP, "t", "Text") +KIND_TYPEPARAMETER = (sublime.KindId.TYPE, "t", "Type Parameter") +KIND_UNIT = (sublime.KindId.VARIABLE, "u", "Unit") +KIND_VALUE = (sublime.KindId.VARIABLE, "v", "Value") +KIND_VARIABLE = (sublime.KindId.VARIABLE, "v", "Variable") + +KIND_ERROR = (sublime.KindId.COLOR_REDISH, "e", "Error") +KIND_WARNING = (sublime.KindId.COLOR_YELLOWISH, "w", "Warning") +KIND_INFORMATION = (sublime.KindId.COLOR_BLUISH, "i", "Information") +KIND_HINT = (sublime.KindId.COLOR_BLUISH, "h", "Hint") + +KIND_QUICKFIX = (sublime.KindId.COLOR_YELLOWISH, "f", "QuickFix") +KIND_REFACTOR = (sublime.KindId.COLOR_CYANISH, "r", "Refactor") +KIND_SOURCE = (sublime.KindId.COLOR_PURPLISH, "s", "Source") COMPLETION_KINDS: dict[CompletionItemKind, SublimeKind] = { CompletionItemKind.Text: KIND_TEXT, diff --git a/plugin/core/open.py b/plugin/core/open.py index fbfe2ee84..a9a695f50 100644 --- a/plugin/core/open.py +++ b/plugin/core/open.py @@ -67,11 +67,11 @@ def _select_and_center(view: sublime.View | None, r: Range) -> sublime.View | No def _return_existing_view(flags: int, existing_view_group: int, active_group: int, specified_group: int) -> bool: if specified_group > -1: return existing_view_group == specified_group - if bool(flags & (sublime.ADD_TO_SELECTION | sublime.REPLACE_MRU)): + if bool(flags & (sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.REPLACE_MRU)): return False if existing_view_group == active_group: return True - return not bool(flags & sublime.FORCE_GROUP) + return not bool(flags & sublime.NewFileFlags.FORCE_GROUP) def _find_open_file(window: sublime.Window, fname: str, group: int = -1) -> sublime.View | None: @@ -101,7 +101,7 @@ def open_file( was_already_open = view is not None view = window.open_file(file, flags, group) if not view.is_loading(): - if was_already_open and (flags & sublime.SEMI_TRANSIENT): + if was_already_open and (flags & sublime.NewFileFlags.SEMI_TRANSIENT): # workaround bug https://github.com/sublimehq/sublime_text/issues/2411 where transient view might not get # its view listeners initialized. sublime_plugin.check_view_event_listeners(view) # type: ignore diff --git a/plugin/core/registry.py b/plugin/core/registry.py index 761029fee..4893920fd 100644 --- a/plugin/core/registry.py +++ b/plugin/core/registry.py @@ -182,9 +182,9 @@ def run( modifier_keys = event.get('modifier_keys') if modifier_keys: if 'primary' in modifier_keys: - flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT | sublime.CLEAR_TO_RIGHT + flags |= sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.SEMI_TRANSIENT | sublime.NewFileFlags.CLEAR_TO_RIGHT # noqa: E501 elif 'shift' in modifier_keys: - flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT + flags |= sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.SEMI_TRANSIENT sublime.set_timeout_async(lambda: self._run_async(location, session_name, flags, group)) def want_event(self) -> bool: diff --git a/plugin/core/tree_view.py b/plugin/core/tree_view.py index 7a6a01594..1322afd93 100644 --- a/plugin/core/tree_view.py +++ b/plugin/core/tree_view.py @@ -76,21 +76,21 @@ def html(self, sheet_name: str, indent_level: int) -> str: @staticmethod def _kind_class_name(kind_id: int) -> str: - if kind_id == sublime.KIND_ID_KEYWORD: + if kind_id == sublime.KindId.KEYWORD: return "kind kind_keyword" - if kind_id == sublime.KIND_ID_TYPE: + if kind_id == sublime.KindId.TYPE: return "kind kind_type" - if kind_id == sublime.KIND_ID_FUNCTION: + if kind_id == sublime.KindId.FUNCTION: return "kind kind_function" - if kind_id == sublime.KIND_ID_NAMESPACE: + if kind_id == sublime.KindId.NAMESPACE: return "kind kind_namespace" - if kind_id == sublime.KIND_ID_NAVIGATION: + if kind_id == sublime.KindId.NAVIGATION: return "kind kind_navigation" - if kind_id == sublime.KIND_ID_MARKUP: + if kind_id == sublime.KindId.MARKUP: return "kind kind_markup" - if kind_id == sublime.KIND_ID_VARIABLE: + if kind_id == sublime.KindId.VARIABLE: return "kind kind_variable" - if kind_id == sublime.KIND_ID_SNIPPET: + if kind_id == sublime.KindId.SNIPPET: return "kind kind_snippet" return "kind kind_ambiguous" @@ -297,7 +297,7 @@ def new_tree_view_sheet( sheet_id = tree_view_sheet.id() if tree_view_sheet.window(): tree_view_sheet.set_provider(data_provider, header) - if flags & sublime.ADD_TO_SELECTION: + if flags & sublime.NewFileFlags.ADD_TO_SELECTION: # add to selected sheets if not already selected selected_sheets = window.selected_sheets() for sheet in window.sheets(): diff --git a/plugin/core/types.py b/plugin/core/types.py index 97228d91c..ade41ed75 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -327,31 +327,31 @@ def r(name: str, default: bool | int | str | list | dict) -> None: set_debug_logging(self.log_debug) def highlight_style_region_flags(self, style_str: str) -> tuple[sublime.RegionFlags, sublime.RegionFlags]: - default = sublime.NO_UNDO + default = sublime.RegionFlags.NO_UNDO if style_str in ("background", "fill"): # Backwards-compatible with "fill" - style = default | sublime.DRAW_NO_OUTLINE + style = default | sublime.RegionFlags.DRAW_NO_OUTLINE return style, style if style_str == "outline": - style = default | sublime.DRAW_NO_FILL + style = default | sublime.RegionFlags.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 + return default | sublime.RegionFlags.DRAW_NO_FILL, default | sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.DRAW_STIPPLED_UNDERLINE # noqa: E501 + return default | sublime.RegionFlags.DRAW_NO_FILL, default | sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.DRAW_SOLID_UNDERLINE # noqa: E501 @staticmethod def _style_str_to_flag(style_str: str) -> sublime.RegionFlags | None: - default = sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_NO_FILL | sublime.NO_UNDO + default = sublime.RegionFlags.DRAW_EMPTY_AS_OVERWRITE | sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.NO_UNDO # noqa: E501 # This method could be a dict or lru_cache if style_str == "": - return default | sublime.DRAW_NO_OUTLINE + return default | sublime.RegionFlags.DRAW_NO_OUTLINE if style_str == "box": return default if style_str == "underline": - return default | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE + return default | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.DRAW_SOLID_UNDERLINE if style_str == "stippled": - return default | sublime.DRAW_NO_OUTLINE | sublime.DRAW_STIPPLED_UNDERLINE + return default | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.DRAW_STIPPLED_UNDERLINE if style_str == "squiggly": - return default | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SQUIGGLY_UNDERLINE + return default | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.DRAW_SQUIGGLY_UNDERLINE # default style (includes NO_UNDO) return None diff --git a/plugin/core/views.py b/plugin/core/views.py index 3128654b1..8fc644570 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -56,15 +56,15 @@ MarkdownLangMap = Dict[str, Tuple[Tuple[str, ...], Tuple[str, ...]]] -_baseflags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.NO_UNDO -_multilineflags = sublime.DRAW_NO_FILL | sublime.NO_UNDO +_baseflags = sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.DRAW_EMPTY_AS_OVERWRITE | sublime.RegionFlags.NO_UNDO # noqa: E501 +_multilineflags = sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.NO_UNDO DIAGNOSTIC_SEVERITY: list[tuple[str, str, str, str, sublime.RegionFlags, sublime.RegionFlags]] = [ # Kind CSS class Scope for color Icon resource add_regions flags for single-line diagnostic multi-line diagnostic # noqa: E501 - ("error", "errors", "region.redish markup.error.lsp", "Packages/LSP/icons/error.png", _baseflags | sublime.DRAW_SQUIGGLY_UNDERLINE, _multilineflags), # noqa: E501 - ("warning", "warnings", "region.yellowish markup.warning.lsp", "Packages/LSP/icons/warning.png", _baseflags | sublime.DRAW_SQUIGGLY_UNDERLINE, _multilineflags), # noqa: E501 - ("info", "info", "region.bluish markup.info.lsp", "Packages/LSP/icons/info.png", _baseflags | sublime.DRAW_STIPPLED_UNDERLINE, _multilineflags), # noqa: E501 - ("hint", "hints", "region.bluish markup.info.hint.lsp", "", _baseflags | sublime.DRAW_STIPPLED_UNDERLINE, _multilineflags), # noqa: E501 + ("error", "errors", "region.redish markup.error.lsp", "Packages/LSP/icons/error.png", _baseflags | sublime.RegionFlags.DRAW_SQUIGGLY_UNDERLINE, _multilineflags), # noqa: E501 + ("warning", "warnings", "region.yellowish markup.warning.lsp", "Packages/LSP/icons/warning.png", _baseflags | sublime.RegionFlags.DRAW_SQUIGGLY_UNDERLINE, _multilineflags), # noqa: E501 + ("info", "info", "region.bluish markup.info.lsp", "Packages/LSP/icons/info.png", _baseflags | sublime.RegionFlags.DRAW_STIPPLED_UNDERLINE, _multilineflags), # noqa: E501 + ("hint", "hints", "region.bluish markup.info.hint.lsp", "", _baseflags | sublime.RegionFlags.DRAW_STIPPLED_UNDERLINE, _multilineflags), # noqa: E501 ] @@ -676,7 +676,7 @@ def lsp_color_to_html(color_info: ColorInformation) -> str: def lsp_color_to_phantom(view: sublime.View, color_info: ColorInformation) -> sublime.Phantom: region = range_to_region(color_info['range'], view) - return sublime.Phantom(region, lsp_color_to_html(color_info), sublime.LAYOUT_INLINE) + return sublime.Phantom(region, lsp_color_to_html(color_info), sublime.PhantomLayout.INLINE) def document_color_params(view: sublime.View) -> DocumentColorParams: diff --git a/plugin/core/windows.py b/plugin/core/windows.py index 27cd45786..8480674d3 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -510,7 +510,7 @@ def _update_panel_main_thread(self, characters: str, prephantoms: list[tuple[int for row, col, code, href in prephantoms: point = panel.text_point(row, col) region = sublime.Region(point, point) - phantoms.append(sublime.Phantom(region, f"({make_link(href, code)})", sublime.LAYOUT_INLINE)) + phantoms.append(sublime.Phantom(region, f"({make_link(href, code)})", sublime.PhantomLayout.INLINE)) self._panel_code_phantoms.update(phantoms) # --- Implements WindowConfigChangeListener ------------------------------------------------------------------------ diff --git a/plugin/diagnostics.py b/plugin/diagnostics.py index 22f426b37..6efa3fece 100644 --- a/plugin/diagnostics.py +++ b/plugin/diagnostics.py @@ -24,7 +24,7 @@ def _annotation_region_key(self, severity: DiagnosticSeverity) -> str: return f'lsp_da-{severity}-{self._config_name}' def draw(self, diagnostics: list[tuple[Diagnostic, sublime.Region]]) -> None: - flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO + flags = sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.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. diff --git a/plugin/documents.py b/plugin/documents.py index b944f1323..89bc93b5a 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -474,27 +474,28 @@ def on_close(self) -> None: def on_query_context(self, key: str, operator: int, operand: Any, match_all: bool) -> bool | None: # You can filter key bindings by the precense of a provider, - if key == "lsp.session_with_capability" and operator == sublime.OP_EQUAL and isinstance(operand, str): + if key == "lsp.session_with_capability" and operator == sublime.QueryOperator.EQUAL and \ + isinstance(operand, str): capabilities = [s.strip() for s in operand.split("|")] for capability in capabilities: if any(self.sessions_async(capability)): return True return False # You can filter key bindings by the precense of a specific name of a configuration. - elif key == "lsp.session_with_name" and operator == sublime.OP_EQUAL and isinstance(operand, str): + elif key == "lsp.session_with_name" and operator == sublime.QueryOperator.EQUAL and isinstance(operand, str): return bool(self.session_by_name(operand)) # You can check if there is at least one session attached to this view. elif key in ("lsp.sessions", "setting.lsp_active"): return bool(self._session_views) # Signature Help handling - elif key == "lsp.signature_help_multiple_choices_available" and operator == sublime.OP_EQUAL: + elif key == "lsp.signature_help_multiple_choices_available" and operator == sublime.QueryOperator.EQUAL: return operand == bool( self._sighelp and self._sighelp.has_multiple_signatures() and self.view.is_popup_visible() and not self.view.is_auto_complete_visible() ) - elif key == "lsp.signature_help_available" and operator == sublime.OP_EQUAL: + elif key == "lsp.signature_help_available" and operator == sublime.QueryOperator.EQUAL: return operand == bool(not self.view.is_popup_visible() and self._get_signature_help_session()) - elif key == "lsp.link_available" and operator == sublime.OP_EQUAL: + elif key == "lsp.link_available" and operator == sublime.QueryOperator.EQUAL: position = get_position(self.view) if position is None: return not operand @@ -512,9 +513,9 @@ def on_hover(self, point: int, hover_zone: int) -> None: if self.view.is_popup_visible(): return window = self.view.window() - if hover_zone == sublime.HOVER_TEXT and window and window.settings().get(HOVER_ENABLED_KEY, True): + if hover_zone == sublime.HoverZone.TEXT and window and window.settings().get(HOVER_ENABLED_KEY, True): self.view.run_command("lsp_hover", {"point": point}) - elif hover_zone == sublime.HOVER_GUTTER: + elif hover_zone == sublime.HoverZone.GUTTER: sublime.set_timeout_async(partial(self._on_hover_gutter_async, point)) def _on_hover_gutter_async(self, point: int) -> None: @@ -546,7 +547,7 @@ def _on_hover_gutter_async(self, point: int) -> None: show_lsp_popup( self.view, content, - flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, + flags=sublime.PopupFlags.HIDE_ON_MOUSE_MOVE_AWAY, location=point, on_navigate=lambda href: self._on_navigate(href, point)) @@ -696,7 +697,7 @@ def _show_sighelp_popup(self, content: str, point: int) -> None: show_lsp_popup( self.view, content, - flags=sublime.COOPERATE_WITH_AUTO_COMPLETE, + flags=sublime.PopupFlags.COOPERATE_WITH_AUTO_COMPLETE, location=point, body_id='lsp-signature-help', on_hide=self._on_sighelp_hide, @@ -743,7 +744,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 | sublime.NO_UNDO + flags = sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.NO_UNDO annotations = [] annotation_color = "" if userprefs().show_code_actions == 'bulb': @@ -1023,12 +1024,16 @@ def _format_on_paste_async(self) -> None: for index, region in enumerate(sel): if multi_cursor_paste: pasted_text = split_clipboard_text[index] - pasted_region = self.view.find(pasted_text, region.end(), sublime.REVERSE | sublime.LITERAL) + pasted_region = self.view.find( + pasted_text, region.end(), sublime.FindFlags.REVERSE | sublime.FindFlags.LITERAL) if pasted_region: # Including whitespace may help servers format a range better # More info at https://github.com/sublimelsp/LSP/pull/2311#issuecomment-1688593038 - a = self.view.find_by_class(pasted_region.a, False, - sublime.CLASS_WORD_END | sublime.CLASS_PUNCTUATION_END) + a = self.view.find_by_class( + pasted_region.a, + False, + sublime.PointClassification.WORD_END | sublime.PointClassification.PUNCTUATION_END + ) formatting_region = sublime.Region(a, pasted_region.b) regions_to_format.append(formatting_region) self.purge_changes_async() diff --git a/plugin/goto_diagnostic.py b/plugin/goto_diagnostic.py index 168219ec4..5f3018481 100644 --- a/plugin/goto_diagnostic.py +++ b/plugin/goto_diagnostic.py @@ -166,7 +166,7 @@ def preview(self, value: DocumentUri | None) -> str: session, location = self.first_locations[parsed_uri] scheme, _ = parsed_uri if scheme == "file": - self._preview = open_location(session, location, flags=sublime.TRANSIENT) + self._preview = open_location(session, location, flags=sublime.NewFileFlags.TRANSIENT) return "" def _simple_project_path(self, parsed_uri: ParsedUri) -> str: @@ -246,7 +246,7 @@ def preview(self, value: list | None) -> str | sublime.Html: base_dir = None scheme, path = self.parsed_uri if scheme == "file": - self._preview = open_location(session, self._get_location(diagnostic), flags=sublime.TRANSIENT) + self._preview = open_location(session, self._get_location(diagnostic), flags=sublime.NewFileFlags.TRANSIENT) base_dir = project_base_dir(map(Path, self.window.folders()), Path(path)) return diagnostic_html(session.config, truncate_message(diagnostic), base_dir) @@ -266,7 +266,7 @@ def open_location( ) -> sublime.View: uri, position = get_uri_and_position_from_location(location) file_name = to_encoded_filename(session.config.map_server_uri_to_client_path(uri), position) - return session.window.open_file(file_name, flags=flags | sublime.ENCODED_POSITION, group=group) + return session.window.open_file(file_name, flags=flags | sublime.NewFileFlags.ENCODED_POSITION, group=group) def diagnostic_html(config: ClientConfig, diagnostic: Diagnostic, base_dir: Path | None) -> sublime.Html: diff --git a/plugin/hierarchy.py b/plugin/hierarchy.py index c426462a9..6c36d7efe 100644 --- a/plugin/hierarchy.py +++ b/plugin/hierarchy.py @@ -72,7 +72,7 @@ def get_tree_item(self, element: HierarchyItemWrapper) -> TreeItem: 'targetSelectionRange': selectionRange }, 'session_name': self.session_name, - 'flags': sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT | sublime.CLEAR_TO_RIGHT + 'flags': sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.SEMI_TRANSIENT | sublime.NewFileFlags.CLEAR_TO_RIGHT # noqa: E501 }) path = simple_path(self.weaksession(), item['uri']) return TreeItem( @@ -214,7 +214,7 @@ def open_first(window: sublime.Window, session_name: str, items: list[HierarchyI 'targetSelectionRange': item['selectionRange'] }, 'session_name': session_name, - 'flags': sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT | sublime.CLEAR_TO_RIGHT + 'flags': sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.SEMI_TRANSIENT | sublime.NewFileFlags.CLEAR_TO_RIGHT # noqa: E501 }) diff --git a/plugin/hover.py b/plugin/hover.py index 260347192..703b6f782 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -313,7 +313,7 @@ def _show_hover(self, listener: AbstractViewListener, point: int, only_diagnosti show_lsp_popup( self.view, contents, - flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, + flags=sublime.PopupFlags.HIDE_ON_MOUSE_MOVE_AWAY, location=point, on_navigate=lambda href: self._on_navigate(href, point), on_hide=lambda: self.view.erase_regions(HOVER_HIGHLIGHT_KEY)) diff --git a/plugin/inlay_hint.py b/plugin/inlay_hint.py index 3b633da69..bebffdb91 100644 --- a/plugin/inlay_hint.py +++ b/plugin/inlay_hint.py @@ -90,7 +90,7 @@ def inlay_hint_to_phantom(view: sublime.View, inlay_hint: InlayHint, session: Se region = sublime.Region(position_to_offset(position, view)) phantom_uuid = str(uuid.uuid4()) content = get_inlay_hint_html(view, inlay_hint, session, phantom_uuid) - p = sublime.Phantom(region, content, sublime.LAYOUT_INLINE) + p = sublime.Phantom(region, content, sublime.PhantomLayout.INLINE) setattr(p, 'lsp_uuid', phantom_uuid) return p diff --git a/plugin/locationpicker.py b/plugin/locationpicker.py index 97f99603c..d4ccc01d5 100644 --- a/plugin/locationpicker.py +++ b/plugin/locationpicker.py @@ -22,11 +22,11 @@ def open_location_async( force_group: bool, group: int = -1 ) -> None: - flags = sublime.ENCODED_POSITION + flags = sublime.NewFileFlags.ENCODED_POSITION if force_group: - flags |= sublime.FORCE_GROUP + flags |= sublime.NewFileFlags.FORCE_GROUP if side_by_side: - flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT + flags |= sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.SEMI_TRANSIENT def check_success_async(view: sublime.View | None) -> None: if not view: @@ -96,7 +96,7 @@ def __init__( for location in locations ], on_select=self._select_entry, - flags=sublime.KEEP_OPEN_ON_FOCUS_LOST, + flags=sublime.QuickPanelFlags.KEEP_OPEN_ON_FOCUS_LOST, selected_index=selected_index, on_highlight=self._highlight_entry, placeholder=placeholder @@ -118,7 +118,7 @@ def _select_entry(self, index: int) -> None: # Note: this has to run on the main thread (and not via open_location_async) # otherwise the bevior feels weird. It's the only reason why open_basic_file exists. if uri.startswith(("file:", "res:")): - flags = sublime.ENCODED_POSITION + flags = sublime.NewFileFlags.ENCODED_POSITION if not self._side_by_side: view = open_basic_file(session, uri, position, flags) if not view: @@ -147,16 +147,16 @@ def _highlight_entry(self, index: int) -> None: if not session: return if uri.startswith(("file:", "res:")): - flags = sublime.ENCODED_POSITION | sublime.FORCE_GROUP + flags = sublime.NewFileFlags.ENCODED_POSITION | sublime.NewFileFlags.FORCE_GROUP if self._side_by_side: if self._highlighted_view and self._highlighted_view.is_valid(): # Replacing the MRU is done relative to the current highlighted sheet self._window.focus_view(self._highlighted_view) - flags |= sublime.REPLACE_MRU | sublime.SEMI_TRANSIENT + flags |= sublime.NewFileFlags.REPLACE_MRU | sublime.NewFileFlags.SEMI_TRANSIENT else: - flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT + flags |= sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.SEMI_TRANSIENT else: - flags |= sublime.TRANSIENT + flags |= sublime.NewFileFlags.TRANSIENT view = open_basic_file(session, uri, position, flags, self._window.active_group()) # Don't overwrite self._highlighted_view if resource uri can't preview, so that side-by-side view will still # be closed upon canceling diff --git a/plugin/references.py b/plugin/references.py index ff94a6753..d697e0c9a 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -218,7 +218,12 @@ def _show_references_in_output_panel(self, word: str, session: Session, location }) # highlight all word occurrences regions = panel.find_all(rf"\b{word}\b") - panel.add_regions('ReferenceHighlight', regions, 'comment', flags=sublime.DRAW_NO_FILL | sublime.NO_UNDO) + panel.add_regions( + 'ReferenceHighlight', + regions, + 'comment', + flags=sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.NO_UNDO + ) def _get_relative_path(base_dir: str | None, file_path: str) -> str: diff --git a/plugin/rename.py b/plugin/rename.py index 309d0e5d4..49cdb37ee 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -199,9 +199,9 @@ def _on_rename_result_async(self, session: Session, response: WorkspaceEdit | No total_changes = sum(map(len, changes.values())) message = f"Replace {total_changes} occurrences across {file_count} files?" choice = sublime.yes_no_cancel_dialog(message, "Replace", "Preview", title="Rename") - if choice == sublime.DIALOG_YES: + if choice == sublime.DialogResult.YES: session.apply_parsed_workspace_edits(changes, True) - elif choice == sublime.DIALOG_NO: + elif choice == sublime.DialogResult.NO: self._render_rename_panel(response, changes, total_changes, file_count, session.config.name) def _on_prepare_result(self, pos: int, response: PrepareRenameResult | None) -> None: @@ -313,7 +313,7 @@ def _render_rename_panel( discard=DISCARD_COMMAND_URL ) pm.update_rename_panel_buttons([ - sublime.Phantom(sublime.Region(len(to_render[0]) - 1), BUTTONS_HTML, sublime.LAYOUT_BLOCK) + sublime.Phantom(sublime.Region(len(to_render[0]) - 1), BUTTONS_HTML, sublime.PhantomLayout.BLOCK) ]) diff --git a/plugin/session_view.py b/plugin/session_view.py index 8b69e548f..7395df858 100644 --- a/plugin/session_view.py +++ b/plugin/session_view.py @@ -306,7 +306,7 @@ def present_diagnostics_async(self, is_view_visible: bool) -> None: def _redraw_diagnostics_async(self) -> 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 | sublime.NO_UNDO # noqa: E501 + multiline_flags = None if userprefs().show_multiline_diagnostics_highlights else sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.NO_UNDO # noqa: E501 level = userprefs().show_diagnostics_severity_level for sev in reversed(range(1, len(DIAGNOSTIC_SEVERITY) + 1)): self._draw_diagnostics(sev, level, flags[sev - 1] or DIAGNOSTIC_SEVERITY[sev - 1][4], multiline=False) @@ -320,7 +320,7 @@ def _draw_diagnostics( flags: sublime.RegionFlags, multiline: bool ) -> None: - ICON_FLAGS = sublime.HIDE_ON_MINIMAP | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO + ICON_FLAGS = sublime.RegionFlags.HIDE_ON_MINIMAP | sublime.RegionFlags.DRAW_NO_FILL | sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.NO_UNDO # noqa: E501 key = self.diagnostics_key(severity, multiline) tags = {tag: TagData(f'{key}_tags_{tag}') for tag in DIAGNOSTIC_TAG_VALUES} data = self._session_buffer.diagnostics_data_per_severity.get((severity, multiline)) @@ -342,7 +342,11 @@ def _draw_diagnostics( for data in tags.values(): if data.regions: self.view.add_regions( - data.key, data.regions, data.scope, flags=sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO) + data.key, + data.regions, + data.scope, + flags=sublime.RegionFlags.DRAW_NO_OUTLINE | sublime.RegionFlags.NO_UNDO + ) else: self.view.erase_regions(data.key) diff --git a/plugin/symbols.py b/plugin/symbols.py index cb7b99452..7073d3808 100644 --- a/plugin/symbols.py +++ b/plugin/symbols.py @@ -340,7 +340,7 @@ def run(self, symbol: WorkspaceSymbolValue) -> None: if session: location = symbol.get('location') if location: - session.open_location_async(location, sublime.ENCODED_POSITION) + session.open_location_async(location, sublime.NewFileFlags.ENCODED_POSITION) else: session.send_request( Request.resolveWorkspaceSymbol(symbol['workspaceSymbol']), # type: ignore @@ -355,7 +355,7 @@ def _on_resolved_symbol_async(self, session_name: str, response: WorkspaceSymbol location = cast(Location, response['location']) session = self.session_by_name(session_name) if session: - session.open_location_async(location, sublime.ENCODED_POSITION) + session.open_location_async(location, sublime.NewFileFlags.ENCODED_POSITION) class WorkspaceSymbolsInputHandler(DynamicListInputHandler): diff --git a/stubs/sublime.pyi b/stubs/sublime.pyi index 98ec39de7..3e2a86e6e 100644 --- a/stubs/sublime.pyi +++ b/stubs/sublime.pyi @@ -3032,7 +3032,7 @@ class Phantom: """The `Region` associated with the phantom. The phantom is displayed at the start of the `Region`.""" content: str """The HTML content of the phantom.""" - layout: int + layout: PhantomLayout """How the phantom should be placed relative to the `region`.""" on_navigate: Callable[[str], None] | None """Called when a link in the HTML is clicked. The value of the `href` attribute is passed.""" @@ -3041,7 +3041,7 @@ class Phantom: self, region: Region, content: str, - layout: int, + layout: PhantomLayout, on_navigate: Callable[[str], None] | None = ... ) -> None: ...