diff --git a/boot.py b/boot.py index 647e0ca49..cab6959c6 100644 --- a/boot.py +++ b/boot.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import sublime import sublime_plugin diff --git a/plugin/code_actions.py b/plugin/code_actions.py index 8258c24b2..6a0adc36f 100644 --- a/plugin/code_actions.py +++ b/plugin/code_actions.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.promise import Promise from .core.protocol import CodeAction from .core.protocol import CodeActionKind diff --git a/plugin/code_lens.py b/plugin/code_lens.py index 2dd136d56..38be9e726 100644 --- a/plugin/code_lens.py +++ b/plugin/code_lens.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.constants import CODE_LENS_ENABLED_KEY from .core.protocol import CodeLens from .core.protocol import CodeLensExtended diff --git a/plugin/color.py b/plugin/color.py index 5b3bfcf06..e1151d253 100644 --- a/plugin/color.py +++ b/plugin/color.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.edit import apply_text_edits from .core.protocol import ColorInformation from .core.protocol import ColorPresentation diff --git a/plugin/completion.py b/plugin/completion.py index 235107a7b..6a21c7932 100644 --- a/plugin/completion.py +++ b/plugin/completion.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.constants import COMPLETION_KINDS from .core.edit import apply_text_edits from .core.logging import debug @@ -28,17 +29,17 @@ from .core.views import update_lsp_popup from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, Union from typing import cast -from typing_extensions import TypeGuard +from typing_extensions import TypeAlias, TypeGuard import functools import html import sublime import weakref import webbrowser -SessionName = str -CompletionResponse = Union[List[CompletionItem], CompletionList, None] -ResolvedCompletions = Tuple[Union[CompletionResponse, Error], 'weakref.ref[Session]'] -CompletionsStore = Tuple[List[CompletionItem], CompletionItemDefaults] +SessionName: TypeAlias = str +CompletionResponse: TypeAlias = Union[List[CompletionItem], CompletionList, None] +ResolvedCompletions: TypeAlias = Tuple[Union[CompletionResponse, Error], 'weakref.ref[Session]'] +CompletionsStore: TypeAlias = Tuple[List[CompletionItem], CompletionItemDefaults] def format_completion( @@ -199,7 +200,7 @@ def _create_completion_request_async(self, session: Session) -> Promise[Resolved return promise.then(lambda response: self._on_completion_response_async(response, request_id, weak_session)) def _on_completion_response_async( - self, response: CompletionResponse, request_id: int, weak_session: 'weakref.ref[Session]' + self, response: CompletionResponse, request_id: int, weak_session: weakref.ref[Session] ) -> ResolvedCompletions: self._pending_completion_requests.pop(request_id, None) return (response, weak_session) diff --git a/plugin/configuration.py b/plugin/configuration.py index b6807bcba..4d2925418 100644 --- a/plugin/configuration.py +++ b/plugin/configuration.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.registry import windows from .core.settings import client_configs from .core.windows import WindowManager diff --git a/plugin/core/active_request.py b/plugin/core/active_request.py index ac514bb48..7426174ec 100644 --- a/plugin/core/active_request.py +++ b/plugin/core/active_request.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .sessions import SessionViewProtocol from .progress import ProgressReporter from .progress import ViewProgressReporter diff --git a/plugin/core/collections.py b/plugin/core/collections.py index 1e8f52934..5412dd431 100644 --- a/plugin/core/collections.py +++ b/plugin/core/collections.py @@ -1,6 +1,7 @@ """ Module with additional collections. """ +from __future__ import annotations from copy import deepcopy from typing import Any, Dict, Generator, Optional import sublime diff --git a/plugin/core/configurations.py b/plugin/core/configurations.py index facf61443..bd4b198fa 100644 --- a/plugin/core/configurations.py +++ b/plugin/core/configurations.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .logging import debug from .logging import exception_log from .logging import printf diff --git a/plugin/core/constants.py b/plugin/core/constants.py index f5b3267ef..caed44eda 100644 --- a/plugin/core/constants.py +++ b/plugin/core/constants.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .protocol import CodeActionKind from .protocol import CompletionItemKind from .protocol import DiagnosticSeverity diff --git a/plugin/core/css.py b/plugin/core/css.py index bfc1010a0..8f26b4677 100644 --- a/plugin/core/css.py +++ b/plugin/core/css.py @@ -1,3 +1,4 @@ +from __future__ import annotations from typing import Optional import sublime diff --git a/plugin/core/diagnostics_storage.py b/plugin/core/diagnostics_storage.py index cf59227d1..fd750204e 100644 --- a/plugin/core/diagnostics_storage.py +++ b/plugin/core/diagnostics_storage.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .protocol import Diagnostic, DiagnosticSeverity, DocumentUri from .url import parse_uri from .views import diagnostic_severity diff --git a/plugin/core/edit.py b/plugin/core/edit.py index 8fc135100..eba72aeee 100644 --- a/plugin/core/edit.py +++ b/plugin/core/edit.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .logging import debug from .protocol import Position from .protocol import TextEdit diff --git a/plugin/core/file_watcher.py b/plugin/core/file_watcher.py index c12b3b957..16e912525 100644 --- a/plugin/core/file_watcher.py +++ b/plugin/core/file_watcher.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .protocol import FileChangeType from .protocol import WatchKind from abc import ABCMeta diff --git a/plugin/core/input_handlers.py b/plugin/core/input_handlers.py index d6f900276..4aea200c1 100644 --- a/plugin/core/input_handlers.py +++ b/plugin/core/input_handlers.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .constants import ST_VERSION from abc import ABCMeta from abc import abstractmethod diff --git a/plugin/core/logging.py b/plugin/core/logging.py index d35ef461e..06129acf3 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -1,3 +1,4 @@ +from __future__ import annotations from typing import Any import traceback import inspect diff --git a/plugin/core/message_request_handler.py b/plugin/core/message_request_handler.py index 1d6ccc9a7..ee382211a 100644 --- a/plugin/core/message_request_handler.py +++ b/plugin/core/message_request_handler.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .protocol import MessageType from .protocol import Response from .protocol import ShowMessageRequestParams diff --git a/plugin/core/open.py b/plugin/core/open.py index aa5411dad..f4d944498 100644 --- a/plugin/core/open.py +++ b/plugin/core/open.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .constants import ST_VERSION from .logging import exception_log from .promise import Promise diff --git a/plugin/core/panels.py b/plugin/core/panels.py index e8dbb68ad..0fc0d3dad 100644 --- a/plugin/core/panels.py +++ b/plugin/core/panels.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .types import PANEL_FILE_REGEX from .types import PANEL_LINE_REGEX from typing import Iterable, Optional diff --git a/plugin/core/paths.py b/plugin/core/paths.py index fcf137303..a600f49c8 100644 --- a/plugin/core/paths.py +++ b/plugin/core/paths.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .protocol import DocumentUri from .sessions import Session from .views import parse_uri diff --git a/plugin/core/progress.py b/plugin/core/progress.py index 2bde72416..f1950bec1 100644 --- a/plugin/core/progress.py +++ b/plugin/core/progress.py @@ -1,3 +1,4 @@ +from __future__ import annotations from typing import Optional, Union import sublime diff --git a/plugin/core/promise.py b/plugin/core/promise.py index 6becd251e..a371bf17a 100644 --- a/plugin/core/promise.py +++ b/plugin/core/promise.py @@ -1,3 +1,4 @@ +from __future__ import annotations from typing import Callable, Generic, List, Optional, Protocol, Tuple, TypeVar, Union import functools import threading diff --git a/plugin/core/protocol.py b/plugin/core/protocol.py index 72d72fe14..85a7ae385 100644 --- a/plugin/core/protocol.py +++ b/plugin/core/protocol.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .typing import StrEnum from enum import IntEnum, IntFlag from functools import total_ordering @@ -6036,133 +6037,133 @@ def __init__( self.partial_results = partial_results @classmethod - def initialize(cls, params: InitializeParams) -> 'Request': + def initialize(cls, params: InitializeParams) -> Request: return Request("initialize", params) @classmethod - def complete(cls, params: CompletionParams, view: sublime.View) -> 'Request': + def complete(cls, params: CompletionParams, view: sublime.View) -> Request: return Request("textDocument/completion", params, view) @classmethod - def signatureHelp(cls, params: SignatureHelpParams, view: sublime.View) -> 'Request': + def signatureHelp(cls, params: SignatureHelpParams, view: sublime.View) -> Request: return Request("textDocument/signatureHelp", params, view) @classmethod - def codeAction(cls, params: CodeActionParams, view: sublime.View) -> 'Request': + def codeAction(cls, params: CodeActionParams, view: sublime.View) -> Request: return Request("textDocument/codeAction", params, view) @classmethod - def documentColor(cls, params: DocumentColorParams, view: sublime.View) -> 'Request': + def documentColor(cls, params: DocumentColorParams, view: sublime.View) -> Request: return Request('textDocument/documentColor', params, view) @classmethod - def colorPresentation(cls, params: ColorPresentationParams, view: sublime.View) -> 'Request': + def colorPresentation(cls, params: ColorPresentationParams, view: sublime.View) -> Request: return Request('textDocument/colorPresentation', params, view) @classmethod - def willSaveWaitUntil(cls, params: WillSaveTextDocumentParams, view: sublime.View) -> 'Request': + def willSaveWaitUntil(cls, params: WillSaveTextDocumentParams, view: sublime.View) -> Request: return Request("textDocument/willSaveWaitUntil", params, view) @classmethod - def documentSymbols(cls, params: DocumentSymbolParams, view: sublime.View) -> 'Request': + def documentSymbols(cls, params: DocumentSymbolParams, view: sublime.View) -> Request: return Request("textDocument/documentSymbol", params, view, progress=True) @classmethod - def documentHighlight(cls, params: DocumentHighlightParams, view: sublime.View) -> 'Request': + def documentHighlight(cls, params: DocumentHighlightParams, view: sublime.View) -> Request: return Request("textDocument/documentHighlight", params, view) @classmethod - def documentLink(cls, params: DocumentLinkParams, view: sublime.View) -> 'Request': + def documentLink(cls, params: DocumentLinkParams, view: sublime.View) -> Request: return Request("textDocument/documentLink", params, view) @classmethod - def semanticTokensFull(cls, params: SemanticTokensParams, view: sublime.View) -> 'Request': + def semanticTokensFull(cls, params: SemanticTokensParams, view: sublime.View) -> Request: return Request("textDocument/semanticTokens/full", params, view) @classmethod - def semanticTokensFullDelta(cls, params: SemanticTokensDeltaParams, view: sublime.View) -> 'Request': + def semanticTokensFullDelta(cls, params: SemanticTokensDeltaParams, view: sublime.View) -> Request: return Request("textDocument/semanticTokens/full/delta", params, view) @classmethod - def semanticTokensRange(cls, params: SemanticTokensRangeParams, view: sublime.View) -> 'Request': + def semanticTokensRange(cls, params: SemanticTokensRangeParams, view: sublime.View) -> Request: return Request("textDocument/semanticTokens/range", params, view) @classmethod def prepareCallHierarchy( cls, params: CallHierarchyPrepareParams, view: sublime.View - ) -> 'Request[Union[List[CallHierarchyItem], Error, None]]': + ) -> Request[Union[List[CallHierarchyItem], Error, None]]: return Request("textDocument/prepareCallHierarchy", params, view, progress=True) @classmethod - def incomingCalls(cls, params: CallHierarchyIncomingCallsParams) -> 'Request': + def incomingCalls(cls, params: CallHierarchyIncomingCallsParams) -> Request: return Request("callHierarchy/incomingCalls", params, None) @classmethod - def outgoingCalls(cls, params: CallHierarchyOutgoingCallsParams) -> 'Request': + def outgoingCalls(cls, params: CallHierarchyOutgoingCallsParams) -> Request: return Request("callHierarchy/outgoingCalls", params, None) @classmethod - def prepareTypeHierarchy(cls, params: TypeHierarchyPrepareParams, view: sublime.View) -> 'Request': + def prepareTypeHierarchy(cls, params: TypeHierarchyPrepareParams, view: sublime.View) -> Request: return Request("textDocument/prepareTypeHierarchy", params, view, progress=True) @classmethod - def supertypes(cls, params: TypeHierarchySupertypesParams) -> 'Request': + def supertypes(cls, params: TypeHierarchySupertypesParams) -> Request: return Request("typeHierarchy/supertypes", params, None) @classmethod - def subtypes(cls, params: TypeHierarchySubtypesParams) -> 'Request': + def subtypes(cls, params: TypeHierarchySubtypesParams) -> Request: return Request("typeHierarchy/subtypes", params, None) @classmethod - def resolveCompletionItem(cls, params: CompletionItem, view: sublime.View) -> 'Request': + def resolveCompletionItem(cls, params: CompletionItem, view: sublime.View) -> Request: return Request("completionItem/resolve", params, view) @classmethod - def resolveDocumentLink(cls, params: DocumentLink, view: sublime.View) -> 'Request': + def resolveDocumentLink(cls, params: DocumentLink, view: sublime.View) -> Request: return Request("documentLink/resolve", params, view) @classmethod - def inlayHint(cls, params: InlayHintParams, view: sublime.View) -> 'Request': + def inlayHint(cls, params: InlayHintParams, view: sublime.View) -> Request: return Request('textDocument/inlayHint', params, view) @classmethod - def resolveInlayHint(cls, params: InlayHint, view: sublime.View) -> 'Request': + def resolveInlayHint(cls, params: InlayHint, view: sublime.View) -> Request: return Request('inlayHint/resolve', params, view) @classmethod - def rename(cls, params: RenameParams, view: sublime.View, progress: bool = False) -> 'Request': + def rename(cls, params: RenameParams, view: sublime.View, progress: bool = False) -> Request: return Request('textDocument/rename', params, view, progress) @classmethod - def prepareRename(cls, params: PrepareRenameParams, view: sublime.View, progress: bool = False) -> 'Request': + def prepareRename(cls, params: PrepareRenameParams, view: sublime.View, progress: bool = False) -> Request: return Request('textDocument/prepareRename', params, view, progress) @classmethod - def selectionRange(cls, params: SelectionRangeParams) -> 'Request': + def selectionRange(cls, params: SelectionRangeParams) -> Request: return Request('textDocument/selectionRange', params) @classmethod - def foldingRange(cls, params: FoldingRangeParams, view: sublime.View) -> 'Request': + def foldingRange(cls, params: FoldingRangeParams, view: sublime.View) -> Request: return Request('textDocument/foldingRange', params, view) @classmethod - def workspaceSymbol(cls, params: WorkspaceSymbolParams) -> 'Request': + def workspaceSymbol(cls, params: WorkspaceSymbolParams) -> Request: return Request("workspace/symbol", params, None, progress=True) @classmethod - def resolveWorkspaceSymbol(cls, params: WorkspaceSymbol) -> 'Request': + def resolveWorkspaceSymbol(cls, params: WorkspaceSymbol) -> Request: return Request('workspaceSymbol/resolve', params) @classmethod - def documentDiagnostic(cls, params: DocumentDiagnosticParams, view: sublime.View) -> 'Request': + def documentDiagnostic(cls, params: DocumentDiagnosticParams, view: sublime.View) -> Request: return Request('textDocument/diagnostic', params, view) @classmethod - def workspaceDiagnostic(cls, params: WorkspaceDiagnosticParams) -> 'Request': + def workspaceDiagnostic(cls, params: WorkspaceDiagnosticParams) -> Request: return Request('workspace/diagnostic', params, partial_results=True) @classmethod - def shutdown(cls) -> 'Request': + def shutdown(cls) -> Request: return Request("shutdown") def __repr__(self) -> str: @@ -6187,7 +6188,7 @@ def __init__(self, code: int, message: str, data: Any = None) -> None: self.data = data @classmethod - def from_lsp(cls, params: Any) -> "Error": + def from_lsp(cls, params: Any) -> Error: return Error(params["code"], params["message"], params.get("data")) def to_lsp(self) -> Dict[str, Any]: @@ -6200,7 +6201,7 @@ def __str__(self) -> str: return "{} ({})".format(super().__str__(), self.code) @classmethod - def from_exception(cls, ex: Exception) -> 'Error': + def from_exception(cls, ex: Exception) -> Error: return Error(ErrorCodes.InternalError, str(ex)) @@ -6232,43 +6233,43 @@ def __init__(self, method: str, params: Any = None) -> None: self.params = params @classmethod - def initialized(cls) -> 'Notification': + def initialized(cls) -> Notification: return Notification("initialized", {}) @classmethod - def didOpen(cls, params: DidOpenTextDocumentParams) -> 'Notification': + def didOpen(cls, params: DidOpenTextDocumentParams) -> Notification: return Notification("textDocument/didOpen", params) @classmethod - def didChange(cls, params: DidChangeTextDocumentParams) -> 'Notification': + def didChange(cls, params: DidChangeTextDocumentParams) -> Notification: return Notification("textDocument/didChange", params) @classmethod - def willSave(cls, params: WillSaveTextDocumentParams) -> 'Notification': + def willSave(cls, params: WillSaveTextDocumentParams) -> Notification: return Notification("textDocument/willSave", params) @classmethod - def didSave(cls, params: DidSaveTextDocumentParams) -> 'Notification': + def didSave(cls, params: DidSaveTextDocumentParams) -> Notification: return Notification("textDocument/didSave", params) @classmethod - def didClose(cls, params: DidCloseTextDocumentParams) -> 'Notification': + def didClose(cls, params: DidCloseTextDocumentParams) -> Notification: return Notification("textDocument/didClose", params) @classmethod - def didChangeConfiguration(cls, params: DidChangeConfigurationParams) -> 'Notification': + def didChangeConfiguration(cls, params: DidChangeConfigurationParams) -> Notification: return Notification("workspace/didChangeConfiguration", params) @classmethod - def didChangeWatchedFiles(cls, params: DidChangeWatchedFilesParams) -> 'Notification': + def didChangeWatchedFiles(cls, params: DidChangeWatchedFilesParams) -> Notification: return Notification("workspace/didChangeWatchedFiles", params) @classmethod - def didChangeWorkspaceFolders(cls, params: DidChangeWorkspaceFoldersParams) -> 'Notification': + def didChangeWorkspaceFolders(cls, params: DidChangeWorkspaceFoldersParams) -> Notification: return Notification("workspace/didChangeWorkspaceFolders", params) @classmethod - def exit(cls) -> 'Notification': + def exit(cls) -> Notification: return Notification("exit") def __repr__(self) -> str: @@ -6304,10 +6305,10 @@ def __lt__(self, other: object) -> bool: return (self.row, self.col) < (other.row, other.col) @classmethod - def from_lsp(cls, point: 'Position') -> 'Point': + def from_lsp(cls, point: Position) -> Point: return Point(point['line'], point['character']) - def to_lsp(self) -> 'Position': + def to_lsp(self) -> Position: return { "line": self.row, "character": self.col diff --git a/plugin/core/registry.py b/plugin/core/registry.py index e6ca3a069..1c1284062 100644 --- a/plugin/core/registry.py +++ b/plugin/core/registry.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .protocol import Diagnostic from .protocol import Location from .protocol import LocationLink diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 76bdcaa74..3cf505054 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .collections import DottedDict from .constants import SEMANTIC_TOKENS_MAP from .diagnostics_storage import DiagnosticsStorage @@ -113,7 +114,7 @@ from enum import IntEnum from typing import Any, Callable, Dict, Generator, List, Optional, Protocol, Set, Tuple, Type, TypeVar, Union from typing import cast -from typing_extensions import TypeGuard +from typing_extensions import TypeAlias, TypeGuard from weakref import WeakSet import functools import mdpopups @@ -121,7 +122,7 @@ import sublime import weakref -InitCallback = Callable[['Session', bool], None] +InitCallback: TypeAlias = Callable[['Session', bool], None] T = TypeVar('T') @@ -234,7 +235,7 @@ def on_diagnostics_updated(self) -> None: # Event callbacks @abstractmethod - def on_post_exit_async(self, session: 'Session', exit_code: int, exception: Optional[Exception]) -> None: + def on_post_exit_async(self, session: Session, exit_code: int, exception: Optional[Exception]) -> None: """ The given Session has stopped with the given exit code. """ @@ -689,19 +690,19 @@ class AbstractViewListener(metaclass=ABCMeta): hover_provider_count = 0 @abstractmethod - def session_async(self, capability: str, point: Optional[int] = None) -> Optional['Session']: + def session_async(self, capability: str, point: Optional[int] = None) -> Optional[Session]: raise NotImplementedError() @abstractmethod - def sessions_async(self, capability: Optional[str] = None) -> Generator['Session', None, None]: + def sessions_async(self, capability: Optional[str] = None) -> Generator[Session, None, None]: raise NotImplementedError() @abstractmethod - def session_buffers_async(self, capability: Optional[str] = None) -> Generator['SessionBufferProtocol', None, None]: + def session_buffers_async(self, capability: Optional[str] = None) -> Generator[SessionBufferProtocol, None, None]: raise NotImplementedError() @abstractmethod - def session_views_async(self) -> Generator['SessionViewProtocol', None, None]: + def session_views_async(self) -> Generator[SessionViewProtocol, None, None]: raise NotImplementedError() @abstractmethod @@ -709,18 +710,18 @@ def purge_changes_async(self) -> None: raise NotImplementedError() @abstractmethod - def on_session_initialized_async(self, session: 'Session') -> None: + def on_session_initialized_async(self, session: Session) -> None: raise NotImplementedError() @abstractmethod - def on_session_shutdown_async(self, session: 'Session') -> None: + def on_session_shutdown_async(self, session: Session) -> None: raise NotImplementedError() @abstractmethod def diagnostics_intersecting_region_async( self, region: sublime.Region - ) -> Tuple[List[Tuple['SessionBufferProtocol', List[Diagnostic]]], sublime.Region]: + ) -> Tuple[List[Tuple[SessionBufferProtocol, List[Diagnostic]]], sublime.Region]: raise NotImplementedError() @abstractmethod @@ -728,13 +729,13 @@ def diagnostics_touching_point_async( self, pt: int, max_diagnostic_severity_level: int = DiagnosticSeverity.Hint - ) -> Tuple[List[Tuple['SessionBufferProtocol', List[Diagnostic]]], sublime.Region]: + ) -> Tuple[List[Tuple[SessionBufferProtocol, List[Diagnostic]]], sublime.Region]: raise NotImplementedError() def diagnostics_intersecting_async( self, region_or_point: Union[sublime.Region, int] - ) -> Tuple[List[Tuple['SessionBufferProtocol', List[Diagnostic]]], sublime.Region]: + ) -> Tuple[List[Tuple[SessionBufferProtocol, List[Diagnostic]]], sublime.Region]: if isinstance(region_or_point, int): return self.diagnostics_touching_point_async(region_or_point) elif region_or_point.empty(): @@ -968,7 +969,7 @@ def markdown_language_id_to_st_syntax_map(cls) -> Optional[MarkdownLangMap]: """ return None - def __init__(self, weaksession: 'weakref.ref[Session]') -> None: + def __init__(self, weaksession: weakref.ref[Session]) -> None: """ Constructs a new instance. Your instance is constructed after a response to the initialize request. diff --git a/plugin/core/settings.py b/plugin/core/settings.py index ff1148093..13b5daaff 100644 --- a/plugin/core/settings.py +++ b/plugin/core/settings.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .collections import DottedDict from .logging import debug from .types import ClientConfig, debounced diff --git a/plugin/core/signature_help.py b/plugin/core/signature_help.py index 6f9d42d50..81a05ce05 100644 --- a/plugin/core/signature_help.py +++ b/plugin/core/signature_help.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .logging import debug from .protocol import SignatureHelp from .protocol import SignatureInformation diff --git a/plugin/core/transports.py b/plugin/core/transports.py index d5e06d1f3..b064bc067 100644 --- a/plugin/core/transports.py +++ b/plugin/core/transports.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .logging import exception_log, debug from .types import TCP_CONNECT_TIMEOUT from .types import TransportConfig @@ -281,7 +282,7 @@ def start_subprocess() -> subprocess.Popen: config.name, process, sock, reader, writer, stderr, json_rpc_processor, callback_object) # type: ignore -_subprocesses: 'weakref.WeakSet[subprocess.Popen]' = weakref.WeakSet() +_subprocesses: weakref.WeakSet[subprocess.Popen] = weakref.WeakSet() def kill_all_subprocesses() -> None: diff --git a/plugin/core/tree_view.py b/plugin/core/tree_view.py index d9194076e..484485274 100644 --- a/plugin/core/tree_view.py +++ b/plugin/core/tree_view.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .constants import SublimeKind from .css import css from .promise import Promise diff --git a/plugin/core/types.py b/plugin/core/types.py index a73d72fde..074364ed8 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .collections import DottedDict from .file_watcher import FileWatcherEventType from .logging import debug, set_debug_logging diff --git a/plugin/core/typing.py b/plugin/core/typing.py index be399071a..62024b056 100644 --- a/plugin/core/typing.py +++ b/plugin/core/typing.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sys if sys.version_info >= (3, 11, 0): @@ -42,11 +43,11 @@ def cast(typ, val): # type: ignore def final(func): # type: ignore return func - def _make_type(name: str) -> '_TypeMeta': + def _make_type(name: str) -> _TypeMeta: return _TypeMeta(name, (Type,), {}) # type: ignore class _TypeMeta(type): - def __getitem__(self, args: 'Any') -> 'Any': + def __getitem__(self, args: Any) -> Any: if not isinstance(args, tuple): args = (args,) diff --git a/plugin/core/url.py b/plugin/core/url.py index 951be28ef..fc78c7091 100644 --- a/plugin/core/url.py +++ b/plugin/core/url.py @@ -1,3 +1,4 @@ +from __future__ import annotations from typing import Any, Tuple from urllib.parse import urljoin from urllib.parse import urlparse diff --git a/plugin/core/views.py b/plugin/core/views.py index 64d05700f..6b8baae2e 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .constants import CODE_ACTION_KINDS from .constants import SUBLIME_KIND_SCOPES from .constants import SublimeKind diff --git a/plugin/core/windows.py b/plugin/core/windows.py index e3213249c..52d54dbcc 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -1,3 +1,4 @@ +from __future__ import annotations from ...third_party import WebsocketServer # type: ignore from .configurations import RETRY_COUNT_TIMEDELTA from .configurations import RETRY_MAX_COUNT diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index 0a82077fb..cddfcc092 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .protocol import WorkspaceFolder as LspWorkspaceFolder from .types import diff from .types import matches_pattern diff --git a/plugin/diagnostics.py b/plugin/diagnostics.py index 86fe0772a..6b5a011c4 100644 --- a/plugin/diagnostics.py +++ b/plugin/diagnostics.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.constants import DIAGNOSTIC_KINDS from .core.constants import REGIONS_INITIALIZE_FLAGS from .core.protocol import Diagnostic diff --git a/plugin/document_link.py b/plugin/document_link.py index 60ee64d80..38423e5fb 100644 --- a/plugin/document_link.py +++ b/plugin/document_link.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.logging import debug from .core.open import open_file_uri from .core.open import open_in_browser diff --git a/plugin/documents.py b/plugin/documents.py index 94159946b..6b814ab4d 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .code_actions import actions_manager from .code_actions import CodeActionOrCommand from .code_actions import CodeActionsByConfigName @@ -91,7 +92,7 @@ def previous_non_whitespace_char(view: sublime.View, pt: int) -> str: class TextChangeListener(sublime_plugin.TextChangeListener): - ids_to_listeners: 'WeakValueDictionary[int, TextChangeListener]' = WeakValueDictionary() + ids_to_listeners: WeakValueDictionary[int, TextChangeListener] = WeakValueDictionary() @classmethod def is_applicable(cls, buffer: sublime.Buffer) -> bool: diff --git a/plugin/edit.py b/plugin/edit.py index bcf17ee0a..fecf999d0 100644 --- a/plugin/edit.py +++ b/plugin/edit.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.edit import parse_range from .core.logging import debug from .core.protocol import TextEdit diff --git a/plugin/execute_command.py b/plugin/execute_command.py index 1d8106525..62f0619c3 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.protocol import Error from .core.protocol import ExecuteCommandParams from .core.registry import LspTextCommand diff --git a/plugin/folding_range.py b/plugin/folding_range.py index eca29e957..436b3cba5 100644 --- a/plugin/folding_range.py +++ b/plugin/folding_range.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.protocol import FoldingRange from .core.protocol import FoldingRangeKind from .core.protocol import FoldingRangeParams diff --git a/plugin/formatting.py b/plugin/formatting.py index 6c804c660..1cb44ceea 100644 --- a/plugin/formatting.py +++ b/plugin/formatting.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.collections import DottedDict from .core.edit import apply_text_edits from .core.promise import Promise diff --git a/plugin/goto.py b/plugin/goto.py index 71fbf5642..8e6421865 100644 --- a/plugin/goto.py +++ b/plugin/goto.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.protocol import Location from .core.protocol import LocationLink from .core.protocol import Request diff --git a/plugin/goto_diagnostic.py b/plugin/goto_diagnostic.py index 11d884421..da6f344b5 100644 --- a/plugin/goto_diagnostic.py +++ b/plugin/goto_diagnostic.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.constants import DIAGNOSTIC_KINDS from .core.diagnostics_storage import is_severity_included from .core.diagnostics_storage import ParsedUri diff --git a/plugin/hierarchy.py b/plugin/hierarchy.py index b38ddac62..b8ec69abe 100644 --- a/plugin/hierarchy.py +++ b/plugin/hierarchy.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.constants import SYMBOL_KINDS from .core.paths import simple_path from .core.promise import Promise @@ -41,7 +42,7 @@ class HierarchyDataProvider(TreeDataProvider): def __init__( self, - weaksession: 'weakref.ref[Session]', + weaksession: weakref.ref[Session], request: Callable[..., Request], request_handler: Callable[..., List[HierarchyItemWrapper]], root_elements: List[HierarchyItemWrapper] @@ -84,7 +85,7 @@ def get_tree_item(self, element: HierarchyItemWrapper) -> TreeItem: def make_data_provider( - weaksession: 'weakref.ref[Session]', sheet_name: str, direction: int, response: List[HierarchyItemWrapper] + weaksession: weakref.ref[Session], sheet_name: str, direction: int, response: List[HierarchyItemWrapper] ) -> HierarchyDataProvider: if sheet_name == "Call Hierarchy": request = Request.incomingCalls if direction == 1 else Request.outgoingCalls @@ -166,7 +167,7 @@ def run(self, edit: sublime.Edit, event: Optional[dict] = None, point: Optional[ self.request(params, self.view), partial(self._handle_response_async, weakref.ref(session))) def _handle_response_async( - self, weaksession: 'weakref.ref[Session]', response: Optional[List[HierarchyItem]] + self, weaksession: weakref.ref[Session], response: Optional[List[HierarchyItem]] ) -> None: if not self._window or not self._window.is_valid(): return diff --git a/plugin/hover.py b/plugin/hover.py index 946ecc70b..2b647bd78 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .code_actions import actions_manager from .code_actions import CodeActionOrCommand from .code_actions import CodeActionsByConfigName diff --git a/plugin/inlay_hint.py b/plugin/inlay_hint.py index edaa8bec2..c302d01b0 100644 --- a/plugin/inlay_hint.py +++ b/plugin/inlay_hint.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.css import css from .core.edit import apply_text_edits from .core.protocol import InlayHint diff --git a/plugin/locationpicker.py b/plugin/locationpicker.py index e2cc83aac..7fff94d4c 100644 --- a/plugin/locationpicker.py +++ b/plugin/locationpicker.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.constants import SublimeKind from .core.logging import debug from .core.protocol import DocumentUri diff --git a/plugin/panels.py b/plugin/panels.py index 43d6b3fbc..834f862fc 100644 --- a/plugin/panels.py +++ b/plugin/panels.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.panels import LOG_LINES_LIMIT_SETTING_NAME from .core.panels import PanelName from .core.registry import windows diff --git a/plugin/references.py b/plugin/references.py index 621653927..6590b9114 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.protocol import Location from .core.protocol import Point from .core.protocol import Request diff --git a/plugin/rename.py b/plugin/rename.py index 66514b910..1ab50322b 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.edit import parse_range from .core.edit import parse_workspace_edit from .core.edit import WorkspaceChanges diff --git a/plugin/save_command.py b/plugin/save_command.py index 44633ec47..7833f0f7a 100644 --- a/plugin/save_command.py +++ b/plugin/save_command.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.registry import LspTextCommand from .core.settings import userprefs from abc import ABCMeta, abstractmethod diff --git a/plugin/selection_range.py b/plugin/selection_range.py index 9da8ab4b7..9d00171b3 100644 --- a/plugin/selection_range.py +++ b/plugin/selection_range.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.protocol import Request from .core.protocol import SelectionRange from .core.registry import get_position diff --git a/plugin/semantic_highlighting.py b/plugin/semantic_highlighting.py index 9f3ad4dae..6aa0a31b8 100644 --- a/plugin/semantic_highlighting.py +++ b/plugin/semantic_highlighting.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.registry import LspTextCommand from typing import Any, List, Tuple from typing import cast diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index 45babed8a..321cea137 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.constants import DOCUMENT_LINK_FLAGS from .core.constants import SEMANTIC_TOKEN_FLAGS from .core.protocol import ColorInformation diff --git a/plugin/session_view.py b/plugin/session_view.py index 6b6619453..45c7bf75b 100644 --- a/plugin/session_view.py +++ b/plugin/session_view.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .code_lens import CodeLensView from .code_lens import LspToggleCodeLensesCommand from .core.active_request import ActiveRequest @@ -50,7 +51,7 @@ class SessionView: TRIGGER_CHARACTERS_KEY = "completionProvider.triggerCharacters" CODE_ACTIONS_KEY = "lsp_code_action" - _session_buffers: 'WeakValueDictionary[Tuple[int, int], SessionBuffer]' = WeakValueDictionary() + _session_buffers: WeakValueDictionary[Tuple[int, int], SessionBuffer] = WeakValueDictionary() def __init__(self, listener: AbstractViewListener, session: Session, uri: DocumentUri) -> None: self._view = listener.view @@ -114,7 +115,7 @@ def view(self) -> sublime.View: return self._view @property - def listener(self) -> 'ref[AbstractViewListener]': + def listener(self) -> ref[AbstractViewListener]: return self._listener @property diff --git a/plugin/symbols.py b/plugin/symbols.py index 51d195064..6948e9b37 100644 --- a/plugin/symbols.py +++ b/plugin/symbols.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.constants import SYMBOL_KINDS from .core.input_handlers import DynamicListInputHandler from .core.input_handlers import PreselectedListInputHandler diff --git a/plugin/tooling.py b/plugin/tooling.py index 2cced21cf..f03d680a0 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -1,3 +1,4 @@ +from __future__ import annotations from .core.css import css from .core.logging import debug from .core.registry import windows diff --git a/tests/server.py b/tests/server.py index 9db43a69d..eb55e41e5 100644 --- a/tests/server.py +++ b/tests/server.py @@ -20,6 +20,7 @@ TODO: Untested on Windows. """ +from __future__ import annotations from argparse import ArgumentParser from enum import IntEnum from typing import Any, Callable, Dict, List, Optional, Tuple, Union, Iterable, Awaitable diff --git a/tests/setup.py b/tests/setup.py index b3731ab3a..4c57a7855 100644 --- a/tests/setup.py +++ b/tests/setup.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.promise import Promise from LSP.plugin.core.logging import debug from LSP.plugin.core.protocol import Notification, Request diff --git a/tests/test_code_actions.py b/tests/test_code_actions.py index 4315c39c3..6ca704895 100644 --- a/tests/test_code_actions.py +++ b/tests/test_code_actions.py @@ -1,3 +1,4 @@ +from __future__ import annotations from copy import deepcopy from LSP.plugin.code_actions import get_matching_on_save_kinds, kinds_include_kind from LSP.plugin.core.protocol import Point, Range diff --git a/tests/test_collections.py b/tests/test_collections.py index 0bd6722bf..327e3fb1c 100644 --- a/tests/test_collections.py +++ b/tests/test_collections.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.collections import DottedDict from typing import Any from unittest import TestCase diff --git a/tests/test_completion.py b/tests/test_completion.py index 1c4f27068..0f595311e 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -1,3 +1,4 @@ +from __future__ import annotations from copy import deepcopy from LSP.plugin.completion import format_completion from LSP.plugin.completion import completion_with_defaults diff --git a/tests/test_configs.py b/tests/test_configs.py index b3cc51e28..3cdade0b2 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -1,3 +1,4 @@ +from __future__ import annotations import sublime from LSP.plugin.core.settings import read_client_config, update_client_config from LSP.plugin.core.views import get_uri_and_position_from_location diff --git a/tests/test_configurations.py b/tests/test_configurations.py index 533c12229..300e01aa5 100644 --- a/tests/test_configurations.py +++ b/tests/test_configurations.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.configurations import WindowConfigManager from test_mocks import DISABLED_CONFIG from test_mocks import TEST_CONFIG diff --git a/tests/test_documents.py b/tests/test_documents.py index 25bcfdd1b..f87be7971 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.logging import debug from LSP.plugin.core.protocol import Request from LSP.plugin.core.registry import windows @@ -125,7 +126,7 @@ def handler1(params: Any) -> None: def handler2(params: Any) -> None: promise2.fulfill(params) - def error_handler(params: 'Any') -> None: + def error_handler(params: Any) -> None: debug("Got error:", params, "awaiting timeout :(") self.session1.send_request(Request("$test/getReceived", {"method": method}), handler1, error_handler) diff --git a/tests/test_edit.py b/tests/test_edit.py index 6d3037ed2..9607ecdfe 100644 --- a/tests/test_edit.py +++ b/tests/test_edit.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin import apply_text_edits from LSP.plugin.core.edit import parse_workspace_edit from LSP.plugin.core.protocol import TextDocumentEdit, TextEdit, WorkspaceEdit diff --git a/tests/test_file_watcher.py b/tests/test_file_watcher.py index db16d9a74..81f525c41 100644 --- a/tests/test_file_watcher.py +++ b/tests/test_file_watcher.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin import FileWatcher from LSP.plugin import FileWatcherEvent from LSP.plugin import FileWatcherEventType diff --git a/tests/test_message_request_handler.py b/tests/test_message_request_handler.py index 1660c2527..4e0e1d52f 100644 --- a/tests/test_message_request_handler.py +++ b/tests/test_message_request_handler.py @@ -1,7 +1,8 @@ -import unittest -from test_mocks import MockSession +from __future__ import annotations from LSP.plugin.core.message_request_handler import MessageRequestHandler +from test_mocks import MockSession import sublime +import unittest class MessageRequestHandlerTest(unittest.TestCase): diff --git a/tests/test_mocks.py b/tests/test_mocks.py index 629ad6db5..f155d5315 100644 --- a/tests/test_mocks.py +++ b/tests/test_mocks.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.logging import debug from LSP.plugin.core.protocol import Notification from LSP.plugin.core.protocol import Request diff --git a/tests/test_protocol.py b/tests/test_protocol.py index 32b6ce538..6b0d5c36c 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.protocol import Point, Position, Range, Request, Notification from LSP.plugin.core.transports import JsonRpcProcessor import unittest diff --git a/tests/test_rename_panel.py b/tests/test_rename_panel.py index a9fd78a7a..e647a410e 100644 --- a/tests/test_rename_panel.py +++ b/tests/test_rename_panel.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.rename import utf16_to_code_points import unittest diff --git a/tests/test_server_notifications.py b/tests/test_server_notifications.py index aabbf82aa..587e440ec 100644 --- a/tests/test_server_notifications.py +++ b/tests/test_server_notifications.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.protocol import DiagnosticSeverity from LSP.plugin.core.protocol import DiagnosticTag from LSP.plugin.core.protocol import PublishDiagnosticsParams diff --git a/tests/test_server_panel_circular.py b/tests/test_server_panel_circular.py index d4ca28415..65d2fc04b 100644 --- a/tests/test_server_panel_circular.py +++ b/tests/test_server_panel_circular.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.panels import MAX_LOG_LINES_LIMIT_ON from LSP.plugin.core.panels import PanelName from LSP.plugin.core.registry import windows diff --git a/tests/test_server_requests.py b/tests/test_server_requests.py index 1139f4fe7..3e24d555e 100644 --- a/tests/test_server_requests.py +++ b/tests/test_server_requests.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.protocol import ErrorCodes from LSP.plugin.core.protocol import TextDocumentSyncKind from LSP.plugin.core.sessions import SessionBufferProtocol diff --git a/tests/test_session.py b/tests/test_session.py index 58f02f377..86c42155d 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.collections import DottedDict from LSP.plugin.core.protocol import Diagnostic from LSP.plugin.core.protocol import DocumentUri diff --git a/tests/test_signature_help.py b/tests/test_signature_help.py index 8de8d43f6..5c00275c6 100644 --- a/tests/test_signature_help.py +++ b/tests/test_signature_help.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.protocol import SignatureHelp from LSP.plugin.core.signature_help import SigHelp import sublime diff --git a/tests/test_single_document.py b/tests/test_single_document.py index 673f1842f..5b5e32028 100644 --- a/tests/test_single_document.py +++ b/tests/test_single_document.py @@ -1,3 +1,4 @@ +from __future__ import annotations from copy import deepcopy from LSP.plugin import apply_text_edits, Request from LSP.plugin.core.protocol import UINT_MAX diff --git a/tests/test_types.py b/tests/test_types.py index ac044beb5..35dc30fd0 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.types import diff from LSP.plugin.core.types import basescope2languageid from LSP.plugin.core.types import DocumentSelector diff --git a/tests/test_url.py b/tests/test_url.py index 31a06556f..bf5acaaac 100644 --- a/tests/test_url.py +++ b/tests/test_url.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.url import filename_to_uri from LSP.plugin.core.url import parse_uri from LSP.plugin.core.url import view_to_uri diff --git a/tests/test_views.py b/tests/test_views.py index 5302ecd60..b5f07ddc4 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,3 +1,4 @@ +from __future__ import annotations from copy import deepcopy from LSP.plugin.core.protocol import CodeActionKind from LSP.plugin.core.protocol import Diagnostic diff --git a/tests/test_workspace.py b/tests/test_workspace.py index 3d73191b7..ce9e89da6 100644 --- a/tests/test_workspace.py +++ b/tests/test_workspace.py @@ -1,3 +1,4 @@ +from __future__ import annotations from LSP.plugin.core.workspace import sorted_workspace_folders, is_subpath_of, WorkspaceFolder import os import unittest