VSCode拡張: Autoflake - Remove unused Python imports
https://marketplace.visualstudio.com/items?itemName=TrungNgo.autoflake
https://github.com/trungnt13/vscode-autoflake
VSCodeのformatting
を調べていて発見
#autoflake
を使って、不要なimportを取り除く
コマンドパレットのアクションとして追加
これを使わなくても
source.fixAll
をeditor.codeActionOnSaveに指定したらimportを削除した
VSCodeでPythonコードをフォーマッティング
実装
https://github.com/trungnt13/vscode-autoflake/blob/b883f92c977fd601f5bb851bb75ab06083d4ec47/src/extension.ts#L16-L22
autoflakeの設定を読み込む
https://github.com/trungnt13/vscode-autoflake/blob/b883f92c977fd601f5bb851bb75ab06083d4ec47/src/extension.ts#L36-L40
コマンドを組み立て(isortのコマンドと合わせる)
子プロセスでコマンド実行
https://github.com/trungnt13/vscode-autoflake/blob/b883f92c977fd601f5bb851bb75ab06083d4ec47/src/extension.ts#L60
registerTextEditorCommandしている