VSCode formatter extension implementation of docformatter.
Simple extension that implementsdocformatter
as a native VSCode
formatter. The formatter uses
PEP 257 as a guide.
See https://pypi.org/project/docformatter/ for the full feature list. This
extension uses that project as a backend with few modifications.
All relevant flags are implemented as extension settings.
If you already have a Python formatting extension installed, you will need to
pick this one when you want to format a file. In a Python file in VSCode,
ctrl+shift+p to open the command pallette,
run the command Format Document With… and select
Python Docstring Formatter.
To set the default formatter that is run when you run the Format Document,
on Python files, add the following to your settings.json (...
being your other settings):
{
...,
"[python]": {
"editor.defaultFormatter": "iansan5653.format-python-docstrings"
}
}
Note: The Python Docstring Formatter option will only appear for files
that have been saved on disk (ie, not Untitled-# tabs).
Note: The extension will use the Python you have set in python.pythonPath
.
It does not support Python 2, so this must be set to some version of Python 3.
If the setting is empty, the extension will use a global Python installation.
This extension requires pip
and/or the docformatter
module to be installed.
Upon activating, the extension will automatically give the option to runpip install --upgrade docformatter
if necessary. If you prefer to install the
formatter program in another way, you may do so. Just make sure that thedocformatter
command is recognized by your terminal (ie, added to your PATH).
All relevant flags from the original docformatter
program are implemented as
settings:
docstringFormatter.wrapSummariesLength
(number
, default 79
): Wrap long0
to disable wrapping.docstringFormatter.wrapDescriptionsLength
(number
, default 72
): Wrap0
to disable wrapping.docstringFormatter.preSummaryNewline
(boolean
, default false
): Add adocstringFormatter.makeSummaryMultiline
(boolean
, default false
): Add adocstringFormatter.forceWrap
(boolean
, default false
): ForceSee CHANGELOG.md for release notes.
Before contributing, you will need to install
Node.js (with NPM) (and Visual Studio Code, of course).
Clone the repository and install the required dependencies by runningnpm install
in a terminal in the new directory. All extension logic is insrc/extension.ts
. Whenever modifying extension behavior, be sure to update and
add unit tests in src/test/extension.test.ts
. To run/test the extension,
simply use the debugger in VSCode after opening the extension folder.