python - VS Code 和 Python,isort 没有做好它的工作
问题描述
我已经在 VS Code 中安装black
并isort
用于代码格式化。黑色有效,而isort
似乎无效。
如果我从命令行运行isort
没有问题。
我试过修改setting.json
无济于事。这是最新版本:
{
"window.zoomLevel": 0,
/** "editor.codeActionsOnSave": null */
/** Enable format on save */
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
/** Pyformat use it's own code action to prevent confliction with other tools. */
"source.organizeImports.pyformat": true,
"source.organizeImports.python": true
},
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.languageServer": "Pylance",
/** "python.sortImports.path": "isort", */
"python.sortImports.args": [
"-m 3",
"-tc",
"-w 88"
],
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length=88"
],
...
有什么建议么?
解决方案
VS Code 一次只支持使用一个格式化程序。但是,此答案中描述了一种解决方法:
const firstFormatter = commands.executeCommand('editor.action.formatDocument');
firstFormatter.then(() => myFormat());
我个人将其配置为使用黑色,然后附加命令以运行第二个。
推荐阅读
- c - C程序打印换行符
- visual-studio-2017 - Fortran 间歇性类型错误
- java - 使用 logback 停用 AWS Lambda Cloudwatch 上的调试日志记录
- javascript - 如何使用 node-module-version 57 安装 node-opus
- regex - 正则表达式返回括号之间有 1 个或多个句点的文本
- android - 除非用户使用 100VH 滚动,否则 Android Chrome 上的 URL 栏会隐藏全高内容
- python-3.x - 在 python 3 中编辑列表的元素
- hive - Hive——改变分区格式
- rust - 在构建脚本中获取当前版本的方法?
- zurb-foundation - Zurb Foundation 5 Reveal 滚动内容?