0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Zed】formatterの設定方法

Posted at

設定方法

Language Serverを使用

{
  "formatter": "language_server"
}

外部コマンドを使用

標準入力からテキストを受け取り、標準出力にフォーマット結果を出力するコマンドを指定します。

{
  "formatter": {
    "external": {
      "command": "sed",
      "arguments": ["-e", "s/ *$//"]
    }
  }
}

ファイルパスのプレースホルダー

{buffer_path}を使うと、フォーマッタにファイルパスを渡せます(Prettierなどで有用)。

{
  "formatter": {
    "external": {
      "command": "prettier",
      "arguments": ["--stdin-filepath", "{buffer_path}"]
    }
  }
}

注意: {buffer_path}はファイル読み込み用ではなく、フォーマッタへの情報提供用です。

Code Actionを使用

v0.208.4以降

{
  "formatter": [
    { "code_action": "source.fixAll.eslint" },
    { "code_action": "source.organizeImports" }
  ]
}

旧形式

{
  "code_actions": {
    "source.organizeImports": true,
    "source.fixAll": true
  }
}

複数のフォーマッタを順次実行

配列で指定すると、上から順に実行されます。いずれかが失敗しても後続は実行されます。

{
  "formatter": [
    { "language_server": { "name": "rust-analyzer" } },
    {
      "external": {
        "command": "sed",
        "arguments": ["-e", "s/ *$//"]
      }
    }
  ]
}

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?