Skip to content
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

rust-analyzer no longer supports workspace/executeCommand #1890

Closed
leotaku opened this issue Jul 7, 2020 · 8 comments
Closed

rust-analyzer no longer supports workspace/executeCommand #1890

leotaku opened this issue Jul 7, 2020 · 8 comments
Assignees

Comments

@leotaku
Copy link

leotaku commented Jul 7, 2020

Describe the bug
When trying to apply a code action using lsp-execute-code-action using a recent version of rust-analyzer, the command fails with the following error message:

The connected server(s) does not support method workspace/executeCommand
To find out what capabilities support your server use ‘M-x lsp-describe-session’ and expand the capabilities section.

To Reproduce

  1. Install rustup rustup 1.21.1
  2. Install a nightly Rust toolchain using rustup. cargo 1.46.0-nightly
  3. Install rust-analyzer using cargo rust-analyzer 36840bd
  4. Load the following code in a clean Emacs instance. (Ensure that you have either set CARGO_HOME, or replace it with your OS's default location)
Click to expand!
(require 'package)

(setq debug-on-error t)

(let* ((package-archives '(("melpa" . "https://melpa.org/packages/")
                           ("gnu" . "https://elpa.gnu.org/packages/")))
       (no-byte-compile t)
       (package-user-dir (expand-file-name (make-temp-name "lsp-tmp-elpa")
                                           user-emacs-directory))
       (custom-file (expand-file-name "custom.el" package-user-dir))
       (pkg-list '(rust-mode lsp-mode lsp-ui yasnippet lsp-java lsp-python-ms lsp-haskell helm-lsp lsp-treemacs dap-mode lsp-origami lsp-dart company flycheck)))

  (package-initialize)
  (package-refresh-contents)

  (mapcar (lambda (pkg)
            (unless (package-installed-p pkg)
              (package-install pkg))
            (require pkg))
          pkg-list)

  (yas-global-mode)
  (add-hook 'prog-mode-hook 'lsp)
  (add-hook 'kill-emacs-hook `(lambda ()
                                (delete-directory ,package-user-dir t))))

(setq lsp-rust-server 'rust-analyzer)
(setq lsp-rust-analyzer-server-command
      (concat (getenv "CARGO_HOME") "/bin/rust-analyzer"))
  1. Open any Rust file that is part of a cargo project.
  2. Try running lsp-execute-code-action where a code action is advertised

Expected behavior

It would be unreasonable to expect this to work as rust-analyzer has lost support for workspace/executeCommand quite a while ago. (rust-analyzer/#1232)

I would argue that lsp-mode should support the server-specific rust-analyzer.applySourceChange capability, as other client implementations (vim, kakoune) already do the same. Though I realize that this could represent additional maintenance burden. (@brotzeit and @kurnevsky, what do you think?)

I also think that as long as we do not support applying the changes suggested by rust-analyzer they should not be by suggested as part of the modeline, lsp-ui or the lsp-execute-code-action minibuffer selection.

Which Language Server did you use

lsp-rust with rust-analyzer

OS
NixOS Linux 20.09pre-git (Nightingale)

@yyoncho yyoncho self-assigned this Jul 7, 2020
@yyoncho
Copy link
Member

yyoncho commented Jul 7, 2020

I will do a fix.

@yyoncho
Copy link
Member

yyoncho commented Jul 7, 2020

@leotaku can you give an example for code action that does not work? I tested a few and they seems to work fine when using this version: https://github.com/rust-analyzer/rust-analyzer/releases/tag/2020-07-06

@leotaku
Copy link
Author

leotaku commented Jul 7, 2020

Sure, all code actions I tried seemed to fail, so I did not specify one.

  • Add #[derive]
  • Add default constructor

These are advertised for all structs and should be easy to reproduce.

@yyoncho
Copy link
Member

yyoncho commented Jul 7, 2020

Sorry, I am not using rust on day to day basis, can you provide sample file to reproduce the issue?

@flodiebold
Copy link
Contributor

rust-analyzer.applySourceChange is not needed by current rust-analyzer versions. Try updating your rust-analyzer (the commit you reference is 3 months old).

@leotaku
Copy link
Author

leotaku commented Jul 7, 2020

@flodiebold is correct, I did not have an up-to-date version of rust-analyzer installed. I honestly did not give it much thought, as I did not see any newer PRs/commits referencing the issue in rust-analyzer but saw very recent commits in e.g. kak-lsp that indicate they had to use custom logic.

@flodiebold do you by any chance have a link to the issue where this new development is discussed? Is there any reason to still support rust-analyzer.applySourceChange?

@yyoncho Thanks for trying to step in so quickly! I am sorry for any confusion caused by my issue.

@flodiebold
Copy link
Contributor

flodiebold commented Jul 7, 2020

No, there's no reason to support applySourceChange anymore. It was removed as part of an effort to move to extensions that can potentially be upstreamed to the protocol, which you can read about here.

(Note that lsp-mode used to have support for applySourceChange. I removed it, because it's not needed anymore.)

@leotaku
Copy link
Author

leotaku commented Jul 7, 2020

Thanks @flodiebold. In that case I think it makes sense to just close this issue.

@leotaku leotaku closed this as completed Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants