From 73efe73de77d921b21f24b7ceb1a6777f1759d00 Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Thu, 24 Nov 2022 08:50:03 +0100 Subject: [PATCH 1/2] add simple progress reporting --- README.rst | 12 ++++++++++++ pylsp_mypy/plugin.py | 36 +++++++++++++++++++++++++++++++++++- setup.cfg | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 52fad22..e248255 100644 --- a/README.rst +++ b/README.rst @@ -42,6 +42,9 @@ Configuration ``config_sub_paths`` (default is ``[]``) specifies sub paths under which the mypy configuration file may be found. For each directory searched for the mypy config file, this also searches the sub paths specified here +``report_progress`` (default is ``False``) report basic progress to the LSP client. + With this option, pylsp-mypy will report when mypy is running, given you editor supports LSP progress reporting. For small files this might produce annoying flashing in your editor, espacially in with ``live_mode``. For large projects, enabling this can be helpfull to assure yourself whether mypy is still running. + This project supports the use of ``pyproject.toml`` for configuration. It is in fact the preferred way. Using that your configuration could look like this: :: @@ -103,6 +106,15 @@ With ``config_sub_paths`` your config could look like this: "config_sub_paths": [".config"] } +With ``report_progress`` your config could look like this: + +:: + + { + "enabled": True, + "report_progress": True + } + Developing ------------- diff --git a/pylsp_mypy/plugin.py b/pylsp_mypy/plugin.py index 468237f..4f31b90 100644 --- a/pylsp_mypy/plugin.py +++ b/pylsp_mypy/plugin.py @@ -125,7 +125,7 @@ def pylsp_lint( config: Config, workspace: Workspace, document: Document, is_saved: bool ) -> List[Dict[str, Any]]: """ - Lints. + Call the linter. Parameters ---------- @@ -157,6 +157,40 @@ def pylsp_lint( if settings == {}: settings = oldSettings2 + if settings.get("report_progress", False): + with workspace.report_progress("lint: mypy"): + return get_diagnostics(config, workspace, document, settings, is_saved) + else: + return get_diagnostics(config, workspace, document, settings, is_saved) + + +def get_diagnostics( + config: Config, + workspace: Workspace, + document: Document, + settings: Dict[str, Any], + is_saved: bool, +) -> List[Dict[str, Any]]: + """ + Lints. + + Parameters + ---------- + config : Config + The pylsp config. + workspace : Workspace + The pylsp workspace. + document : Document + The document to be linted. + is_saved : bool + Weather the document is saved. + + Returns + ------- + List[Dict[str, Any]] + List of the linting data. + + """ log.info( "lint settings = %s document.path = %s is_saved = %s", settings, diff --git a/setup.cfg b/setup.cfg index 3bbe0db..d5988d1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,7 +19,7 @@ classifiers = python_requires = >= 3.7 packages = find: install_requires = - python-lsp-server + python-lsp-server >=1.7.0 mypy toml From 33087a2c5b715cb74e860814c3bea5c1df517d68 Mon Sep 17 00:00:00 2001 From: Richard Kellnberger Date: Thu, 5 Jan 2023 19:47:38 +0100 Subject: [PATCH 2/2] Spelling/grammar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafał Chłodnicki --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e248255..b1c221c 100644 --- a/README.rst +++ b/README.rst @@ -43,7 +43,7 @@ Configuration For each directory searched for the mypy config file, this also searches the sub paths specified here ``report_progress`` (default is ``False``) report basic progress to the LSP client. - With this option, pylsp-mypy will report when mypy is running, given you editor supports LSP progress reporting. For small files this might produce annoying flashing in your editor, espacially in with ``live_mode``. For large projects, enabling this can be helpfull to assure yourself whether mypy is still running. + With this option, pylsp-mypy will report when mypy is running, given your editor supports LSP progress reporting. For small files this might produce annoying flashing in your editor, especially in with ``live_mode``. For large projects, enabling this can be helpful to assure yourself whether mypy is still running. This project supports the use of ``pyproject.toml`` for configuration. It is in fact the preferred way. Using that your configuration could look like this: