Skip to content

Commit adc5a99

Browse files
committed
Add 'dmypy_log_file' option to store daemon output to a file
This may be useful to diagnose issues in the daemon itself, for example when it crashes due to an internal error.
1 parent 738aed0 commit adc5a99

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ Configuration
5555
- ``array`` of (``string`` items or ``true``)
5656
- **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.
5757
- ``[true]``
58+
* - ``dmypy_log_file``
59+
- ``pylsp.plugins.pylsp_mypy.dmypy_log_file``
60+
- ``string``
61+
- **Specifies a path for dmypy logs**. This modifies the ``--log-file`` option passed to ``dmypy`` given ``dmypy`` is active.
62+
- ``None``
5863
* - ``dmypy_status_file``
5964
- ``pylsp.plugins.pylsp_mypy.dmypy_status_file``
6065
- ``string``

pylsp_mypy/plugin.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def get_diagnostics(
298298
live_mode = False
299299

300300
if dmypy:
301+
dmypy_log_file = settings.get("dmypy_log_file")
301302
dmypy_status_file = settings.get("dmypy_status_file", ".dmypy.json")
302303

303304
args = ["--show-error-end", "--no-error-summary", "--no-pretty"]
@@ -404,13 +405,16 @@ def get_diagnostics(
404405
mypy_api.run_dmypy(["--status-file", dmypy_status_file, "restart"])
405406

406407
# run to use existing daemon or restart if required
407-
args = ["--status-file", dmypy_status_file, "run", "--"] + apply_overrides(args, overrides)
408+
runargs = ["--status-file", dmypy_status_file, "run"]
409+
if dmypy_log_file is not None:
410+
runargs += ["--log-file", dmypy_log_file]
411+
runargs += ["--"] + apply_overrides(args, overrides)
408412
if dmypy_command:
409413
# dmypy exists on PATH or was provided by settings
410414
# -> use this dmypy
411-
log.info("dmypy run args = %s via path", args)
415+
log.info("dmypy run args = %s via path", runargs)
412416
completed_process = subprocess.run(
413-
[*dmypy_command, *args], capture_output=True, **windows_flag, encoding="utf-8"
417+
[*dmypy_command, *runargs], capture_output=True, **windows_flag, encoding="utf-8"
414418
)
415419
report = completed_process.stdout
416420
errors = completed_process.stderr
@@ -419,8 +423,8 @@ def get_diagnostics(
419423
# dmypy does not exist on PATH and was not provided by settings,
420424
# but must exist in the env pylsp-mypy is installed in
421425
# -> use dmypy via api
422-
log.info("dmypy run args = %s via api", args)
423-
report, errors, exit_status = mypy_api.run_dmypy(args)
426+
log.info("dmypy run args = %s via api", runargs)
427+
report, errors, exit_status = mypy_api.run_dmypy(runargs)
424428

425429
log.debug("report:\n%s", report)
426430
log.debug("errors:\n%s", errors)

0 commit comments

Comments
 (0)