From b9dbf51420d7da042ba68ce1355a9f6b50e891ef Mon Sep 17 00:00:00 2001 From: Daniel Biehl Date: Fri, 26 Jan 2024 22:49:46 +0100 Subject: [PATCH] style: reformat code with new black stable style 2024 --- .../core/src/robotcode/core/concurrent.py | 21 +- .../src/robotcode/core/documents_manager.py | 27 +- .../core/src/robotcode/core/filewatcher.py | 9 +- packages/core/src/robotcode/core/lsp/types.py | 6 +- .../core/src/robotcode/core/text_document.py | 6 +- packages/core/src/robotcode/core/uri.py | 6 +- .../src/robotcode/core/utils/dataclasses.py | 10 +- .../src/robotcode/core/utils/glob_path.py | 6 +- .../core/src/robotcode/core/utils/logging.py | 10 +- .../src/robotcode/debugger/debugger.py | 3 +- .../src/robotcode/debugger/launcher/client.py | 3 +- .../src/robotcode/debugger/launcher/server.py | 10 +- .../src/robotcode/jsonrpc2/protocol.py | 15 +- .../jsonrpc2/src/robotcode/jsonrpc2/server.py | 13 +- .../common/parts/code_action.py | 6 +- .../language_server/common/parts/code_lens.py | 6 +- .../common/parts/completion.py | 6 +- .../common/parts/declaration.py | 3 +- .../common/parts/definition.py | 3 +- .../common/parts/diagnostics.py | 33 +-- .../common/parts/document_highlight.py | 3 +- .../common/parts/document_symbols.py | 3 +- .../language_server/common/parts/documents.py | 20 +- .../common/parts/formatting.py | 6 +- .../language_server/common/parts/hover.py | 3 +- .../common/parts/implementation.py | 3 +- .../common/parts/inlay_hint.py | 6 +- .../common/parts/inline_value.py | 3 +- .../common/parts/linked_editing_ranges.py | 3 +- .../common/parts/references.py | 3 +- .../language_server/common/parts/rename.py | 6 +- .../common/parts/selection_range.py | 3 +- .../common/parts/semantic_tokens.py | 31 ++- .../common/parts/signature_help.py | 3 +- .../language_server/common/parts/window.py | 16 +- .../language_server/common/parts/workspace.py | 24 +- .../parts/code_action_documentation.py | 10 +- .../parts/code_action_refactor.py | 86 +++--- .../robotframework/parts/completion.py | 182 +++++++------ .../robotframework/parts/documents_cache.py | 6 +- .../robotframework/parts/goto.py | 6 +- .../robotframework/parts/hover.py | 18 +- .../robotframework/parts/references.py | 27 +- .../robotframework/parts/rename.py | 60 +++-- .../parts/robocop_diagnostics.py | 20 +- .../robotframework/parts/robot_workspace.py | 8 +- .../robotframework/parts/semantic_tokens.py | 23 +- .../robotframework/parts/signature_help.py | 14 +- .../robotframework/protocol.py | 3 +- .../plugin/src/robotcode/plugin/__init__.py | 4 +- .../diagnostics/document_cache_helper.py | 9 +- .../robot/diagnostics/imports_manager.py | 28 +- .../robot/diagnostics/library_doc.py | 116 +++++---- .../robotcode/robot/diagnostics/namespace.py | 246 ++++++++++-------- .../robot/diagnostics/namespace_analyzer.py | 4 +- .../robot/utils/markdownformatter.py | 12 +- .../robot/src/robotcode/robot/utils/stubs.py | 6 +- .../robotcode/runner/cli/discover/discover.py | 24 +- .../runner/src/robotcode/runner/cli/robot.py | 10 +- .../test_code_action_show_documentation.py | 20 +- .../parts/test_document_symbols.py | 14 +- .../robotframework/parts/test_references.py | 14 +- .../parts/test_signature_help.py | 34 +-- 63 files changed, 678 insertions(+), 664 deletions(-) diff --git a/packages/core/src/robotcode/core/concurrent.py b/packages/core/src/robotcode/core/concurrent.py index c743d3333..8a73dd363 100644 --- a/packages/core/src/robotcode/core/concurrent.py +++ b/packages/core/src/robotcode/core/concurrent.py @@ -23,22 +23,17 @@ class Lockable(Protocol): - def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: - ... + def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ... - def release(self) -> None: - ... + def release(self) -> None: ... - def __enter__(self) -> bool: - ... + def __enter__(self) -> bool: ... def __exit__( self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] - ) -> None: - ... + ) -> None: ... - def __str__(self) -> str: - ... + def __str__(self) -> str: ... class LockBase: @@ -130,13 +125,11 @@ def add_done_callback(self, fn: Callable[["Task[Any]"], Any]) -> None: @overload -def threaded_task(__func: _F) -> _F: - ... +def threaded_task(__func: _F) -> _F: ... @overload -def threaded_task(*, enabled: bool = True) -> Callable[[_F], _F]: - ... +def threaded_task(*, enabled: bool = True) -> Callable[[_F], _F]: ... def threaded_task(__func: _F = None, *, enabled: bool = True) -> Callable[[_F], _F]: diff --git a/packages/core/src/robotcode/core/documents_manager.py b/packages/core/src/robotcode/core/documents_manager.py index fe8e1424b..56f6f4bdd 100644 --- a/packages/core/src/robotcode/core/documents_manager.py +++ b/packages/core/src/robotcode/core/documents_manager.py @@ -96,32 +96,25 @@ def get_or_open_document( raise CantReadDocumentError(f"Error reading document '{path}': {e!s}") from e @event - def on_read_document_text(sender, uri: Uri) -> Optional[str]: - ... + def on_read_document_text(sender, uri: Uri) -> Optional[str]: ... @event - def did_create_uri(sender, uri: DocumentUri) -> None: - ... + def did_create_uri(sender, uri: DocumentUri) -> None: ... @event - def did_create(sender, document: TextDocument) -> None: - ... + def did_create(sender, document: TextDocument) -> None: ... @event - def did_open(sender, document: TextDocument) -> None: - ... + def did_open(sender, document: TextDocument) -> None: ... @event - def did_close(sender, document: TextDocument, full_close: bool) -> None: - ... + def did_close(sender, document: TextDocument, full_close: bool) -> None: ... @event - def did_change(sender, document: TextDocument) -> None: - ... + def did_change(sender, document: TextDocument) -> None: ... @event - def did_save(sender, document: TextDocument) -> None: - ... + def did_save(sender, document: TextDocument) -> None: ... def get(self, _uri: Union[DocumentUri, Uri]) -> Optional[TextDocument]: with self._lock: @@ -137,15 +130,13 @@ def __iter__(self) -> Iterator[DocumentUri]: return self._documents.__iter__() @event - def on_document_cache_invalidate(sender, document: TextDocument) -> None: - ... + def on_document_cache_invalidate(sender, document: TextDocument) -> None: ... def _on_document_cache_invalidate(self, sender: TextDocument) -> None: self.on_document_cache_invalidate(self, sender) @event - def on_document_cache_invalidated(sender, document: TextDocument) -> None: - ... + def on_document_cache_invalidated(sender, document: TextDocument) -> None: ... def _on_document_cache_invalidated(self, sender: TextDocument) -> None: self.on_document_cache_invalidated(self, sender) diff --git a/packages/core/src/robotcode/core/filewatcher.py b/packages/core/src/robotcode/core/filewatcher.py index 04f8be9cc..75db13659 100644 --- a/packages/core/src/robotcode/core/filewatcher.py +++ b/packages/core/src/robotcode/core/filewatcher.py @@ -25,8 +25,7 @@ def __init__( self.finalizer: Any = None @event - def child_callbacks(sender, changes: List[FileEvent]) -> None: - ... + def child_callbacks(sender, changes: List[FileEvent]) -> None: ... def call_childrens(self, sender: Any, changes: List[FileEvent]) -> None: self.child_callbacks(sender, changes) @@ -52,12 +51,10 @@ def add_file_watchers( self, callback: Callable[[Any, List[FileEvent]], None], watchers: List[Union[FileWatcher, str, Tuple[str, Optional[WatchKind]]]], - ) -> FileWatcherEntry: - ... + ) -> FileWatcherEntry: ... @abstractmethod - def remove_file_watcher_entry(self, entry: FileWatcherEntry) -> None: - ... + def remove_file_watcher_entry(self, entry: FileWatcherEntry) -> None: ... class FileWatcherManagerDummy(FileWatcherManagerBase): diff --git a/packages/core/src/robotcode/core/lsp/types.py b/packages/core/src/robotcode/core/lsp/types.py index fba707ed9..4d03cb216 100644 --- a/packages/core/src/robotcode/core/lsp/types.py +++ b/packages/core/src/robotcode/core/lsp/types.py @@ -6405,9 +6405,9 @@ class SignatureHelpClientCapabilitiesSignatureInformationType(CamelSnakeMixin): """Client supports the following content formats for the documentation property. The order describes the preferred format of the client.""" - parameter_information: Optional[ - SignatureHelpClientCapabilitiesSignatureInformationTypeParameterInformationType - ] = None + parameter_information: Optional[SignatureHelpClientCapabilitiesSignatureInformationTypeParameterInformationType] = ( + None + ) """Client capabilities specific to parameter information.""" active_parameter_support: Optional[bool] = None diff --git a/packages/core/src/robotcode/core/text_document.py b/packages/core/src/robotcode/core/text_document.py index 0b3575196..8d75d1c7f 100644 --- a/packages/core/src/robotcode/core/text_document.py +++ b/packages/core/src/robotcode/core/text_document.py @@ -209,12 +209,10 @@ def get_lines(self) -> List[str]: return self._lines @event - def cache_invalidate(sender) -> None: - ... + def cache_invalidate(sender) -> None: ... @event - def cache_invalidated(sender) -> None: - ... + def cache_invalidated(sender) -> None: ... def _invalidate_cache(self) -> None: self.cache_invalidate(self) diff --git a/packages/core/src/robotcode/core/uri.py b/packages/core/src/robotcode/core/uri.py index e0cd5c6e5..b89bd1638 100644 --- a/packages/core/src/robotcode/core/uri.py +++ b/packages/core/src/robotcode/core/uri.py @@ -47,8 +47,7 @@ class Uri(Mapping[str, str]): _parts: _Parts @overload - def __init__(self, uri_str: str): - ... + def __init__(self, uri_str: str): ... @overload def __init__( @@ -60,8 +59,7 @@ def __init__( params: Optional[str] = None, query: Optional[str] = None, fragment: Optional[str] = None, - ): - ... + ): ... def __init__( self, diff --git a/packages/core/src/robotcode/core/utils/dataclasses.py b/packages/core/src/robotcode/core/utils/dataclasses.py index 0a548afb9..e988ef614 100644 --- a/packages/core/src/robotcode/core/utils/dataclasses.py +++ b/packages/core/src/robotcode/core/utils/dataclasses.py @@ -482,9 +482,7 @@ def from_dict( ( (getattr(e, "__name__", None) or str(e) if e is not type(None) else "None") if _get_origin_cached(e) is not Literal - else repr(e).replace("typing.", "") - if e is not None - else "None" + else repr(e).replace("typing.", "") if e is not None else "None" ) for e in types ) @@ -521,9 +519,9 @@ def _handle_dataclass(value: Any, remove_defaults: bool, encode: bool) -> Dict[s fields = dataclasses.fields(t) __dataclasses_cache[t] = fields return { - encode_case_for_field_name(t, f) - if encode - else f.name: _as_dict_inner(getattr(value, f.name), remove_defaults, encode) + encode_case_for_field_name(t, f) if encode else f.name: _as_dict_inner( + getattr(value, f.name), remove_defaults, encode + ) for f in fields if not remove_defaults or getattr(value, f.name) != f.default } diff --git a/packages/core/src/robotcode/core/utils/glob_path.py b/packages/core/src/robotcode/core/utils/glob_path.py index f2669719f..6a48ea4f4 100644 --- a/packages/core/src/robotcode/core/utils/glob_path.py +++ b/packages/core/src/robotcode/core/utils/glob_path.py @@ -142,9 +142,9 @@ def iter_files( yield from _iter_files_recursive_re( path=path, patterns=[] if patterns is None else [p if isinstance(p, Pattern) else Pattern(p) for p in patterns], - ignore_patterns=[] - if ignore_patterns is None - else [p if isinstance(p, Pattern) else Pattern(p) for p in ignore_patterns], + ignore_patterns=( + [] if ignore_patterns is None else [p if isinstance(p, Pattern) else Pattern(p) for p in ignore_patterns] + ), include_hidden=include_hidden, absolute=absolute, _base_path=path, diff --git a/packages/core/src/robotcode/core/utils/logging.py b/packages/core/src/robotcode/core/utils/logging.py index 96e24e8b0..26b0f0274 100644 --- a/packages/core/src/robotcode/core/utils/logging.py +++ b/packages/core/src/robotcode/core/utils/logging.py @@ -145,9 +145,7 @@ def __init_logger(self) -> LoggingDescriptor: else ( ("" if self.__owner is None else self.__owner.__module__ + "." + self.__owner.__qualname__) if self.__owner is not None - else get_unwrapped_func(self.__func).__module__ - if self.__func is not None - else "" + else get_unwrapped_func(self.__func).__module__ if self.__func is not None else "" ) + self.__postfix ) @@ -363,8 +361,7 @@ def set_call_tracing_default_level(cls, level: int) -> None: cls._call_tracing_default_level = level @overload - def call(self, _func: _F) -> _F: - ... + def call(self, _func: _F) -> _F: ... @overload def call( @@ -377,8 +374,7 @@ def call( exiting: bool = False, exception: bool = False, timed: bool = False, - ) -> Callable[[_F], _F]: - ... + ) -> Callable[[_F], _F]: ... def call( self, diff --git a/packages/debugger/src/robotcode/debugger/debugger.py b/packages/debugger/src/robotcode/debugger/debugger.py index 06e7f2e55..433d1ff6d 100644 --- a/packages/debugger/src/robotcode/debugger/debugger.py +++ b/packages/debugger/src/robotcode/debugger/debugger.py @@ -504,8 +504,7 @@ def step_out(self, thread_id: int, granularity: Optional[SteppingGranularity] = self.condition.notify_all() @event - def send_event(sender: Any, event: Event) -> None: - ... + def send_event(sender: Any, event: Event) -> None: ... def set_breakpoints( self, diff --git a/packages/debugger/src/robotcode/debugger/launcher/client.py b/packages/debugger/src/robotcode/debugger/launcher/client.py index 3763f1be3..958fad1a8 100644 --- a/packages/debugger/src/robotcode/debugger/launcher/client.py +++ b/packages/debugger/src/robotcode/debugger/launcher/client.py @@ -52,8 +52,7 @@ def __init__( self._transport: Optional[asyncio.BaseTransport] = None @event - def on_closed(sender) -> None: - ... + def on_closed(sender) -> None: ... @_logger.call def close(self) -> None: diff --git a/packages/debugger/src/robotcode/debugger/launcher/server.py b/packages/debugger/src/robotcode/debugger/launcher/server.py index 40b68d838..6fe4d81cf 100644 --- a/packages/debugger/src/robotcode/debugger/launcher/server.py +++ b/packages/debugger/src/robotcode/debugger/launcher/server.py @@ -283,11 +283,11 @@ async def _launch( cwd=cwd, args=[*robotcode_run_args, *run_args], env=env, - kind=RunInTerminalKind.INTEGRATED - if console == "integratedTerminal" - else RunInTerminalKind.EXTERNAL - if console == "externalTerminal" - else None, + kind=( + RunInTerminalKind.INTEGRATED + if console == "integratedTerminal" + else RunInTerminalKind.EXTERNAL if console == "externalTerminal" else None + ), title=name, ) ), diff --git a/packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py b/packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py index 04ee8f37f..338144e75 100644 --- a/packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py +++ b/packages/jsonrpc2/src/robotcode/jsonrpc2/protocol.py @@ -168,8 +168,7 @@ class RpcMethod(Protocol): @overload -def rpc_method(_func: _F) -> _F: - ... +def rpc_method(_func: _F) -> _F: ... @overload @@ -179,8 +178,7 @@ def rpc_method( param_type: Optional[Type[Any]] = None, cancelable: bool = True, threaded: bool = False, -) -> Callable[[_F], _F]: - ... +) -> Callable[[_F], _F]: ... def rpc_method( @@ -389,12 +387,10 @@ def loop(self) -> Optional[asyncio.AbstractEventLoop]: return self._loop @event - def on_connection_made(sender, transport: asyncio.BaseTransport) -> None: - ... + def on_connection_made(sender, transport: asyncio.BaseTransport) -> None: ... @event - def on_connection_lost(sender, exc: Optional[BaseException]) -> None: - ... + def on_connection_lost(sender, exc: Optional[BaseException]) -> None: ... def connection_made(self, transport: asyncio.BaseTransport) -> None: super().connection_made(transport) @@ -449,8 +445,7 @@ def data_received(self, data: bytes) -> None: self._handle_body(body, charset) @abstractmethod - def _handle_body(self, body: bytes, charset: str) -> None: - ... + def _handle_body(self, body: bytes, charset: str) -> None: ... class JsonRPCProtocol(JsonRPCProtocolBase): diff --git a/packages/jsonrpc2/src/robotcode/jsonrpc2/server.py b/packages/jsonrpc2/src/robotcode/jsonrpc2/server.py index 1981c0e9d..3407cb7dc 100644 --- a/packages/jsonrpc2/src/robotcode/jsonrpc2/server.py +++ b/packages/jsonrpc2/src/robotcode/jsonrpc2/server.py @@ -91,11 +91,11 @@ def start(self) -> None: elif self.mode == ServerMode.SOCKET: self.start_socket( self.tcp_params.port, - self.tcp_params.host - if isinstance(self.tcp_params.host, str) - else self.tcp_params.host[0] - if self.tcp_params.host - else None, + ( + self.tcp_params.host + if isinstance(self.tcp_params.host, str) + else self.tcp_params.host[0] if self.tcp_params.host else None + ), ) else: raise JsonRPCException(f"Unknown server mode {self.mode}") @@ -166,8 +166,7 @@ def __exit__( self.close() @abc.abstractmethod - def create_protocol(self) -> TProtocol: - ... + def create_protocol(self) -> TProtocol: ... stdio_executor: Optional[ThreadPoolExecutor] = None diff --git a/packages/language_server/src/robotcode/language_server/common/parts/code_action.py b/packages/language_server/src/robotcode/language_server/common/parts/code_action.py index 1d798e35b..3bb0d051a 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/code_action.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/code_action.py @@ -39,12 +39,10 @@ def collect( document: TextDocument, range: Range, context: CodeActionContext, - ) -> Optional[List[Union[Command, CodeAction]]]: - ... + ) -> Optional[List[Union[Command, CodeAction]]]: ... @event - def resolve(sender, code_action: CodeAction) -> Optional[CodeAction]: - ... + def resolve(sender, code_action: CodeAction) -> Optional[CodeAction]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.collect): diff --git a/packages/language_server/src/robotcode/language_server/common/parts/code_lens.py b/packages/language_server/src/robotcode/language_server/common/parts/code_lens.py index 0270a25a8..c96320a30 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/code_lens.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/code_lens.py @@ -31,12 +31,10 @@ def __init__(self, parent: "LanguageServerProtocol") -> None: self.refresh_timer: Optional[threading.Timer] = None @event - def collect(sender, document: TextDocument) -> Optional[List[CodeLens]]: - ... + def collect(sender, document: TextDocument) -> Optional[List[CodeLens]]: ... @event - def resolve(sender, code_lens: CodeLens) -> Optional[CodeLens]: - ... + def resolve(sender, code_lens: CodeLens) -> Optional[CodeLens]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.collect): diff --git a/packages/language_server/src/robotcode/language_server/common/parts/completion.py b/packages/language_server/src/robotcode/language_server/common/parts/completion.py index 53a3def46..6727b0fe2 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/completion.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/completion.py @@ -48,12 +48,10 @@ def collect( document: TextDocument, position: Position, context: Optional[CompletionContext], - ) -> Union[List[CompletionItem], CompletionList, None]: - ... + ) -> Union[List[CompletionItem], CompletionList, None]: ... @event - def resolve(sender, completion_item: CompletionItem) -> Optional[CompletionItem]: - ... + def resolve(sender, completion_item: CompletionItem) -> Optional[CompletionItem]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.collect): diff --git a/packages/language_server/src/robotcode/language_server/common/parts/declaration.py b/packages/language_server/src/robotcode/language_server/common/parts/declaration.py index 7a22d26a8..46d540063 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/declaration.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/declaration.py @@ -35,8 +35,7 @@ def collect( sender, document: TextDocument, position: Position, - ) -> Union[Location, List[Location], List[LocationLink], None]: - ... + ) -> Union[Location, List[Location], List[LocationLink], None]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if ( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/definition.py b/packages/language_server/src/robotcode/language_server/common/parts/definition.py index 066a46167..7854ad59a 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/definition.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/definition.py @@ -35,8 +35,7 @@ def collect( sender, document: TextDocument, position: Position, - ) -> Union[Location, List[Location], List[LocationLink], None]: - ... + ) -> Union[Location, List[Location], List[LocationLink], None]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if ( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/diagnostics.py b/packages/language_server/src/robotcode/language_server/common/parts/diagnostics.py index 8ef3a4342..a4d92c9f6 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/diagnostics.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/diagnostics.py @@ -138,50 +138,39 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None: self.client_supports_pull = True @event - def analyze(sender, document: TextDocument) -> Optional[DiagnosticsResult]: - ... + def analyze(sender, document: TextDocument) -> Optional[DiagnosticsResult]: ... @event - def collect(sender, document: TextDocument) -> Optional[DiagnosticsResult]: - ... + def collect(sender, document: TextDocument) -> Optional[DiagnosticsResult]: ... @event def load_workspace_documents( sender, - ) -> Optional[List[WorkspaceDocumentsResult]]: - ... + ) -> Optional[List[WorkspaceDocumentsResult]]: ... @event - def on_workspace_loaded(sender: Any) -> None: - ... + def on_workspace_loaded(sender: Any) -> None: ... @event - def on_get_analysis_progress_mode(sender: Any, uri: Uri) -> Optional[AnalysisProgressMode]: - ... + def on_get_analysis_progress_mode(sender: Any, uri: Uri) -> Optional[AnalysisProgressMode]: ... @event - def on_get_diagnostics_mode(sender: Any, uri: Uri) -> Optional[DiagnosticsMode]: - ... + def on_get_diagnostics_mode(sender: Any, uri: Uri) -> Optional[DiagnosticsMode]: ... @event - def on_workspace_diagnostics_start(sender: Any) -> None: - ... + def on_workspace_diagnostics_start(sender: Any) -> None: ... @event - def on_workspace_diagnostics_analyze(sender: Any) -> None: - ... + def on_workspace_diagnostics_analyze(sender: Any) -> None: ... @event - def on_workspace_diagnostics_collect(sender: Any) -> None: - ... + def on_workspace_diagnostics_collect(sender: Any) -> None: ... @event - def on_workspace_diagnostics_end(sender: Any) -> None: - ... + def on_workspace_diagnostics_end(sender: Any) -> None: ... @event - def on_workspace_diagnostics_break(sender: Any) -> None: - ... + def on_workspace_diagnostics_break(sender: Any) -> None: ... def ensure_workspace_loaded(self) -> None: self.parent.ensure_initialized() diff --git a/packages/language_server/src/robotcode/language_server/common/parts/document_highlight.py b/packages/language_server/src/robotcode/language_server/common/parts/document_highlight.py index e08da1c3a..b22c2846d 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/document_highlight.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/document_highlight.py @@ -34,8 +34,7 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None: capabilities.document_highlight_provider = DocumentHighlightOptions(work_done_progress=True) @event - def collect(sender, document: TextDocument, position: Position) -> Optional[List[DocumentHighlight]]: - ... + def collect(sender, document: TextDocument, position: Position) -> Optional[List[DocumentHighlight]]: ... @rpc_method(name="textDocument/documentHighlight", param_type=DocumentHighlightParams, threaded=True) def _text_document_document_highlight( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/document_symbols.py b/packages/language_server/src/robotcode/language_server/common/parts/document_symbols.py index c6c895c21..db889ab81 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/document_symbols.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/document_symbols.py @@ -66,8 +66,7 @@ def __init__(self, parent: "LanguageServerProtocol") -> None: def collect( sender, document: TextDocument, - ) -> Optional[Union[List[DocumentSymbol], List[SymbolInformation], None]]: - ... + ) -> Optional[Union[List[DocumentSymbol], List[SymbolInformation], None]]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if ( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/documents.py b/packages/language_server/src/robotcode/language_server/common/parts/documents.py index 98b09464f..cf62c04b0 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/documents.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/documents.py @@ -114,9 +114,11 @@ def _text_document_did_open(self, text_document: TextDocumentItem, *args: Any, * document = self._create_document( text_document.uri, normalized_text, - text_document.language_id - if text_document.language_id - else self.detect_language_id(text_document.uri), + ( + text_document.language_id + if text_document.language_id + else self.detect_language_id(text_document.uri) + ), text_document.version, ) @@ -221,12 +223,14 @@ def _text_document_did_change( self.parent.capabilities.text_document_sync, TextDocumentSyncKind, ) - else self.parent.capabilities.text_document_sync.change - if isinstance( - self.parent.capabilities.text_document_sync, - TextDocumentSyncOptions, + else ( + self.parent.capabilities.text_document_sync.change + if isinstance( + self.parent.capabilities.text_document_sync, + TextDocumentSyncOptions, + ) + else None ) - else None ) for content_change in content_changes: if sync_kind is None or sync_kind == TextDocumentSyncKind.NONE_: diff --git a/packages/language_server/src/robotcode/language_server/common/parts/formatting.py b/packages/language_server/src/robotcode/language_server/common/parts/formatting.py index a2f6905a4..fa53a447e 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/formatting.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/formatting.py @@ -39,8 +39,7 @@ def format( document: TextDocument, options: FormattingOptions, **further_options: Any, - ) -> Optional[List[TextEdit]]: - ... + ) -> Optional[List[TextEdit]]: ... @event def format_range( @@ -49,8 +48,7 @@ def format_range( range: Range, options: FormattingOptions, **further_options: Any, - ) -> Optional[List[TextEdit]]: - ... + ) -> Optional[List[TextEdit]]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.format): diff --git a/packages/language_server/src/robotcode/language_server/common/parts/hover.py b/packages/language_server/src/robotcode/language_server/common/parts/hover.py index 501635ebf..49dc251be 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/hover.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/hover.py @@ -30,8 +30,7 @@ def __init__(self, parent: "LanguageServerProtocol") -> None: super().__init__(parent) @event - def collect(sender, document: TextDocument, position: Position) -> Optional[Hover]: - ... + def collect(sender, document: TextDocument, position: Position) -> Optional[Hover]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.collect): diff --git a/packages/language_server/src/robotcode/language_server/common/parts/implementation.py b/packages/language_server/src/robotcode/language_server/common/parts/implementation.py index 30f4abdd7..4dc16af25 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/implementation.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/implementation.py @@ -34,8 +34,7 @@ def collect( sender, document: TextDocument, position: Position, - ) -> Union[Location, List[Location], List[LocationLink], None]: - ... + ) -> Union[Location, List[Location], List[LocationLink], None]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if ( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/inlay_hint.py b/packages/language_server/src/robotcode/language_server/common/parts/inlay_hint.py index bdfaf2004..92457c5c1 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/inlay_hint.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/inlay_hint.py @@ -31,12 +31,10 @@ def __init__(self, parent: "LanguageServerProtocol") -> None: self.refresh_timer: Optional[threading.Timer] = None @event - def collect(sender, document: TextDocument, range: Range) -> Optional[List[InlayHint]]: - ... + def collect(sender, document: TextDocument, range: Range) -> Optional[List[InlayHint]]: ... @event - def resolve(sender, hint: InlayHint) -> Optional[InlayHint]: - ... + def resolve(sender, hint: InlayHint) -> Optional[InlayHint]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.collect): diff --git a/packages/language_server/src/robotcode/language_server/common/parts/inline_value.py b/packages/language_server/src/robotcode/language_server/common/parts/inline_value.py index 32645ad94..5c7cd932a 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/inline_value.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/inline_value.py @@ -46,8 +46,7 @@ def collect( document: TextDocument, range: Range, context: InlineValueContext, # pragma: no cover, NOSONAR - ) -> Optional[List[InlineValue]]: - ... + ) -> Optional[List[InlineValue]]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.collect): diff --git a/packages/language_server/src/robotcode/language_server/common/parts/linked_editing_ranges.py b/packages/language_server/src/robotcode/language_server/common/parts/linked_editing_ranges.py index b6468e61d..e190b4feb 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/linked_editing_ranges.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/linked_editing_ranges.py @@ -34,8 +34,7 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None: capabilities.linked_editing_range_provider = LinkedEditingRangeOptions(work_done_progress=True) @event - def collect(sender, document: TextDocument, position: Position) -> Optional[LinkedEditingRanges]: - ... + def collect(sender, document: TextDocument, position: Position) -> Optional[LinkedEditingRanges]: ... @rpc_method(name="textDocument/linkedEditingRange", param_type=LinkedEditingRangeParams, threaded=True) def _text_document_linked_editing_range( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/references.py b/packages/language_server/src/robotcode/language_server/common/parts/references.py index b867810ac..f07040067 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/references.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/references.py @@ -39,8 +39,7 @@ def collect( document: TextDocument, position: Position, context: ReferenceContext, - ) -> Optional[List[Location]]: - ... + ) -> Optional[List[Location]]: ... @rpc_method(name="textDocument/references", param_type=ReferenceParams, threaded=True) def _text_document_references( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/rename.py b/packages/language_server/src/robotcode/language_server/common/parts/rename.py index 545e59174..0cb988d6f 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/rename.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/rename.py @@ -51,12 +51,10 @@ def collect( document: TextDocument, position: Position, new_name: str, - ) -> Optional[WorkspaceEdit]: - ... + ) -> Optional[WorkspaceEdit]: ... @event - def collect_prepare(sender, document: TextDocument, position: Position) -> Optional[PrepareRenameResult]: - ... + def collect_prepare(sender, document: TextDocument, position: Position) -> Optional[PrepareRenameResult]: ... @rpc_method(name="textDocument/rename", param_type=RenameParams, threaded=True) def _text_document_rename( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/selection_range.py b/packages/language_server/src/robotcode/language_server/common/parts/selection_range.py index fe731b121..299c5dd22 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/selection_range.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/selection_range.py @@ -33,8 +33,7 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None: capabilities.selection_range_provider = SelectionRangeOptions(work_done_progress=True) @event - def collect(sender, document: TextDocument, positions: List[Position]) -> Optional[List[SelectionRange]]: - ... + def collect(sender, document: TextDocument, positions: List[Position]) -> Optional[List[SelectionRange]]: ... @rpc_method(name="textDocument/selectionRange", param_type=SelectionRangeParams, threaded=True) def _text_document_selection_range( diff --git a/packages/language_server/src/robotcode/language_server/common/parts/semantic_tokens.py b/packages/language_server/src/robotcode/language_server/common/parts/semantic_tokens.py index 298dbf7c0..1fc3a8012 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/semantic_tokens.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/semantic_tokens.py @@ -50,8 +50,7 @@ def collect_full( sender, document: TextDocument, **kwargs: Any, - ) -> Union[SemanticTokens, SemanticTokensPartialResult, None]: - ... + ) -> Union[SemanticTokens, SemanticTokensPartialResult, None]: ... @event def collect_full_delta( @@ -59,8 +58,12 @@ def collect_full_delta( document: TextDocument, previous_result_id: str, **kwargs: Any, - ) -> Union[SemanticTokens, SemanticTokensDelta, SemanticTokensDeltaPartialResult, None,]: - ... + ) -> Union[ + SemanticTokens, + SemanticTokensDelta, + SemanticTokensDeltaPartialResult, + None, + ]: ... @event def collect_range( @@ -68,8 +71,7 @@ def collect_range( document: TextDocument, range: Range, **kwargs: Any, - ) -> Union[SemanticTokens, SemanticTokensPartialResult, None]: - ... + ) -> Union[SemanticTokens, SemanticTokensPartialResult, None]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.collect_full) or len(self.collect_range): @@ -78,11 +80,11 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None: token_types=[e.value for e in self.token_types], token_modifiers=[e.value for e in self.token_modifiers], ), - full=SemanticTokensOptionsFullType1(delta=True if len(self.collect_full_delta) else None) - if len(self.collect_full) and len(self.collect_full_delta) - else True - if len(self.collect_full) - else None, + full=( + SemanticTokensOptionsFullType1(delta=True if len(self.collect_full_delta) else None) + if len(self.collect_full) and len(self.collect_full_delta) + else True if len(self.collect_full) else None + ), range=True if len(self.collect_range) else None, ) @@ -124,7 +126,12 @@ def _text_document_semantic_tokens_full_delta( previous_result_id: str, *args: Any, **kwargs: Any, - ) -> Union[SemanticTokens, SemanticTokensDelta, SemanticTokensDeltaPartialResult, None,]: + ) -> Union[ + SemanticTokens, + SemanticTokensDelta, + SemanticTokensDeltaPartialResult, + None, + ]: results: List[ Union[ SemanticTokens, diff --git a/packages/language_server/src/robotcode/language_server/common/parts/signature_help.py b/packages/language_server/src/robotcode/language_server/common/parts/signature_help.py index 324538e76..8cc9e140f 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/signature_help.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/signature_help.py @@ -42,8 +42,7 @@ def collect( document: TextDocument, position: Position, context: Optional[SignatureHelpContext] = None, - ) -> Optional[SignatureHelp]: - ... + ) -> Optional[SignatureHelp]: ... def extend_capabilities(self, capabilities: ServerCapabilities) -> None: if len(self.collect): diff --git a/packages/language_server/src/robotcode/language_server/common/parts/window.py b/packages/language_server/src/robotcode/language_server/common/parts/window.py index 663c2adca..6c174e922 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/window.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/window.py @@ -61,9 +61,11 @@ def begin( self.parent.progress_begin( self.token, message if message is not None else self.message, - int(current * 100 / self.max) - if percentage is None and current is not None and self.max is not None - else percentage, + ( + int(current * 100 / self.max) + if percentage is None and current is not None and self.max is not None + else percentage + ), cancellable, title, ) @@ -88,9 +90,11 @@ def report( self.parent.progress_report( self.token, message if message is not None else self.message, - int(current * 100 / self.max) - if percentage is None and current is not None and self.max is not None - else percentage, + ( + int(current * 100 / self.max) + if percentage is None and current is not None and self.max is not None + else percentage + ), cancellable, title, ) diff --git a/packages/language_server/src/robotcode/language_server/common/parts/workspace.py b/packages/language_server/src/robotcode/language_server/common/parts/workspace.py index a1b73d06d..851950a24 100644 --- a/packages/language_server/src/robotcode/language_server/common/parts/workspace.py +++ b/packages/language_server/src/robotcode/language_server/common/parts/workspace.py @@ -173,8 +173,7 @@ def settings(self, value: Dict[str, Any]) -> None: self._settings = value @event - def did_change_configuration(sender, settings: Dict[str, Any]) -> None: - ... + def did_change_configuration(sender, settings: Dict[str, Any]) -> None: ... @rpc_method(name="workspace/didChangeConfiguration", param_type=DidChangeConfigurationParams) def _workspace_did_change_configuration(self, settings: Dict[str, Any], *args: Any, **kwargs: Any) -> None: @@ -183,28 +182,22 @@ def _workspace_did_change_configuration(self, settings: Dict[str, Any], *args: A self.did_change_configuration(self, settings) @event - def will_create_files(sender, files: List[str]) -> Optional[Mapping[str, List[TextEdit]]]: - ... + def will_create_files(sender, files: List[str]) -> Optional[Mapping[str, List[TextEdit]]]: ... @event - def did_create_files(sender, files: List[str]) -> None: - ... + def did_create_files(sender, files: List[str]) -> None: ... @event - def will_rename_files(sender, files: List[Tuple[str, str]]) -> None: - ... + def will_rename_files(sender, files: List[Tuple[str, str]]) -> None: ... @event - def did_rename_files(sender, files: List[Tuple[str, str]]) -> None: - ... + def did_rename_files(sender, files: List[Tuple[str, str]]) -> None: ... @event - def will_delete_files(sender, files: List[str]) -> None: - ... + def will_delete_files(sender, files: List[str]) -> None: ... @event - def did_delete_files(sender, files: List[str]) -> None: - ... + def did_delete_files(sender, files: List[str]) -> None: ... @rpc_method(name="workspace/willCreateFiles", param_type=CreateFilesParams, threaded=True) def _workspace_will_create_files( @@ -374,8 +367,7 @@ def _workspace_did_change_workspace_folders( # TODO: do we need an event for this? @event - def did_change_watched_files(sender, changes: List[FileEvent]) -> None: - ... + def did_change_watched_files(sender, changes: List[FileEvent]) -> None: ... @rpc_method(name="workspace/didChangeWatchedFiles", param_type=DidChangeWatchedFilesParams, threaded=True) def _workspace_did_change_watched_files(self, changes: List[FileEvent], *args: Any, **kwargs: Any) -> None: diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_documentation.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_documentation.py index a00fab99c..8886b40a4 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_documentation.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_documentation.py @@ -87,11 +87,11 @@ def collect( # only source actions result = self.get_keyworddoc_and_token_from_position( - node.value - if isinstance(node, (TestTemplate, Template)) - else node.keyword - if isinstance(node, KeywordCall) - else node.name, + ( + node.value + if isinstance(node, (TestTemplate, Template)) + else node.keyword if isinstance(node, KeywordCall) else node.name + ), cast( Token, node.get_token(RobotToken.KEYWORD if isinstance(node, KeywordCall) else RobotToken.NAME), diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py index 4e576ec0e..60b0c1a6b 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/code_action_refactor.py @@ -299,49 +299,55 @@ def code_action_surround( CodeAction( "Surround with TRY...EXCEPT", kind=CODE_ACTION_KIND_SURROUND_WITH, - data=as_dict( - CodeActionData( - "refactor", - "surround", - document.document_uri, - insert_range, - SurroundType.TRY_EXCEPT, + data=( + as_dict( + CodeActionData( + "refactor", + "surround", + document.document_uri, + insert_range, + SurroundType.TRY_EXCEPT, + ) ) - ) - if insert_range - else None, + if insert_range + else None + ), disabled=disabled, ), CodeAction( "Surround with TRY...FINALLY", kind=CODE_ACTION_KIND_SURROUND_WITH, - data=as_dict( - CodeActionData( - "refactor", - "surround", - document.document_uri, - insert_range, - SurroundType.TRY_FINALLY, + data=( + as_dict( + CodeActionData( + "refactor", + "surround", + document.document_uri, + insert_range, + SurroundType.TRY_FINALLY, + ) ) - ) - if insert_range - else None, + if insert_range + else None + ), disabled=disabled, ), CodeAction( "Surround with TRY...EXCEPT..FINALLY", kind=CODE_ACTION_KIND_SURROUND_WITH, - data=as_dict( - CodeActionData( - "refactor", - "surround", - document.document_uri, - insert_range, - SurroundType.TRY_EXCEPT_FINALLY, + data=( + as_dict( + CodeActionData( + "refactor", + "surround", + document.document_uri, + insert_range, + SurroundType.TRY_EXCEPT_FINALLY, + ) ) - ) - if insert_range - else None, + if insert_range + else None + ), disabled=disabled, ), ] @@ -570,16 +576,18 @@ def code_action_extract_keyword( CodeAction( "Extract keyword", kind=CODE_ACTION_KIND_REFACTOR_EXTRACT_FUNCTION, - data=as_dict( - CodeActionData( - "refactor", - "extract_keyword", - document.document_uri, - insert_range, + data=( + as_dict( + CodeActionData( + "refactor", + "extract_keyword", + document.document_uri, + insert_range, + ) ) - ) - if insert_range - else None, + if insert_range + else None + ), disabled=disabled, ) ] diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/completion.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/completion.py index ca32f62db..915270e7c 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/completion.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/completion.py @@ -539,9 +539,9 @@ def create_headers_completion_items(self, range: Optional[Range]) -> List[Comple kind=CompletionItemKind.CLASS, detail="Header", # this is to get the english version in the documentation - documentation=self.namespace.languages.headers.get(s[1]) - if self.namespace.languages is not None - else None, + documentation=( + self.namespace.languages.headers.get(s[1]) if self.namespace.languages is not None else None + ), sort_text=f"100_{s[1]}", insert_text_format=InsertTextFormat.PLAIN_TEXT, text_edit=TextEdit(range=range, new_text=s[0]) if range is not None else None, @@ -618,9 +618,9 @@ def create_settings_completion_items(self, range: Optional[Range]) -> List[Compl label=setting, kind=CompletionItemKind.KEYWORD, detail="Setting", - documentation=self.namespace.languages.settings.get(setting) - if self.namespace.languages is not None - else None, + documentation=( + self.namespace.languages.settings.get(setting) if self.namespace.languages is not None else None + ), sort_text=f"090_{setting}", insert_text_format=InsertTextFormat.PLAIN_TEXT, text_edit=TextEdit(range=range, new_text=setting) if range is not None else None, @@ -662,9 +662,9 @@ def create_testcase_settings_completion_items(self, range: Optional[Range]) -> L CompletionItem( label=f"[{setting}]", kind=CompletionItemKind.KEYWORD, - documentation=self.namespace.languages.settings.get(setting) - if self.namespace.languages is not None - else None, + documentation=( + self.namespace.languages.settings.get(setting) if self.namespace.languages is not None else None + ), detail="Setting", sort_text=f"070_{setting}", insert_text_format=InsertTextFormat.PLAIN_TEXT, @@ -691,9 +691,9 @@ def create_bdd_prefix_completion_items( detail="BDD Prefix", sort_text=f"000_{prefix}" if at_top else f"080_{prefix}", insert_text_format=InsertTextFormat.PLAIN_TEXT, - text_edit=TextEdit(range=range, new_text=prefix + (" " if with_space else "")) - if range is not None - else None, + text_edit=( + TextEdit(range=range, new_text=prefix + (" " if with_space else "")) if range is not None else None + ), ) for prefix in prefixes ] @@ -718,9 +718,9 @@ def create_keyword_settings_completion_items(self, range: Optional[Range]) -> Li CompletionItem( label=f"[{setting}]", kind=CompletionItemKind.KEYWORD, - documentation=self.namespace.languages.settings.get(setting) - if self.namespace.languages is not None - else None, + documentation=( + self.namespace.languages.settings.get(setting) if self.namespace.languages is not None else None + ), detail="Setting", sort_text=f"070_{setting}", insert_text_format=InsertTextFormat.PLAIN_TEXT, @@ -865,17 +865,21 @@ def enumerate_indexes(s: str, c: str) -> Iterator[int]: detail=f"{CompleteResultKind.KEYWORD.value} " f"{f'({kw.libname})' if kw.libname is not None else ''}", sort_text=f"019_{kw.name}", - insert_text_format=InsertTextFormat.PLAIN_TEXT - if not kw.is_embedded - else InsertTextFormat.SNIPPET, - text_edit=TextEdit( - range=r, - new_text=kw.name - if not kw.is_embedded - else self.get_keyword_snipped_text(kw, in_template), - ) - if r is not None - else None, + insert_text_format=( + InsertTextFormat.PLAIN_TEXT if not kw.is_embedded else InsertTextFormat.SNIPPET + ), + text_edit=( + TextEdit( + range=r, + new_text=( + kw.name + if not kw.is_embedded + else self.get_keyword_snipped_text(kw, in_template) + ), + ) + if r is not None + else None + ), data=CompletionKeywordData( document_uri=str(self.document.uri), type=CompleteResultKind.KEYWORD.name, @@ -908,14 +912,18 @@ def enumerate_indexes(s: str, c: str) -> Iterator[int]: detail=f"{CompleteResultKind.KEYWORD.value} " f"{f'({kw.libname})' if kw.libname is not None else ''}", sort_text=f"019_{kw.name}", - insert_text_format=InsertTextFormat.PLAIN_TEXT - if not kw.is_embedded - else InsertTextFormat.SNIPPET, + insert_text_format=( + InsertTextFormat.PLAIN_TEXT + if not kw.is_embedded + else InsertTextFormat.SNIPPET + ), text_edit=TextEdit( range=r, - new_text=kw.name - if not kw.is_embedded - else self.get_keyword_snipped_text(kw, in_template), + new_text=( + kw.name + if not kw.is_embedded + else self.get_keyword_snipped_text(kw, in_template) + ), ), data=CompletionKeywordData( document_uri=str(self.document.uri), @@ -1162,13 +1170,17 @@ def complete_default( line=position.line, character=token_at_position.col_offset + open_brace_index + 1, ), - end=position - if contains_spezial or variable_end < 0 - else Position( - line=position.line, - character=(token_at_position.col_offset + variable_end) - if not contains_spezial - else token_at_position.end_col_offset, + end=( + position + if contains_spezial or variable_end < 0 + else Position( + line=position.line, + character=( + (token_at_position.col_offset + variable_end) + if not contains_spezial + else token_at_position.end_col_offset + ), + ) ), ) if token_at_position.value[open_brace_index - 1] == "%": @@ -1251,12 +1263,16 @@ def _complete_TestCase_or_Keyword( # noqa: N802 return create_items( in_assign, in_template, - range_from_token(statement_node.tokens[index + 1]) - if r.end == position and len(statement_node.tokens) > index + 1 - else None, - statement_node.tokens[index + 1] - if r.end == position and len(statement_node.tokens) > index + 1 - else None, + ( + range_from_token(statement_node.tokens[index + 1]) + if r.end == position and len(statement_node.tokens) > index + 1 + else None + ), + ( + statement_node.tokens[index + 1] + if r.end == position and len(statement_node.tokens) > index + 1 + else None + ), position, ) @@ -1674,17 +1690,19 @@ def complete_import() -> Optional[List[CompletionItem]]: return [ CompletionItem( label=e.label, - kind=CompletionItemKind.MODULE - if e.kind - in [ - CompleteResultKind.MODULE, - CompleteResultKind.MODULE_INTERNAL, - ] - else CompletionItemKind.FILE - if e.kind == CompleteResultKind.FILE - else CompletionItemKind.FOLDER - if e.kind == CompleteResultKind.FOLDER - else None, + kind=( + CompletionItemKind.MODULE + if e.kind + in [ + CompleteResultKind.MODULE, + CompleteResultKind.MODULE_INTERNAL, + ] + else ( + CompletionItemKind.FILE + if e.kind == CompleteResultKind.FILE + else CompletionItemKind.FOLDER if e.kind == CompleteResultKind.FOLDER else None + ) + ), detail=e.kind.value, sort_text=f"030_{e}", insert_text_format=InsertTextFormat.PLAIN_TEXT, @@ -1871,13 +1889,15 @@ def complete_ResourceImport( # noqa: N802 return [ CompletionItem( label=e.label, - kind=CompletionItemKind.FILE - if e.kind == CompleteResultKind.RESOURCE - else CompletionItemKind.FILE - if e.kind == CompleteResultKind.FILE - else CompletionItemKind.FOLDER - if e.kind == CompleteResultKind.FOLDER - else None, + kind=( + CompletionItemKind.FILE + if e.kind == CompleteResultKind.RESOURCE + else ( + CompletionItemKind.FILE + if e.kind == CompleteResultKind.FILE + else CompletionItemKind.FOLDER if e.kind == CompleteResultKind.FOLDER else None + ) + ), detail=e.kind.value, sort_text=f"030_{e}", insert_text_format=InsertTextFormat.PLAIN_TEXT, @@ -1991,13 +2011,15 @@ def complete_import() -> Optional[List[CompletionItem]]: return [ CompletionItem( label=e.label, - kind=CompletionItemKind.FILE - if e.kind == CompleteResultKind.VARIABLES - else CompletionItemKind.FILE - if e.kind == CompleteResultKind.FILE - else CompletionItemKind.FOLDER - if e.kind == CompleteResultKind.FOLDER - else None, + kind=( + CompletionItemKind.FILE + if e.kind == CompleteResultKind.VARIABLES + else ( + CompletionItemKind.FILE + if e.kind == CompleteResultKind.FILE + else CompletionItemKind.FOLDER if e.kind == CompleteResultKind.FOLDER else None + ) + ), detail=e.kind.value, sort_text=f"030_{e}", insert_text_format=InsertTextFormat.PLAIN_TEXT, @@ -2281,15 +2303,17 @@ def _complete_keyword_arguments_at_position( ) if type_info.items: snippets = [ - "{" - + ", ".join( - (f'"{m.key}"' + ": ${" + str(i + 1) + "}") - for i, m in enumerate(type_info.items) - if m.required - ) - + "}" - if any(m.required for m in type_info.items) and any(not m.required for m in type_info.items) - else "", + ( + "{" + + ", ".join( + (f'"{m.key}"' + ": ${" + str(i + 1) + "}") + for i, m in enumerate(type_info.items) + if m.required + ) + + "}" + if any(m.required for m in type_info.items) and any(not m.required for m in type_info.items) + else "" + ), "{" + ", ".join((f'"{m.key}"' + ": ${" + str(i + 1) + "}") for i, m in enumerate(type_info.items)) + "}", diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/documents_cache.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/documents_cache.py index f77f95997..54a6ded97 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/documents_cache.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/documents_cache.py @@ -31,9 +31,9 @@ def __init__(self, parent: "RobotLanguageServerProtocol") -> None: self._imports_managers_lock = threading.RLock() self._imports_managers: weakref.WeakKeyDictionary[WorkspaceFolder, ImportsManager] = weakref.WeakKeyDictionary() self._default_imports_manager: Optional[ImportsManager] = None - self._workspace_languages: weakref.WeakKeyDictionary[ - WorkspaceFolder, Optional[Languages] - ] = weakref.WeakKeyDictionary() + self._workspace_languages: weakref.WeakKeyDictionary[WorkspaceFolder, Optional[Languages]] = ( + weakref.WeakKeyDictionary() + ) def calc_cache_path(self, folder_uri: Uri) -> Path: cache_config = self.parent.workspace.get_configuration(CacheConfig, folder_uri) diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/goto.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/goto.py index b4231fcab..d2bf39467 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/goto.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/goto.py @@ -70,9 +70,9 @@ def collect( origin_selection_range=found_range, target_uri=str(Uri.from_path(variable.source)), target_range=variable.range, - target_selection_range=range_from_token(variable.name_token) - if variable.name_token - else variable.range, + target_selection_range=( + range_from_token(variable.name_token) if variable.name_token else variable.range + ), ) ) diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/hover.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/hover.py index 409686641..005325b50 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/hover.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/hover.py @@ -187,14 +187,16 @@ def _hover_default(self, nodes: List[ast.AST], document: TextDocument, position: found_range = ( ns.import_range if ns.import_source == namespace.source and position.is_in_range(ns.import_range, False) - else ns.alias_range - if ns.import_source == namespace.source and position.is_in_range(ns.alias_range, False) - else cast( - Optional[Range], - next( - (r.range for r in ns_refs if position.is_in_range(r.range, False)), - None, - ), + else ( + ns.alias_range + if ns.import_source == namespace.source and position.is_in_range(ns.alias_range, False) + else cast( + Optional[Range], + next( + (r.range for r in ns_refs if position.is_in_range(r.range, False)), + None, + ), + ) ) ) diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/references.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/references.py index 8b911cd18..d75c0623f 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/references.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/references.py @@ -70,8 +70,7 @@ def __init__(self, parent: "RobotLanguageServerProtocol") -> None: parent.diagnostics.on_workspace_diagnostics_break.add(self.on_workspace_diagnostics_break) @event - def cache_cleared(sender) -> None: - ... + def cache_cleared(sender) -> None: ... def server_initialized(self, sender: Any) -> None: self.parent.workspace.add_file_watcher( @@ -592,17 +591,19 @@ def find_tag_references_in_file(self, doc: TextDocument, tag: str, is_normalized (statements.Tags, statements.ForceTags, statements.DefaultTags) if get_robot_version() < (6, 0) else ( - statements.Tags, - statements.ForceTags, - statements.DefaultTags, - statements.KeywordTags, - ) - if get_robot_version() < (7, 0) - else ( - statements.Tags, - statements.TestTags, - statements.DefaultTags, - statements.KeywordTags, + ( + statements.Tags, + statements.ForceTags, + statements.DefaultTags, + statements.KeywordTags, + ) + if get_robot_version() < (7, 0) + else ( + statements.Tags, + statements.TestTags, + statements.DefaultTags, + statements.KeywordTags, + ) ) ) diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/rename.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/rename.py index 67723b51f..726642b84 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/rename.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/rename.py @@ -365,15 +365,17 @@ def _find_KeywordCall( # noqa: N802 ): return ( keyword_doc, - RobotToken( - keyword_token.type, - keyword_token.value[len(kw_namespace) + 1 :], - keyword_token.lineno, - keyword_token.col_offset + len(kw_namespace) + 1, - keyword_token.error, - ) - if lib_entry and kw_namespace - else keyword_token, + ( + RobotToken( + keyword_token.type, + keyword_token.value[len(kw_namespace) + 1 :], + keyword_token.lineno, + keyword_token.col_offset + len(kw_namespace) + 1, + keyword_token.error, + ) + if lib_entry and kw_namespace + else keyword_token + ), ) return None @@ -486,15 +488,17 @@ def _find_Fixture( # noqa: N802 if position in kw_range and keyword_doc is not None and not keyword_doc.is_error_handler: return ( keyword_doc, - RobotToken( - keyword_token.type, - keyword_token.value[len(kw_namespace) + 1 :], - keyword_token.lineno, - keyword_token.col_offset + len(kw_namespace) + 1, - keyword_token.error, - ) - if lib_entry and kw_namespace - else keyword_token, + ( + RobotToken( + keyword_token.type, + keyword_token.value[len(kw_namespace) + 1 :], + keyword_token.lineno, + keyword_token.col_offset + len(kw_namespace) + 1, + keyword_token.error, + ) + if lib_entry and kw_namespace + else keyword_token + ), ) return None @@ -545,15 +549,17 @@ def _find_Template_or_TestTemplate( # noqa: N802 if not keyword_doc.is_error_handler: return ( keyword_doc, - RobotToken( - keyword_token.type, - keyword_token.value[len(kw_namespace) + 1 :], - keyword_token.lineno, - keyword_token.col_offset + len(kw_namespace) + 1, - keyword_token.error, - ) - if lib_entry and kw_namespace - else keyword_token, + ( + RobotToken( + keyword_token.type, + keyword_token.value[len(kw_namespace) + 1 :], + keyword_token.lineno, + keyword_token.col_offset + len(kw_namespace) + 1, + keyword_token.error, + ) + if lib_entry and kw_namespace + else keyword_token + ), ) return None diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/robocop_diagnostics.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/robocop_diagnostics.py index e502e23d6..e8ac3d15f 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/robocop_diagnostics.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/robocop_diagnostics.py @@ -153,13 +153,19 @@ def run_check(self, ast_model, filename, source=None): # type: ignore ), ), message=issue.desc, - severity=DiagnosticSeverity.INFORMATION - if issue.severity == RuleSeverity.INFO - else DiagnosticSeverity.WARNING - if issue.severity == RuleSeverity.WARNING - else DiagnosticSeverity.ERROR - if issue.severity == RuleSeverity.ERROR - else DiagnosticSeverity.HINT, + severity=( + DiagnosticSeverity.INFORMATION + if issue.severity == RuleSeverity.INFO + else ( + DiagnosticSeverity.WARNING + if issue.severity == RuleSeverity.WARNING + else ( + DiagnosticSeverity.ERROR + if issue.severity == RuleSeverity.ERROR + else DiagnosticSeverity.HINT + ) + ) + ), source=self.source_name, code=f"{issue.name}-{issue.severity.value}{issue.rule_id}", code_description=self.get_code_description(robocop_version, issue), diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/robot_workspace.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/robot_workspace.py index 854ef045b..07bcd8e68 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/robot_workspace.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/robot_workspace.py @@ -89,9 +89,11 @@ def load_workspace_documents(self, sender: Any) -> List[WorkspaceDocumentsResult progress.begin() progress.report( - f"Load {name!s}" - if config.analysis.progress_mode == AnalysisProgressMode.DETAILED - else None, + ( + f"Load {name!s}" + if config.analysis.progress_mode == AnalysisProgressMode.DETAILED + else None + ), current=i, ) except (SystemExit, KeyboardInterrupt): diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py index 516812fb8..dc4320a9a 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/semantic_tokens.py @@ -638,9 +638,11 @@ def generate_sem_tokens( token.lineno, token.col_offset, ), - RobotSemTokenTypes.NAMED_ARGUMENT - if isinstance(node, Variable) - else SemanticTokenTypes.PARAMETER, + ( + RobotSemTokenTypes.NAMED_ARGUMENT + if isinstance(node, Variable) + else SemanticTokenTypes.PARAMETER + ), ) yield SemTokenInfo.from_token( Token( @@ -1082,9 +1084,11 @@ def get_tokens() -> Iterator[Tuple[Token, ast.AST]]: if isinstance(node, (KeywordCall, Fixture)): kw_token = cast( Token, - node.get_token(Token.KEYWORD) - if isinstance(node, KeywordCall) - else node.get_token(Token.NAME), + ( + node.get_token(Token.KEYWORD) + if isinstance(node, KeywordCall) + else node.get_token(Token.NAME) + ), ) for node_token in node.tokens: @@ -1222,5 +1226,10 @@ def collect_full_delta( document: TextDocument, previous_result_id: str, **kwargs: Any, - ) -> Union[SemanticTokens, SemanticTokensDelta, SemanticTokensDeltaPartialResult, None,]: + ) -> Union[ + SemanticTokens, + SemanticTokensDelta, + SemanticTokensDeltaPartialResult, + None, + ]: return None diff --git a/packages/language_server/src/robotcode/language_server/robotframework/parts/signature_help.py b/packages/language_server/src/robotcode/language_server/robotframework/parts/signature_help.py index 1e687beb8..3677f22bd 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/parts/signature_help.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/parts/signature_help.py @@ -173,12 +173,14 @@ def _get_signature_help( parameters=[ ParameterInformation( label=p.signature(), - documentation=MarkupContent( - kind=MarkupKind.MARKDOWN, - value="\n\n---\n\n".join([t.to_markdown() for t in keyword_doc.parent.get_types(p.types)]), - ) - if p.types and keyword_doc.parent is not None - else None, + documentation=( + MarkupContent( + kind=MarkupKind.MARKDOWN, + value="\n\n---\n\n".join([t.to_markdown() for t in keyword_doc.parent.get_types(p.types)]), + ) + if p.types and keyword_doc.parent is not None + else None + ), ) for i, p in enumerate(kw_arguments) ], diff --git a/packages/language_server/src/robotcode/language_server/robotframework/protocol.py b/packages/language_server/src/robotcode/language_server/robotframework/protocol.py index e0bd5f877..a591f002b 100644 --- a/packages/language_server/src/robotcode/language_server/robotframework/protocol.py +++ b/packages/language_server/src/robotcode/language_server/robotframework/protocol.py @@ -207,8 +207,7 @@ def _on_did_change_configuration(self, sender: Any, settings: Dict[str, Any]) -> pass @event - def on_robot_initialized(sender) -> None: - ... + def on_robot_initialized(sender) -> None: ... def server_initialized(self, sender: Any) -> None: for folder in self.workspace.workspace_folders: diff --git a/packages/plugin/src/robotcode/plugin/__init__.py b/packages/plugin/src/robotcode/plugin/__init__.py index 36bc09b23..62240fba9 100644 --- a/packages/plugin/src/robotcode/plugin/__init__.py +++ b/packages/plugin/src/robotcode/plugin/__init__.py @@ -142,9 +142,7 @@ def print_data( text = tomli_w.dumps( as_dict(data, remove_defaults=remove_defaults) if dataclasses.is_dataclass(data) - else data - if isinstance(data, dict) - else {data: data} + else data if isinstance(data, dict) else {data: data} ) if text is None: diff --git a/packages/robot/src/robotcode/robot/diagnostics/document_cache_helper.py b/packages/robot/src/robotcode/robot/diagnostics/document_cache_helper.py index b98453b1d..089061cf1 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/document_cache_helper.py +++ b/packages/robot/src/robotcode/robot/diagnostics/document_cache_helper.py @@ -59,9 +59,9 @@ def __init__( self._imports_managers_lock = threading.RLock() self._imports_managers: weakref.WeakKeyDictionary[WorkspaceFolder, ImportsManager] = weakref.WeakKeyDictionary() self._default_imports_manager: Optional[ImportsManager] = None - self._workspace_languages: weakref.WeakKeyDictionary[ - WorkspaceFolder, Optional[Languages] - ] = weakref.WeakKeyDictionary() + self._workspace_languages: weakref.WeakKeyDictionary[WorkspaceFolder, Optional[Languages]] = ( + weakref.WeakKeyDictionary() + ) def get_languages_for_document(self, document_or_uri: Union[TextDocument, Uri, str]) -> Optional[Languages]: if get_robot_version() < (6, 0): @@ -416,8 +416,7 @@ def __get_general_namespace(self, document: TextDocument) -> Namespace: return self.__get_namespace_for_document_type(document, DocumentType.GENERAL) @event - def namespace_invalidated(sender, namespace: Namespace) -> None: - ... + def namespace_invalidated(sender, namespace: Namespace) -> None: ... def __invalidate_namespace(self, sender: Namespace) -> None: document = sender.document diff --git a/packages/robot/src/robotcode/robot/diagnostics/imports_manager.py b/packages/robot/src/robotcode/robot/diagnostics/imports_manager.py index 16c631349..235f52f3b 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/imports_manager.py +++ b/packages/robot/src/robotcode/robot/diagnostics/imports_manager.py @@ -119,8 +119,7 @@ def _remove_file_watcher(self) -> None: self.file_watchers = [] @abstractmethod - def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileChangeType]: - ... + def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileChangeType]: ... @final def invalidate(self) -> None: @@ -128,16 +127,13 @@ def invalidate(self) -> None: self._invalidate() @abstractmethod - def _invalidate(self) -> None: - ... + def _invalidate(self) -> None: ... @abstractmethod - def _update(self) -> None: - ... + def _update(self) -> None: ... @abstractmethod - def is_valid(self) -> bool: - ... + def is_valid(self) -> bool: ... class _LibrariesEntry(_ImportEntry): @@ -211,9 +207,7 @@ def _update(self) -> None: source_or_origin = ( self._lib_doc.source if self._lib_doc.source is not None - else self._lib_doc.module_spec.origin - if self._lib_doc.module_spec is not None - else None + else self._lib_doc.module_spec.origin if self._lib_doc.module_spec is not None else None ) # we are a module, so add the module path into file watchers @@ -661,20 +655,16 @@ def get_resolvable_command_line_variables(self) -> Dict[str, Any]: return self._resolvable_command_line_variables @event - def libraries_changed(sender, libraries: List[LibraryDoc]) -> None: - ... + def libraries_changed(sender, libraries: List[LibraryDoc]) -> None: ... @event - def resources_changed(sender, resources: List[LibraryDoc]) -> None: - ... + def resources_changed(sender, resources: List[LibraryDoc]) -> None: ... @event - def variables_changed(sender, variables: List[LibraryDoc]) -> None: - ... + def variables_changed(sender, variables: List[LibraryDoc]) -> None: ... @event - def imports_changed(sender, uri: DocumentUri) -> None: - ... + def imports_changed(sender, uri: DocumentUri) -> None: ... def possible_imports_modified(self, sender: Any, uri: DocumentUri) -> None: self.imports_changed(self, uri) diff --git a/packages/robot/src/robotcode/robot/diagnostics/library_doc.py b/packages/robot/src/robotcode/robot/diagnostics/library_doc.py index b628bbc58..7431f1f8e 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/library_doc.py +++ b/packages/robot/src/robotcode/robot/diagnostics/library_doc.py @@ -397,11 +397,15 @@ def from_robot(arg: Any) -> ArgumentInfo: name=robot_arg.name, default_value=robot_arg_repr(robot_arg), str_repr=str(arg), - types=robot_arg.types_reprs - if get_robot_version() < (7, 0) - else ([str(robot_arg.type)] if not robot_arg.type.is_union else [str(t) for t in robot_arg.type.nested]) - if robot_arg.type - else None, + types=( + robot_arg.types_reprs + if get_robot_version() < (7, 0) + else ( + ([str(robot_arg.type)] if not robot_arg.type.is_union else [str(t) for t in robot_arg.type.nested]) + if robot_arg.type + else None + ) + ), kind=KeywordArgumentKind[robot_arg.kind], required=robot_arg.required, ) @@ -1273,9 +1277,9 @@ def get_module_spec(module_name: str) -> Optional[ModuleSpec]: return ModuleSpec( # type: ignore name=result.name, origin=result.origin, - submodule_search_locations=list(result.submodule_search_locations) - if result.submodule_search_locations - else None, + submodule_search_locations=( + list(result.submodule_search_locations) if result.submodule_search_locations else None + ), member_name=member_name, ) return None @@ -1396,9 +1400,11 @@ def get_message_and_traceback_from_exception_text( return MessageAndTraceback( message=splitted[0].strip(), - traceback=[SourceAndLineInfo(t.group(1), int(t.group(2))) for t in __RE_TRACEBACK.finditer(splitted[1])] - if len(splitted) > 1 - else [], + traceback=( + [SourceAndLineInfo(t.group(1), int(t.group(2))) for t in __RE_TRACEBACK.finditer(splitted[1])] + if len(splitted) > 1 + else [] + ), ) @@ -1723,20 +1729,20 @@ def get_test_library( except BaseException as e: return LibraryDoc( name=name, - source=source or module_spec.origin - if module_spec is not None and module_spec.origin - else import_name - if is_library_by_path(import_name) - else None, + source=( + source or module_spec.origin + if module_spec is not None and module_spec.origin + else import_name if is_library_by_path(import_name) else None + ), module_spec=module_spec, errors=[ error_from_exception( e, - source or module_spec.origin - if module_spec is not None and module_spec.origin - else import_name - if is_library_by_path(import_name) - else None, + ( + source or module_spec.origin + if module_spec is not None and module_spec.origin + else import_name if is_library_by_path(import_name) else None + ), 1 if source is not None or module_spec is not None and module_spec.origin is not None else None, ) ], @@ -1798,11 +1804,13 @@ def get_test_library( libdoc = LibraryDoc( name=library_name, source=real_source, - module_spec=module_spec - if module_spec is not None - and module_spec.origin != real_source - and module_spec.submodule_search_locations is None - else None, + module_spec=( + module_spec + if module_spec is not None + and module_spec.origin != real_source + and module_spec.submodule_search_locations is None + else None + ), python_path=sys.path, line_no=lib.lineno if lib is not None else -1, doc=str(lib.doc) if lib is not None else "", @@ -1921,18 +1929,22 @@ def get_args_to_process(libdoc_name: str, kw_name: str) -> Any: is_registered_run_keyword=RUN_KW_REGISTER.is_run_keyword(libdoc.name, kw[0].name), args_to_process=get_args_to_process(libdoc.name, kw[0].name), deprecated=kw[0].deprecated, - arguments_spec=ArgumentSpec.from_robot_argument_spec( - kw[1].arguments if get_robot_version() < (7, 0) else kw[1].args - ) - if not kw[1].is_error_handler - else None, + arguments_spec=( + ArgumentSpec.from_robot_argument_spec( + kw[1].arguments if get_robot_version() < (7, 0) else kw[1].args + ) + if not kw[1].is_error_handler + else None + ), return_type=( - str(kw[1].args.return_type) - if kw[1].args.return_type is not None and kw[1].args.return_type != type(None) + ( + str(kw[1].args.return_type) + if kw[1].args.return_type is not None and kw[1].args.return_type != type(None) + else None + ) + if get_robot_version() >= (7, 0) else None - ) - if get_robot_version() >= (7, 0) - else None, + ), ) for kw in keyword_docs ], @@ -2273,9 +2285,9 @@ def _get_initial_handler(self, library: Any, name: Any, method: Any) -> Any: source=source or (module_spec.origin if module_spec is not None else None) or "", name=name if get_robot_version() < (7, 0) else f"${{{name}}}", name_token=None, - value=NativeValue(value) - if value is None or isinstance(value, (int, float, bool, str)) - else None, + value=( + NativeValue(value) if value is None or isinstance(value, (int, float, bool, str)) else None + ), has_value=value is None or isinstance(value, (int, float, bool, str)), value_is_native=value is None or isinstance(value, (int, float, bool, str)), ) @@ -2287,11 +2299,11 @@ def _get_initial_handler(self, library: Any, name: Any, method: Any) -> Any: libdoc.errors = [ error_from_exception( e, - source or module_spec.origin - if module_spec is not None and module_spec.origin - else import_name - if is_variables_by_path(import_name) - else None, + ( + source or module_spec.origin + if module_spec is not None and module_spec.origin + else import_name if is_variables_by_path(import_name) else None + ), 1 if source is not None or module_spec is not None and module_spec.origin is not None else None, ) ] @@ -2307,11 +2319,11 @@ def _get_initial_handler(self, library: Any, name: Any, method: Any) -> Any: errors=[ error_from_exception( e, - source or module_spec.origin - if module_spec is not None and module_spec.origin - else import_name - if is_variables_by_path(import_name) - else None, + ( + source or module_spec.origin + if module_spec is not None and module_spec.origin + else import_name if is_variables_by_path(import_name) else None + ), 1 if source is not None or module_spec is not None and module_spec.origin is not None else None, ) ], @@ -2788,9 +2800,9 @@ def get_kw_errors(kw: Any) -> Any: is_embedded=is_embedded_keyword(kw[0].name), errors=get_kw_errors(kw[1]), is_error_handler=isinstance(kw[1], UserErrorHandler), - error_handler_message=str(cast(UserErrorHandler, kw[1]).error) - if isinstance(kw[1], UserErrorHandler) - else None, + error_handler_message=( + str(cast(UserErrorHandler, kw[1]).error) if isinstance(kw[1], UserErrorHandler) else None + ), arguments_spec=ArgumentSpec.from_robot_argument_spec( kw[1].arguments if get_robot_version() < (7, 0) else kw[1].args ), diff --git a/packages/robot/src/robotcode/robot/diagnostics/namespace.py b/packages/robot/src/robotcode/robot/diagnostics/namespace.py index ceafb9b6e..1c8d2d399 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/namespace.py +++ b/packages/robot/src/robotcode/robot/diagnostics/namespace.py @@ -466,16 +466,16 @@ def visit_LibraryImport(self, node: RobotLibraryImport) -> None: # noqa: N802 alias_token=alias_token, line_no=node.lineno, col_offset=node.col_offset, - end_line_no=last_data_token.lineno - if last_data_token is not None - else node.end_lineno - if node.end_lineno is not None - else -1, - end_col_offset=last_data_token.end_col_offset - if last_data_token is not None - else node.end_col_offset - if node.end_col_offset is not None - else -1, + end_line_no=( + last_data_token.lineno + if last_data_token is not None + else node.end_lineno if node.end_lineno is not None else -1 + ), + end_col_offset=( + last_data_token.end_col_offset + if last_data_token is not None + else node.end_col_offset if node.end_col_offset is not None else -1 + ), source=self.source, ) ) @@ -491,16 +491,16 @@ def visit_ResourceImport(self, node: RobotResourceImport) -> None: # noqa: N802 name_token=name if name is not None else None, line_no=node.lineno, col_offset=node.col_offset, - end_line_no=last_data_token.lineno - if last_data_token is not None - else node.end_lineno - if node.end_lineno is not None - else -1, - end_col_offset=last_data_token.end_col_offset - if last_data_token is not None - else node.end_col_offset - if node.end_col_offset is not None - else -1, + end_line_no=( + last_data_token.lineno + if last_data_token is not None + else node.end_lineno if node.end_lineno is not None else -1 + ), + end_col_offset=( + last_data_token.end_col_offset + if last_data_token is not None + else node.end_col_offset if node.end_col_offset is not None else -1 + ), source=self.source, ) ) @@ -517,16 +517,16 @@ def visit_VariablesImport(self, node: RobotVariablesImport) -> None: # noqa: N8 args=node.args, line_no=node.lineno, col_offset=node.col_offset, - end_line_no=last_data_token.lineno - if last_data_token is not None - else node.end_lineno - if node.end_lineno is not None - else -1, - end_col_offset=last_data_token.end_col_offset - if last_data_token is not None - else node.end_col_offset - if node.end_col_offset is not None - else -1, + end_line_no=( + last_data_token.lineno + if last_data_token is not None + else node.end_lineno if node.end_lineno is not None else -1 + ), + end_col_offset=( + last_data_token.end_col_offset + if last_data_token is not None + else node.end_col_offset if node.end_col_offset is not None else -1 + ), source=self.source, ) ) @@ -610,20 +610,16 @@ def __init__( self._ignored_lines: Optional[List[int]] = None @event - def has_invalidated(sender) -> None: - ... + def has_invalidated(sender) -> None: ... @event - def has_initialized(sender) -> None: - ... + def has_initialized(sender) -> None: ... @event - def has_imports_changed(sender) -> None: - ... + def has_imports_changed(sender) -> None: ... @event - def has_analysed(sender) -> None: - ... + def has_analysed(sender) -> None: ... @property def document(self) -> Optional[TextDocument]: @@ -959,16 +955,18 @@ def yield_variables( for var in chain( *[ ( - BlockVariableVisitor( - self.get_library_doc(), - self.get_global_variables(), - self.source, - position, - isinstance(test_or_keyword_nodes[-1], Arguments) if nodes else False, - ).get(test_or_keyword) + ( + BlockVariableVisitor( + self.get_library_doc(), + self.get_global_variables(), + self.source, + position, + isinstance(test_or_keyword_nodes[-1], Arguments) if nodes else False, + ).get(test_or_keyword) + ) + if test_or_keyword is not None + else [] ) - if test_or_keyword is not None - else [] ], self.get_global_variables(), ): @@ -1098,17 +1096,19 @@ def _import( message="Possible circular import.", severity=DiagnosticSeverity.INFORMATION, source=DIAGNOSTICS_SOURCE_NAME, - related_information=[ - DiagnosticRelatedInformation( - location=Location( - str(Uri.from_path(value.source)), - value.range, - ), - message=f"'{Path(self.source).name}' is also imported here.", - ) - ] - if value.source - else None, + related_information=( + [ + DiagnosticRelatedInformation( + location=Location( + str(Uri.from_path(value.source)), + value.range, + ), + message=f"'{Path(self.source).name}' is also imported here.", + ) + ] + if value.source + else None + ), code=Error.POSSIBLE_CIRCULAR_IMPORT, ) else: @@ -1174,20 +1174,24 @@ def _import( uri=str(Uri.from_path(err.source)), range=Range( start=Position( - line=err.line_no - 1 - if err.line_no is not None - else max( - result.library_doc.line_no, - 0, + line=( + err.line_no - 1 + if err.line_no is not None + else max( + result.library_doc.line_no, + 0, + ) ), character=0, ), end=Position( - line=err.line_no - 1 - if err.line_no is not None - else max( - result.library_doc.line_no, - 0, + line=( + err.line_no - 1 + if err.line_no is not None + else max( + result.library_doc.line_no, + 0, + ) ), character=0, ), @@ -1295,17 +1299,21 @@ def _import( message=f"Resource {entry} already imported.", severity=DiagnosticSeverity.INFORMATION, source=DIAGNOSTICS_SOURCE_NAME, - related_information=[ - DiagnosticRelatedInformation( - location=Location( - uri=str(Uri.from_path(already_imported_resources.import_source)), - range=already_imported_resources.import_range, - ), - message="", - ) - ] - if already_imported_resources.import_source - else None, + related_information=( + [ + DiagnosticRelatedInformation( + location=Location( + uri=str( + Uri.from_path(already_imported_resources.import_source) + ), + range=already_imported_resources.import_range, + ), + message="", + ) + ] + if already_imported_resources.import_source + else None + ), code=Error.RESOURCE_ALREADY_IMPORTED, ) @@ -1327,17 +1335,19 @@ def _import( message=f'Variables "{entry}" already imported.', severity=DiagnosticSeverity.INFORMATION, source=DIAGNOSTICS_SOURCE_NAME, - related_information=[ - DiagnosticRelatedInformation( - location=Location( - uri=str(Uri.from_path(already_imported_variables[0].import_source)), - range=already_imported_variables[0].import_range, - ), - message="", - ) - ] - if already_imported_variables[0].import_source - else None, + related_information=( + [ + DiagnosticRelatedInformation( + location=Location( + uri=str(Uri.from_path(already_imported_variables[0].import_source)), + range=already_imported_variables[0].import_range, + ), + message="", + ) + ] + if already_imported_variables[0].import_source + else None + ), code=Error.VARIABLES_ALREADY_IMPORTED, ) @@ -1352,17 +1362,19 @@ def _import( ' because it would override the "BuiltIn" library.', severity=DiagnosticSeverity.INFORMATION, source=DIAGNOSTICS_SOURCE_NAME, - related_information=[ - DiagnosticRelatedInformation( - location=Location( - uri=str(Uri.from_path(entry.import_source)), - range=entry.import_range, - ), - message="", - ) - ] - if entry.import_source - else None, + related_information=( + [ + DiagnosticRelatedInformation( + location=Location( + uri=str(Uri.from_path(entry.import_source)), + range=entry.import_range, + ), + message="", + ) + ] + if entry.import_source + else None + ), code=Error.LIBRARY_OVERRIDES_BUILTIN, ) continue @@ -1381,17 +1393,19 @@ def _import( message=f'Library "{entry}" already imported.', severity=DiagnosticSeverity.INFORMATION, source=DIAGNOSTICS_SOURCE_NAME, - related_information=[ - DiagnosticRelatedInformation( - location=Location( - uri=str(Uri.from_path(already_imported_library[0].import_source)), - range=already_imported_library[0].import_range, - ), - message="", - ) - ] - if already_imported_library[0].import_source - else None, + related_information=( + [ + DiagnosticRelatedInformation( + location=Location( + uri=str(Uri.from_path(already_imported_library[0].import_source)), + range=already_imported_library[0].import_range, + ), + message="", + ) + ] + if already_imported_library[0].import_source + else None + ), code=Error.LIBRARY_ALREADY_IMPORTED, ) @@ -1695,9 +1709,11 @@ def analyze(self) -> None: self._analyzed = not canceled self._logger.debug( - lambda: f"end analyzed {self.document} succeed in {time.monotonic() - start_time}s" - if self._analyzed - else f"end analyzed {self.document} failed in {time.monotonic() - start_time}s" + lambda: ( + f"end analyzed {self.document} succeed in {time.monotonic() - start_time}s" + if self._analyzed + else f"end analyzed {self.document} failed in {time.monotonic() - start_time}s" + ) ) self.has_analysed(self) diff --git a/packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py b/packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py index 9d8a61a78..bb9704b88 100644 --- a/packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py +++ b/packages/robot/src/robotcode/robot/diagnostics/namespace_analyzer.py @@ -555,9 +555,7 @@ def _analyze_keyword_call( Uri.from_path( err.source if err.source is not None - else result.source - if result.source is not None - else "/" + else result.source if result.source is not None else "/" ) ), range=Range( diff --git a/packages/robot/src/robotcode/robot/utils/markdownformatter.py b/packages/robot/src/robotcode/robot/utils/markdownformatter.py index 474718145..a048e11a1 100644 --- a/packages/robot/src/robotcode/robot/utils/markdownformatter.py +++ b/packages/robot/src/robotcode/robot/utils/markdownformatter.py @@ -17,8 +17,7 @@ def handles(self, line: str) -> bool: return self._handles(line.strip() if self._strip_lines else line) @abstractmethod - def _handles(self, line: str) -> bool: - ... + def _handles(self, line: str) -> bool: ... def add(self, line: str) -> None: self._lines.append(line.strip() if self._strip_lines else line) @@ -29,8 +28,7 @@ def end(self) -> str: return result @abstractmethod - def format(self, lines: List[str]) -> str: - ... + def format(self, lines: List[str]) -> str: ... class MarkDownFormatter: @@ -80,15 +78,13 @@ def _handles(self, line: str) -> bool: return bool(not self._lines and self.match(line)) @abstractmethod - def match(self, line: str) -> Optional[re.Match[str]]: - ... + def match(self, line: str) -> Optional[re.Match[str]]: ... def format(self, lines: List[str]) -> str: return self.format_line(lines[0]) @abstractmethod - def format_line(self, line: str) -> str: - ... + def format_line(self, line: str) -> str: ... class HeaderFormatter(SingleLineFormatter): diff --git a/packages/robot/src/robotcode/robot/utils/stubs.py b/packages/robot/src/robotcode/robot/utils/stubs.py index d26a03a34..826791145 100644 --- a/packages/robot/src/robotcode/robot/utils/stubs.py +++ b/packages/robot/src/robotcode/robot/utils/stubs.py @@ -33,8 +33,6 @@ class Languages(Protocol): true_strings: Set[str] false_strings: Set[str] - def add_language(self, name: str) -> None: - ... + def add_language(self, name: str) -> None: ... - def __iter__(self) -> Iterator[Any]: - ... + def __iter__(self) -> Iterator[Any]: ... diff --git a/packages/runner/src/robotcode/runner/cli/discover/discover.py b/packages/runner/src/robotcode/runner/cli/discover/discover.py index e61fce610..528840ddf 100644 --- a/packages/runner/src/robotcode/runner/cli/discover/discover.py +++ b/packages/runner/src/robotcode/runner/cli/discover/discover.py @@ -280,12 +280,14 @@ def visit_suite(self, suite: TestSuite) -> None: uri=str(Uri.from_path(absolute_path)) if absolute_path else None, source=str(suite.source), rel_source=get_rel_source(suite.source), - range=Range( - start=Position(line=0, character=0), - end=Position(line=0, character=0), - ) - if suite.source and Path(suite.source).is_file() - else None, + range=( + Range( + start=Position(line=0, character=0), + end=Position(line=0, character=0), + ) + if suite.source and Path(suite.source).is_file() + else None + ), children=[], error=suite.error_message if isinstance(suite, ErroneousTestSuite) else None, ) @@ -462,11 +464,11 @@ def handle_options( options, arguments = RobotFrameworkEx( app, - [*(app.config.default_paths if app.config.default_paths else ())] - if profile.paths is None - else profile.paths - if isinstance(profile.paths, list) - else [profile.paths], + ( + [*(app.config.default_paths if app.config.default_paths else ())] + if profile.paths is None + else profile.paths if isinstance(profile.paths, list) else [profile.paths] + ), app.config.dry, root_folder, ).parse_arguments((*cmd_options, *robot_options_and_args)) diff --git a/packages/runner/src/robotcode/runner/cli/robot.py b/packages/runner/src/robotcode/runner/cli/robot.py index 993a1bdb5..519c035c8 100644 --- a/packages/runner/src/robotcode/runner/cli/robot.py +++ b/packages/runner/src/robotcode/runner/cli/robot.py @@ -185,11 +185,11 @@ def robot( int, RobotFrameworkEx( app, - [*(app.config.default_paths if app.config.default_paths else ())] - if profile.paths is None - else profile.paths - if isinstance(profile.paths, list) - else [profile.paths], + ( + [*(app.config.default_paths if app.config.default_paths else ())] + if profile.paths is None + else profile.paths if isinstance(profile.paths, list) else [profile.paths] + ), app.config.dry, root_folder, ).execute_cli((*cmd_options, *robot_options_and_args), exit=False), diff --git a/tests/robotcode/language_server/robotframework/parts/test_code_action_show_documentation.py b/tests/robotcode/language_server/robotframework/parts/test_code_action_show_documentation.py index 025468574..67b97817c 100644 --- a/tests/robotcode/language_server/robotframework/parts/test_code_action_show_documentation.py +++ b/tests/robotcode/language_server/robotframework/parts/test_code_action_show_documentation.py @@ -66,15 +66,17 @@ def split(action: Union[Command, CodeAction]) -> Union[Command, CodeAction]: yaml.dump( { "data": data, - "result": sorted( - (split(v) for v in result), - key=lambda v: ( - v.title, - v.kind if isinstance(v, CodeAction) else None, - ), - ) - if result - else result, + "result": ( + sorted( + (split(v) for v in result), + key=lambda v: ( + v.title, + v.kind if isinstance(v, CodeAction) else None, + ), + ) + if result + else result + ), } ) ) diff --git a/tests/robotcode/language_server/robotframework/parts/test_document_symbols.py b/tests/robotcode/language_server/robotframework/parts/test_document_symbols.py index 5d3633ced..23ed0758b 100644 --- a/tests/robotcode/language_server/robotframework/parts/test_document_symbols.py +++ b/tests/robotcode/language_server/robotframework/parts/test_document_symbols.py @@ -64,12 +64,14 @@ def test( yaml.dump( { "data": data, - "result": next( - reversed([l for l in split(result, data) if l is not None]), - None, - ) - if result - else result, + "result": ( + next( + reversed([l for l in split(result, data) if l is not None]), + None, + ) + if result + else result + ), } ) ) diff --git a/tests/robotcode/language_server/robotframework/parts/test_references.py b/tests/robotcode/language_server/robotframework/parts/test_references.py index e17aef4d6..aca1be2e7 100644 --- a/tests/robotcode/language_server/robotframework/parts/test_references.py +++ b/tests/robotcode/language_server/robotframework/parts/test_references.py @@ -44,12 +44,14 @@ def split(location: Location) -> Location: yaml.dump( { "data": data, - "result": sorted( - (split(v) for v in result), - key=lambda v: (v.uri, v.range.start, v.range.end), - ) - if result - else result, + "result": ( + sorted( + (split(v) for v in result), + key=lambda v: (v.uri, v.range.start, v.range.end), + ) + if result + else result + ), } ) ) diff --git a/tests/robotcode/language_server/robotframework/parts/test_signature_help.py b/tests/robotcode/language_server/robotframework/parts/test_signature_help.py index 30c6b7302..eb4133254 100644 --- a/tests/robotcode/language_server/robotframework/parts/test_signature_help.py +++ b/tests/robotcode/language_server/robotframework/parts/test_signature_help.py @@ -47,21 +47,25 @@ def test( yaml.dump( { "data": data, - "result": dataclasses.replace( - result, - signatures=[ - dataclasses.replace( - s, - documentation=None, - parameters=[dataclasses.replace(p, documentation=None) for p in s.parameters] - if s.parameters - else s.parameters, - ) - for s in result.signatures - ], - ) - if result - else None, + "result": ( + dataclasses.replace( + result, + signatures=[ + dataclasses.replace( + s, + documentation=None, + parameters=( + [dataclasses.replace(p, documentation=None) for p in s.parameters] + if s.parameters + else s.parameters + ), + ) + for s in result.signatures + ], + ) + if result + else None + ), } ) )