Skip to content

Commit edec6f6

Browse files
authored
Fix logic for rust-analyzer.checkOnSave.features setting inheritance (#4542)
The rust-analyzer inherits the setting of `rust-analyzer.checkOnSve.features` from `rust-analyzer.cargo.features` by default, but the elisp code here was incorrectly defaulting the former to the empty list, regardless of the value of the latter. The effect was that `rust-analyzer.cargo.features` disabled warnings about "inactive code", without actually turning on type checking of that code!
1 parent dd61303 commit edec6f6

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

CHANGELOG.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Add support for C# via the [[https://github.com/dotnet/roslyn/tree/main/src/LanguageServer][Roslyn language server]].
1010
* Add basic support for [[https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics][pull diagnostics]] requests.
1111
* Add ~lsp-flush-delayed-changes-before-next-message~ customization point to enforce throttling document change notifications.
12+
* Fix bug in ~rust-analyzer.check.features~ configuration via ~lsp-rust-checkonsave-features~ Emacs setting: we were defaulting to ~[]~, but ~rust-analyzer~ defaults to inheriting the value from ~rust-analyzer.cargo.features~. The bug resulted in code hidden behind features not getting type checked when those features were enabled by setting ~rust-analyzer.cargo.features~ via the ~lsp-rust-features~ Emacs setting.
1213

1314
** 9.0.0
1415
* Add language server config for QML (Qt Modeling Language) using qmlls.

clients/lsp-rust.el

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ the latest build duration."
187187

188188
(defcustom lsp-rust-features []
189189
"List of features to activate.
190+
Corresponds to the `rust-analyzer` setting `rust-analyzer.cargo.features`.
190191
Set this to `\"all\"` to pass `--all-features` to cargo."
191192
:type 'lsp-string-vector
192193
:group 'lsp-rust-rls
@@ -596,9 +597,15 @@ The command should include `--message=format=json` or similar option."
596597
:group 'lsp-rust-analyzer
597598
:package-version '(lsp-mode . "8.0.2"))
598599

599-
(defcustom lsp-rust-analyzer-checkonsave-features []
600+
(defcustom lsp-rust-analyzer-checkonsave-features nil
600601
"List of features to activate.
601-
Set this to `\"all\"` to pass `--all-features` to cargo."
602+
Corresponds to the `rust-analyzer` setting `rust-analyzer.check.features`.
603+
When set to `nil` (default), the value of `lsp-rust-features' is inherited.
604+
Set this to `\"all\"` to pass `--all-features` to cargo.
605+
Note: setting this to `nil` means \"unset\", whereas setting this
606+
to `[]` (empty vector) means \"set to empty list of features\",
607+
which overrides any value that would otherwise be inherited from
608+
`lsp-rust-features'."
602609
:type 'lsp-string-vector
603610
:group 'lsp-rust-rust-analyzer
604611
:package-version '(lsp-mode . "8.0.2"))
@@ -1666,11 +1673,22 @@ https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.m
16661673
:merge (:glob ,(lsp-json-bool lsp-rust-analyzer-imports-merge-glob))
16671674
:prefix ,lsp-rust-analyzer-import-prefix)
16681675
:lruCapacity ,lsp-rust-analyzer-lru-capacity
1676+
;; This `checkOnSave` is called `check` in the `rust-analyzer` docs, not
1677+
;; `checkOnSave`, but the `rust-analyzer` source code shows that both names
1678+
;; work. The `checkOnSave` name has been supported by `rust-analyzer` for a
1679+
;; long time, whereas the `check` name was introduced here in 2023:
1680+
;; https://github.com/rust-lang/rust-analyzer/commit/d2bb62b6a81d26f1e41712e04d4ac760f860d3b3
16691681
:checkOnSave ( :enable ,(lsp-json-bool lsp-rust-analyzer-cargo-watch-enable)
16701682
:command ,lsp-rust-analyzer-cargo-watch-command
16711683
:extraArgs ,lsp-rust-analyzer-cargo-watch-args
16721684
:allTargets ,(lsp-json-bool lsp-rust-analyzer-check-all-targets)
1673-
:features ,lsp-rust-analyzer-checkonsave-features
1685+
;; We need to distinguish between setting this to the empty
1686+
;; vector, and not setting it at all, which `rust-analyzer`
1687+
;; interprets as "inherit from
1688+
;; `rust-analyzer.cargo.features`". We use `nil` to mean
1689+
;; "unset".
1690+
,@(when (vectorp lsp-rust-analyzer-checkonsave-features)
1691+
`(:features ,lsp-rust-analyzer-checkonsave-features))
16741692
:overrideCommand ,lsp-rust-analyzer-cargo-override-command)
16751693
:highlightRelated ( :breakPoints (:enable ,(lsp-json-bool lsp-rust-analyzer-highlight-breakpoints))
16761694
:closureCaptures (:enable ,(lsp-json-bool lsp-rust-analyzer-highlight-closure-captures))

0 commit comments

Comments
 (0)