Skip to content

Commit f078667

Browse files
sypharRichardk2n
authored andcommitted
add simple progress reporting
1 parent 1c5a336 commit f078667

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Configuration
3636
``overrides`` (default is ``[True]``) specifies a list of alternate or supplemental command-line options.
3737
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``).
3838

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

4144
::

pylsp_mypy/plugin.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,36 @@ def apply_overrides(args: List[str], overrides: List[Any]) -> List[str]:
122122
@hookimpl
123123
def pylsp_lint(
124124
config: Config, workspace: Workspace, document: Document, is_saved: bool
125+
) -> List[Dict[str, Any]]:
126+
settings = config.plugin_settings("pylsp_mypy")
127+
oldSettings1 = config.plugin_settings("mypy-ls")
128+
if oldSettings1 != {}:
129+
raise DeprecationWarning(
130+
"Your configuration uses the namespace mypy-ls, this should be changed to pylsp_mypy"
131+
)
132+
oldSettings2 = config.plugin_settings("mypy_ls")
133+
if oldSettings2 != {}:
134+
raise DeprecationWarning(
135+
"Your configuration uses the namespace mypy_ls, this should be changed to pylsp_mypy"
136+
)
137+
if settings == {}:
138+
settings = oldSettings1
139+
if settings == {}:
140+
settings = oldSettings2
141+
142+
if settings.get("report_progress", False):
143+
with workspace.report_progress("lint: mypy"):
144+
return get_diagnostics(config, workspace, document, settings, is_saved)
145+
else:
146+
return get_diagnostics(config, workspace, document, settings, is_saved)
147+
148+
149+
def get_diagnostics(
150+
config: Config,
151+
workspace: Workspace,
152+
document: Document,
153+
settings: Dict[str, Any],
154+
is_saved: bool,
125155
) -> List[Dict[str, Any]]:
126156
"""
127157
Lints.
@@ -143,22 +173,6 @@ def pylsp_lint(
143173
List of the linting data.
144174
145175
"""
146-
settings = config.plugin_settings("pylsp_mypy")
147-
oldSettings1 = config.plugin_settings("mypy-ls")
148-
if oldSettings1 != {}:
149-
raise DeprecationWarning(
150-
"Your configuration uses the namespace mypy-ls, this should be changed to pylsp_mypy"
151-
)
152-
oldSettings2 = config.plugin_settings("mypy_ls")
153-
if oldSettings2 != {}:
154-
raise DeprecationWarning(
155-
"Your configuration uses the namespace mypy_ls, this should be changed to pylsp_mypy"
156-
)
157-
if settings == {}:
158-
settings = oldSettings1
159-
if settings == {}:
160-
settings = oldSettings2
161-
162176
log.info(
163177
"lint settings = %s document.path = %s is_saved = %s",
164178
settings,
@@ -297,7 +311,8 @@ def pylsp_lint(
297311
"end": {"line": 0, "character": 1000},
298312
},
299313
"message": errors,
300-
"severity": 1 if exit_status != 0 else 2, # Error if exited with error or warning.
314+
# Error if exited with error or warning.
315+
"severity": 1 if exit_status != 0 else 2,
301316
}
302317
)
303318

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ classifiers =
1919
python_requires = >= 3.7
2020
packages = find:
2121
install_requires =
22-
python-lsp-server
22+
python-lsp-server >=1.7.0
2323
mypy
2424
toml
2525

0 commit comments

Comments
 (0)