以下のバージョンで確認しています。
-
- Emacs 26.1
rust-mode 20190304.1336
lsp-mode 20190328.2018
Rust stable
rls 1.33.0
cargo-clippy 0.0.212
rlsの設定項目
rlsは設定を有効にすることで、診断にclippyを含めることができます。
clippy_preferenceという設定項目があります。
デフォルトの値は”opt-in”で、コードに#![warn(clippy::all)]など明記している時のみ有効です。
この値を”on”に変更することで、常時有効になります。
逆に無効にしたい時は”off”を指定します。
clippy_preferenceなど設定の項目は、READMEのconfigurationの節で確認できます。
自前のLSPクライアントを定義する
Emacsでrlsの設定を変更するために、clippy_preferenceを有効にしたLSPクライアントを定義、登録しました。
init.elには以下のように書きます。
(use-package lsp-mode
:commands lsp
:config
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection '("rls"))
:major-modes '(rust-mode)
:priority 0
:server-id 'myrls
:initialized-fn (lambda (workspace)
(with-lsp-workspace workspace (lsp--set-configuration `(:rust (:clippy_preference "on")))))
:notification-handlers (lsp-ht ("window/progress" 'lsp-clients--rust-window-progress)))))
lsp-mode/lsp-clients.elのLSPクライアントの定義を参考にしました。
:initialized-fn …が、rlsと設定のなんやかんやをやってくれる部分です。既存のRust向けLSPクライアントより優先して自前のを使ってもらうよう、:priority 0としています。
ちなみにですが、PythonやGo向けにはLSPサーバ設定用の値が定義されており、custom-set-variablesしておけば、後はよしなにやってくれるようになっています。
他の言語向けも追々同様になるのではないでしょうか……なってくれるといいなあ……
その他の選択肢
rusticというrust-modeのフォークがあります。
rusticはrustic-clippyというflycheckバックエンドをもっており、吊るしでclippyが使えます。