Skip to content

Commit

Permalink
Fix logic for rust-analyzer.checkOnSave.features setting inheritance
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
ntc2 committed Sep 9, 2024
1 parent dd61303 commit 9d95db2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Add support for C# via the [[https://github.com/dotnet/roslyn/tree/main/src/LanguageServer][Roslyn language server]].
* Add basic support for [[https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics][pull diagnostics]] requests.
* Add ~lsp-flush-delayed-changes-before-next-message~ customization point to enforce throttling document change notifications.
* 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.

** 9.0.0
* Add language server config for QML (Qt Modeling Language) using qmlls.
Expand Down
21 changes: 18 additions & 3 deletions clients/lsp-rust.el
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ the latest build duration."

(defcustom lsp-rust-features []
"List of features to activate.
Corresponds to the `rust-analyzer` setting `rust-analyzer.cargo.features`.
Set this to `\"all\"` to pass `--all-features` to cargo."
:type 'lsp-string-vector
:group 'lsp-rust-rls
Expand Down Expand Up @@ -596,9 +597,12 @@ The command should include `--message=format=json` or similar option."
:group 'lsp-rust-analyzer
:package-version '(lsp-mode . "8.0.2"))

(defcustom lsp-rust-analyzer-checkonsave-features []
(defcustom lsp-rust-analyzer-checkonsave-features nil
"List of features to activate.
Set this to `\"all\"` to pass `--all-features` to cargo."
Corresponds to the `rust-analyzer` setting `rust-analyzer.check.features`.
When set to `nil` (default), the value of `lsp-rust-features' is inherited.
Set this to `\"all\"` to pass `--all-features` to cargo.
Note: setting this to `nil` means \"unset\", whereas setting this to `[]` (empty vector) means \"set to empty list of features\", which overrides any value that would otherwise be inherited from `lsp-rust-features'."
:type 'lsp-string-vector
:group 'lsp-rust-rust-analyzer
:package-version '(lsp-mode . "8.0.2"))
Expand Down Expand Up @@ -1666,11 +1670,22 @@ https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.m
:merge (:glob ,(lsp-json-bool lsp-rust-analyzer-imports-merge-glob))
:prefix ,lsp-rust-analyzer-import-prefix)
:lruCapacity ,lsp-rust-analyzer-lru-capacity
;; This `checkOnSave` is called `check` in the `rust-analyzer` docs, not
;; `checkOnSave`, but the `rust-analyzer` source code shows that both names
;; work. The `checkOnSave` name has been supported by `rust-analyzer` for a
;; long time, whereas the `check` name was introduced here in 2023:
;; https://github.com/rust-lang/rust-analyzer/commit/d2bb62b6a81d26f1e41712e04d4ac760f860d3b3
:checkOnSave ( :enable ,(lsp-json-bool lsp-rust-analyzer-cargo-watch-enable)
:command ,lsp-rust-analyzer-cargo-watch-command
:extraArgs ,lsp-rust-analyzer-cargo-watch-args
:allTargets ,(lsp-json-bool lsp-rust-analyzer-check-all-targets)
:features ,lsp-rust-analyzer-checkonsave-features
;; We need to distinguish between setting this to the empty
;; vector, and not setting it at all, which `rust-analyzer`
;; interprets as "inherit from
;; `rust-analyzer.cargo.features`". We use `nil` to mean
;; "unset".
,@(when (vectorp lsp-rust-analyzer-checkonsave-features)
`(:features ,lsp-rust-analyzer-checkonsave-features))
:overrideCommand ,lsp-rust-analyzer-cargo-override-command)
:highlightRelated ( :breakPoints (:enable ,(lsp-json-bool lsp-rust-analyzer-highlight-breakpoints))
:closureCaptures (:enable ,(lsp-json-bool lsp-rust-analyzer-highlight-closure-captures))
Expand Down

0 comments on commit 9d95db2

Please sign in to comment.