From a3dec7c4e2a45df95d85b7376ec0977d8116f675 Mon Sep 17 00:00:00 2001 From: jwortmann Date: Sat, 26 Oct 2024 17:28:34 +0200 Subject: [PATCH 1/8] Don't attach LSP to syntax test files (#2531) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafał Chłodnicki --- plugin/documents.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/documents.py b/plugin/documents.py index b944f1323..492ab43d8 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -56,6 +56,7 @@ from .session_view import SessionView from functools import partial from functools import wraps +from os.path import basename from typing import Any, Callable, Generator, Iterable, TypeVar from typing import cast from typing_extensions import Concatenate, ParamSpec @@ -95,6 +96,10 @@ def is_regular_view(v: sublime.View) -> bool: return False if v.settings().get('is_widget'): return False + # Not a syntax test file. + if (filename := v.file_name()) and basename(filename).startswith('syntax_test_'): + return False + # Not a transient sheet (preview). sheet = v.sheet() if not sheet: return False From 07cfe6fb2f7247d28597a6671a08551d330003d1 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Fri, 25 Oct 2024 14:49:35 +0200 Subject: [PATCH 2/8] Fix mistake in docs --- docs/src/client_configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/client_configuration.md b/docs/src/client_configuration.md index c066a1d3d..14fbbe834 100644 --- a/docs/src/client_configuration.md +++ b/docs/src/client_configuration.md @@ -41,7 +41,7 @@ Below is an example of the `LSP.sublime-settings` file with configurations for t | settings | per-project settings (equivalent to VS Code's Workspace Settings) | | initializationOptions | options to send to the server at startup (rarely used) | | selector | This is _the_ connection between your files and language servers. It's a selector that is matched against the current view's base scope. If the selector matches with the base scope of the the file, the associated language server is started. For more information, see https://www.sublimetext.com/docs/3/selectors.html | -| priority_selector | Used to prioritize a certain language server when choosing which one to query on views with multiple servers active. Certain LSP actions have to pick which server to query and this setting can be used to decide which one to pick based on the current scopes at the cursor location. For example when having both HTML and PHP servers running on a PHP file, this can be used to give priority to the HTML one in HTML blocks and to PHP one otherwise. That would be done by setting "feature_selector" to `text.html` for HTML server and `source.php` to PHP server. Note: when the "feature_selector" is missing, it will be the same as the "document_selector". +| priority_selector | Used to prioritize a certain language server when choosing which one to query on views with multiple servers active. Certain LSP actions have to pick which server to query and this setting can be used to decide which one to pick based on the current scopes at the cursor location. For example when having both HTML and PHP servers running on a PHP file, this can be used to give priority to the HTML one in HTML blocks and to PHP one otherwise. That would be done by setting "priority_selector" to `text.html` for HTML server and `source.php` to PHP server. Note: when the "priority_selector" is missing, it will be the same as the "document_selector". | diagnostics_mode | Set to `"workspace"` (default is `"open_files"`) to ignore diagnostics for files that are not within the project (window) folders. If project has no folders then this option has no effect and diagnostics are shown for all files. If the server supports _pull diagnostics_ (`diagnosticProvider`), this setting also controls whether diagnostics are requested only for open files (`"open_files"`), or for all files in the project folders (`"workspace"`). | | tcp_port | see instructions below | | experimental_capabilities | Turn on experimental capabilities of a language server. This is a dictionary and differs per language server | From c9728ad63b6e5351451d1bc842e97b1c7e9f462d Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Fri, 25 Oct 2024 14:51:54 +0200 Subject: [PATCH 3/8] Update semantic token types in docs --- docs/src/customization.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/customization.md b/docs/src/customization.md index e0f635c6d..ba133ea5c 100644 --- a/docs/src/customization.md +++ b/docs/src/customization.md @@ -123,6 +123,7 @@ Furthermore, it is possible to adjust the colors for semantic tokens by applying | `meta.semantic-token.number` | number | | `meta.semantic-token.regexp` | regexp | | `meta.semantic-token.operator` | operator | +| `meta.semantic-token.decorator` | decorator | By default, LSP will assign scopes based on the [scope naming guideline](https://www.sublimetext.com/docs/scope_naming.html) to each of these token types, but if you define color scheme rules for the scopes specified above, the latter will take precedence. From 986d4375a4b339ac7f414147fb73d1ef74fc2a5c Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Fri, 25 Oct 2024 15:12:24 +0200 Subject: [PATCH 4/8] Extract to private function --- plugin/core/input_handlers.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugin/core/input_handlers.py b/plugin/core/input_handlers.py index f68ece81f..bad0d50b9 100644 --- a/plugin/core/input_handlers.py +++ b/plugin/core/input_handlers.py @@ -111,7 +111,7 @@ def __init__(self, command: sublime_plugin.WindowCommand, args: dict[str, Any]) self.listener: sublime_plugin.TextChangeListener | None = None self.input_view: sublime.View | None = None - def attach_listener(self) -> None: + def _attach_listener(self) -> None: for buffer in sublime._buffers(): # type: ignore view = buffer.primary_view() # This condition to find the input field view might not be sufficient if there is another command palette @@ -129,6 +129,10 @@ def attach_listener(self) -> None: selection.clear() selection.add(len(self.text)) + def _detach_listener(self) -> None: + if self.listener and self.listener.is_attached(): + self.listener.detach() + @final def list_items(self) -> list[sublime.ListInputItem]: if not self.text: # Show initial items when the command was just invoked @@ -149,7 +153,7 @@ def _select_first_row(self) -> None: def initial_text(self) -> str: setattr(self.command, '_text', '') - sublime.set_timeout(self.attach_listener) + sublime.set_timeout(self._attach_listener) return self.text def initial_selection(self) -> list[tuple[int, int]]: @@ -160,12 +164,10 @@ def validate(self, text: str) -> bool: return bool(text) def cancel(self) -> None: - if self.listener and self.listener.is_attached(): - self.listener.detach() + self._detach_listener() def confirm(self, text: str) -> None: - if self.listener and self.listener.is_attached(): - self.listener.detach() + self._detach_listener() def on_modified(self, text: str) -> None: """ Called after changes have been made to the input, with the text of the input field passed as argument. """ From d55ac1d0519ce8b42c64957a8662a4295f0a43d5 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Fri, 25 Oct 2024 15:17:13 +0200 Subject: [PATCH 5/8] Replace literal with enum constant --- plugin/core/tree_view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/tree_view.py b/plugin/core/tree_view.py index 041cb2e4d..7a6a01594 100644 --- a/plugin/core/tree_view.py +++ b/plugin/core/tree_view.py @@ -281,7 +281,7 @@ def new_tree_view_sheet( name: str, data_provider: TreeDataProvider, header: str = "", - flags: int = 0, + flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE, group: int = -1 ) -> TreeViewSheet | None: """ From 79ef72e13ab5a3c78c5e713d3572a5775d78b76f Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Fri, 25 Oct 2024 15:20:23 +0200 Subject: [PATCH 6/8] Remove deprecated abstractproperty decorator --- plugin/core/sessions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 3fd66aae9..038c64d46 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -111,7 +111,6 @@ from .workspace import WorkspaceFolder from abc import ABCMeta from abc import abstractmethod -from abc import abstractproperty from enum import IntEnum, IntFlag from typing import Any, Callable, Generator, List, Protocol, TypeVar from typing import cast @@ -194,7 +193,8 @@ class Manager(metaclass=ABCMeta): # Observers - @abstractproperty + @property + @abstractmethod def window(self) -> sublime.Window: """ Get the window associated with this manager. From 93a54f11e6a20d5ceb214cb33c6de0b41d1b169b Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Fri, 25 Oct 2024 15:25:53 +0200 Subject: [PATCH 7/8] Improve custom IntFlag enum and annotations --- plugin/core/sessions.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 038c64d46..beabce998 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -127,8 +127,9 @@ class ViewStateActions(IntFlag): - Close = 2 - Save = 1 + NONE = 0 + SAVE = 1 + CLOSE = 2 def is_workspace_full_document_diagnostic_report( @@ -1847,17 +1848,17 @@ def _apply_text_edits( apply_text_edits(view, edits, required_view_version=view_version) return view - def _get_view_state_actions(self, uri: DocumentUri, auto_save: str) -> int: + def _get_view_state_actions(self, uri: DocumentUri, auto_save: str) -> ViewStateActions: """ Determine the required actions for a view after applying a WorkspaceEdit, depending on the "refactoring_auto_save" user setting. Returns a bitwise combination of ViewStateActions.Save and ViewStateActions.Close, or 0 if no action is necessary. """ if auto_save == 'never': - return 0 # Never save or close automatically + return ViewStateActions.NONE # Never save or close automatically scheme, filepath = parse_uri(uri) if scheme != 'file': - return 0 # Can't save or close unsafed buffers (and other schemes) without user dialog + return ViewStateActions.NONE # Can't save or close unsafed buffers (and other schemes) without user dialog view = self.window.find_open_file(filepath) if view: is_opened = True @@ -1865,27 +1866,27 @@ def _get_view_state_actions(self, uri: DocumentUri, auto_save: str) -> int: else: is_opened = False is_dirty = False - actions = 0 + actions = ViewStateActions.NONE if auto_save == 'always': - actions |= ViewStateActions.Save # Always save + actions |= ViewStateActions.SAVE # Always save if not is_opened: - actions |= ViewStateActions.Close # Close if file was previously closed + actions |= ViewStateActions.CLOSE # Close if file was previously closed elif auto_save == 'preserve': if not is_dirty: - actions |= ViewStateActions.Save # Only save if file didn't have unsaved changes + actions |= ViewStateActions.SAVE # Only save if file didn't have unsaved changes if not is_opened: - actions |= ViewStateActions.Close # Close if file was previously closed + actions |= ViewStateActions.CLOSE # Close if file was previously closed elif auto_save == 'preserve_opened': if is_opened and not is_dirty: # Only save if file was already open and didn't have unsaved changes, but never close - actions |= ViewStateActions.Save + actions |= ViewStateActions.SAVE return actions - def _set_view_state(self, actions: int, view: sublime.View | None) -> None: + def _set_view_state(self, actions: ViewStateActions, view: sublime.View | None) -> None: if not view: return - should_save = bool(actions & ViewStateActions.Save) - should_close = bool(actions & ViewStateActions.Close) + should_save = bool(actions & ViewStateActions.SAVE) + should_close = bool(actions & ViewStateActions.CLOSE) if should_save and view.is_dirty(): # The save operation must be blocking in case the tab should be closed afterwards view.run_command('save', {'async': not should_close, 'quiet': True}) From c7d622c2890ee33ed66d349d58c69275b40be26d Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Fri, 25 Oct 2024 18:20:18 +0200 Subject: [PATCH 8/8] 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 492ab43d8..9dbf5d366 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -479,27 +479,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 @@ -517,9 +518,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: @@ -551,7 +552,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)) @@ -701,7 +702,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, @@ -748,7 +749,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': @@ -1028,12 +1029,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: ...