Skip to content

Commit

Permalink
add simple progress reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar authored and Richardk2n committed Jan 5, 2023
1 parent 1c5a336 commit f078667
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Configuration
``overrides`` (default is ``[True]``) specifies a list of alternate or supplemental command-line options.
This modifies the options passed to ``mypy`` or the mypy-specific ones passed to ``dmypy run``. When present, the special boolean member ``True`` is replaced with the command-line options that would've been passed had ``overrides`` not been specified. Later options take precedence, which allows for replacing or negating individual default options (see ``mypy.main:process_options`` and ``mypy --help | grep inverse``).

``report_progress`` (default is False) report progress to the LSP client.
When you editor supports LSP progress reporting, mypy will then report progress when it's 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:

::
Expand Down
49 changes: 32 additions & 17 deletions pylsp_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,36 @@ def apply_overrides(args: List[str], overrides: List[Any]) -> List[str]:
@hookimpl
def pylsp_lint(
config: Config, workspace: Workspace, document: Document, is_saved: bool
) -> List[Dict[str, Any]]:
settings = config.plugin_settings("pylsp_mypy")
oldSettings1 = config.plugin_settings("mypy-ls")
if oldSettings1 != {}:
raise DeprecationWarning(
"Your configuration uses the namespace mypy-ls, this should be changed to pylsp_mypy"
)
oldSettings2 = config.plugin_settings("mypy_ls")
if oldSettings2 != {}:
raise DeprecationWarning(
"Your configuration uses the namespace mypy_ls, this should be changed to pylsp_mypy"
)
if settings == {}:
settings = oldSettings1
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.
Expand All @@ -143,22 +173,6 @@ def pylsp_lint(
List of the linting data.
"""
settings = config.plugin_settings("pylsp_mypy")
oldSettings1 = config.plugin_settings("mypy-ls")
if oldSettings1 != {}:
raise DeprecationWarning(
"Your configuration uses the namespace mypy-ls, this should be changed to pylsp_mypy"
)
oldSettings2 = config.plugin_settings("mypy_ls")
if oldSettings2 != {}:
raise DeprecationWarning(
"Your configuration uses the namespace mypy_ls, this should be changed to pylsp_mypy"
)
if settings == {}:
settings = oldSettings1
if settings == {}:
settings = oldSettings2

log.info(
"lint settings = %s document.path = %s is_saved = %s",
settings,
Expand Down Expand Up @@ -297,7 +311,8 @@ def pylsp_lint(
"end": {"line": 0, "character": 1000},
},
"message": errors,
"severity": 1 if exit_status != 0 else 2, # Error if exited with error or warning.
# Error if exited with error or warning.
"severity": 1 if exit_status != 0 else 2,
}
)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers =
python_requires = >= 3.7
packages = find:
install_requires =
python-lsp-server
python-lsp-server >=1.7.0
mypy
toml

Expand Down

0 comments on commit f078667

Please sign in to comment.