VSCodeのRustまわりの環境を見直した
- #rust #vscode
最近VSCode用のRust設定を見直していたが、暫定的なものとして下記の設定に落ち着いた
VSCodeのsettings.json
より一部引用
/* --------------------------------- */
// Rustの設定
/* --------------------------------- */
"[rust]": {
"editor.tabSize": 4,
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true,
"editor.inlayHints.enabled": "offUnlessPressed",
},
/* -----------------------------------
// rust-analyzer設定(フォーマッター)
----------------------------------- */
"rust-analyzer.rustfmt.rangeFormatting.enable": true,
/* Default版のrustfmt */
// "rust-analyzer.rustfmt.extraArgs": ["--edition", "2021"],
/* Nightly版のrustfmt */
"rust-analyzer.rustfmt.overrideCommand": ["rustup", "run", "nightly", "rustfmt", "--unstable-features"],
/* -----------------------------------
// rust-analyzer設定(リンター)
----------------------------------- */
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.extraArgs": ["--", "-A", "clippy::needless_return"],
ちなみにこちらが現在のrustfmt.toml
## stable
# edition = "2015"
tab_spaces = 4
max_width = 160
chain_width = 160
match_block_trailing_comma = true
use_small_heuristics = "Max"
single_line_if_else_max_width = 160
single_line_let_else_max_width = 160
short_array_element_width_threshold = 10
## unstable
unstable_features = true
# indent_style = "Visual"
brace_style = "PreferSameLine"
match_arm_blocks = false
fn_single_line = true
where_single_line = true
struct_lit_single_line = true
struct_field_align_threshold = 20
enum_discrim_align_threshold = 20
Nightly版のrustfmt
を使うとunstable
なオプションが利用できて便利だなと思う
特に、1行メソッドやwhere
節などを無理やり改行されてしまうことが防げるのは大きいなと