-
-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for setting cargo features via rust-analyzer.cargo.features #3375
Comments
It's probably a little hard to find it in this case. :cargo (:allFeatures ,(lsp-json-bool lsp-rust-all-features)
:noDefaultFeatures ,(lsp-json-bool lsp-rust-no-default-features)
:features ,lsp-rust-features I think you are looking for |
Thanks @brotzeit ! Yes looks like it works. Here is what I do:
I'll have to see how to simplify this process, but that's already great. |
You can use |
I mean more something like a function that permits to edit the variable to easily add or remove features and that would automatically restart rust-analyzer (or if it's possible to push the config, it's even better). But for that I'll need to learn elisp again, so it will wait this week-end. |
Have fun ;) Is your question answered ? |
Yes thanks! :-) |
For posterity, here is what I did to edit the features: (defun edit-lsp-rust-features ()
"Edit lsp-rust-features."
(interactive)
(setq lsp-rust-features
(read-minibuffer "Features? " (format "%S" lsp-rust-features)))) I wasn't able to call
Thanks again for pointing me out to |
@ia0 FYI there is M-x customize-variable |
Yes I've seen this too, but it's very unconvenient to use. The cursor is not directly on the old value and Enter doesn't change the value. You need to click |
Another take on @ia0 function, I find more convenient to just type (defun edit-lsp-rust-features ()
"Edit lsp-rust-features."
(interactive)
(setq lsp-rust-features
(let ((current-features (mapconcat 'identity lsp-rust-features ",")))
(vconcat (s-split "," (read-string "Features? " current-features)))))) |
Thanks @yorodm ! I was actually having issues when typing multiple features today that I had to update the prompt to remind me that the syntax is |
I modified it a bit to correctly map the empty string to the empty vector: (defun edit-lsp-rust-features ()
"Edit lsp-rust-features."
(interactive)
(let ((old-features (mapconcat 'identity lsp-rust-features ",")))
(let ((new-features (read-string "Features? " old-features)))
(setq lsp-rust-features (vconcat (split-string new-features "," t)))))) |
For posterity, I improved the command to support (defun edit-lsp-rust-features ()
"Edit lsp-rust-features and lsp-rust-no-default-features."
(interactive)
(let ((old-features (mapconcat 'identity lsp-rust-features ",")))
(when lsp-rust-no-default-features
(setq old-features (concat "=" old-features)))
(let ((new-features (read-string "Features? " old-features)))
(setq lsp-rust-no-default-features (string-prefix-p "=" new-features))
(if lsp-rust-no-default-features (aset new-features 0 ?,))
(setq lsp-rust-features (vconcat (split-string new-features "," t)))))) The syntax is an optional
|
I'm trying to get this working at the moment but I just get @yyoncho Could lsp-mode provide a high level setting for this similar to VS Code? |
I'm finding that adding a feature to Looking at the part of the code that @brotzeit linked to earlier, I see that it has "features" configs in two places:
It seems that (1) However, it seems that (2) So, perhaps this issue should be reopened? I think a proper resolution would amount to an ergonomic way to get the effect of changing the I'm going to attempt to make the "check" features default to the "cargo" features and submit a PR if I can get that working ... |
I just submitted a PR fixing the bug I mentioned in my last comment. With that PR, the (defun edit-lsp-rust-features ()
"Edit `lsp-rust-features' and `lsp-rust-no-default-features'.
If the first character of input is '=', then
`lsp-rust-no-default-features' is set. Multiple features are
specified by separating them with commas. The value \"all\" is
special and means \"--all-features\"."
(interactive)
(let ((old-features (mapconcat 'identity lsp-rust-features ",")))
(when lsp-rust-no-default-features
(setq old-features (concat "=" old-features)))
(let ((new-features (read-string "Features? " old-features)))
(setq lsp-rust-no-default-features (string-prefix-p "=" new-features))
(if lsp-rust-no-default-features (aset new-features 0 ?,))
(setq lsp-rust-features (vconcat (split-string new-features "," t)))))
(call-interactively 'lsp-workspace-restart)) |
Hi,
I would like to change the list of features that rust-analyzer is using to compile the code (from within emacs, so without changing the default features in the
Cargo.toml
). Searching on internet, it looks like there is somerust-analyzer.cargo.features
configuration for that. But I can't see it in lsp-mode. The closest I see islsp-rust-analyzer-cargo-override-command
but I don't know how to use it.I didn't find any mention of this feature request in the wishlist.
Thanks!
The text was updated successfully, but these errors were encountered: