Skip to content

Commit

Permalink
Per #803: Change Rust language server to rust-analyzer
Browse files Browse the repository at this point in the history
rust-analyzer is the officially blessed Language Server for Rust:
rust-lang/rfcs#2912

Also drop the special support code for RLS.

* eglot.el (eglot-server-programs): Add rust-mode language server
"rust-analyzer" and prefer it to the older "rls".
(eglot-rls, jsonrpc-connection-ready-p)
(eglot-handle-notification): Delete special support for "rls".

* eglot-tests.el (rls-analyzer-watches-files)
(rls-analyzer-hover-after-edit): Rename to ...
(rust-analyzer-watches-files)
(rust-analyzer-hover-after-edit): ... this.  Update tests to work
with rust-analyzer.
* README.md: Update references for RLS to point to rust-analyzer.
* NEWS.md: Announce above change.
  • Loading branch information
skangas committed Jan 17, 2022
1 parent e5cea1f commit 8ee2179
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ unnecessary code" or "deprecated or obsolete code". Following the
rendering suggestions in the protocol, we fade out unnecessary code
and strike-through deprecated code.

##### The Rust language server is now rust-analyzer by default ([#803][github#803])
Eglot will now prefer starting "rust-analazyer" to "rls" when it is
available. The special support code for RLS has been removed.

##### New servers have been added to `eglot-server-programs`
- racket-langserver ([#694][github#694])

Expand Down Expand Up @@ -327,3 +331,4 @@ and now said bunch of references-->
[github#769]: https://github.com/joaotavora/eglot/issues/769
[github#787]: https://github.com/joaotavora/eglot/issues/787
[github#794]: https://github.com/joaotavora/eglot/issues/794
[github#803]: https://github.com/joaotavora/eglot/issues/803
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ find-library` can help you tell if that happened.
* R's [languageserver][r-languageserver]
* Racket's [racket-langserver][racket-langserver]
* Ruby's [solargraph][solargraph]
* Rust's [rls][rls]
* Rust's [rust-analyzer][rust-analyzer]
* Scala's [metals][metals]
* TeX/LaTeX's [Digestif][digestif]
* VimScript's [vim-language-server][vim-language-server]
Expand Down Expand Up @@ -467,7 +467,7 @@ User-visible differences:
connection name;
- Pretty interactive mode-line section for live tracking of server
communication;
- Automatically restarts frequently crashing servers (like RLS);
- Automatically restarts frequently crashing servers;
- Slow-to-start servers start asynchronously in the background;
- Server-initiated edits are confirmed with the user;
- Diagnostics work out-of-the-box (no `flycheck.el` needed);
Expand Down Expand Up @@ -517,7 +517,7 @@ Under the hood:
[r-languageserver]: https://cran.r-project.org/package=languageserver
[racket-langserver]: https://github.com/jeapostrophe/racket-langserver
[solargraph]: https://github.com/castwide/solargraph
[rls]: https://github.com/rust-lang-nursery/rls
[rust-analyzer]: https://github.com/rust-analyzer/rust-analyzer
[metals]: https://scalameta.org/metals/
[digestif]: https://github.com/astoff/digestif
[vim-language-server]: https://github.com/iamcco/vim-language-server
Expand Down
12 changes: 6 additions & 6 deletions eglot-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ Pass TIMEOUT to `eglot--with-timeout'."
(while (process-live-p proc) (accept-process-output nil 0.5)))
(should (not (eglot-current-server)))))))

(ert-deftest rls-watches-files ()
"Start RLS server. Notify it when a critical file changes."
(skip-unless (executable-find "rls"))
(ert-deftest rust-analyzer-watches-files ()
"Start rust-analyzer. Notify it when a critical file changes."
(skip-unless (executable-find "rust-analyzer"))
(skip-unless (executable-find "cargo"))
(let ((eglot-autoreconnect 1))
(eglot--with-fixture
Expand Down Expand Up @@ -467,9 +467,9 @@ Pass TIMEOUT to `eglot--with-timeout'."
do (sit-for 0.5)
finally (error "eglot--tests-force-full-eldoc didn't deliver")))

(ert-deftest rls-hover-after-edit ()
"Hover and highlightChanges are tricky in RLS."
(skip-unless (executable-find "rls"))
(ert-deftest rust-analyzer-hover-after-edit ()
"Hover and highlightChanges."
(skip-unless (executable-find "rust-analyzer"))
(skip-unless (executable-find "cargo"))
(eglot--with-fixture
'(("hover-project" .
Expand Down
21 changes: 1 addition & 20 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ chosen (interactively or automatically)."
when probe return (cons probe args)
finally (funcall err)))))))

(defvar eglot-server-programs `((rust-mode . (eglot-rls "rls"))
(defvar eglot-server-programs `((rust-mode . ("rust-analyzer" "rls"))
(cmake-mode . ("cmake-language-server"))
(vimrc-mode . ("vim-language-server" "--stdio"))
(python-mode
Expand Down Expand Up @@ -2984,25 +2984,6 @@ If NOERROR, return predicate, else erroring function."
(when (eq ?! (aref arg 1)) (aset arg 1 ?^))
`(,self () (re-search-forward ,(concat "\\=" arg)) (,next)))


;;; Rust-specific
;;;
(defclass eglot-rls (eglot-lsp-server) () :documentation "Rustlang's RLS.")

(cl-defmethod jsonrpc-connection-ready-p ((server eglot-rls) what)
"Except for :completion, RLS isn't ready until Indexing done."
(and (cl-call-next-method)
(or ;; RLS normally ready for this, even if building.
(eq :textDocument/completion what)
(pcase-let ((`(,_id ,what ,done ,_detail) (eglot--spinner server)))
(and (equal "Indexing" what) done)))))

(cl-defmethod eglot-handle-notification
((server eglot-rls) (_method (eql window/progress))
&key id done title message &allow-other-keys)
"Handle notification window/progress."
(setf (eglot--spinner server) (list id title done message)))


;;; eclipse-jdt-specific
;;;
Expand Down

1 comment on commit 8ee2179

@tsdh
Copy link

@tsdh tsdh commented on 8ee2179 Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skangas @joaotavora Hey, I just wanted to say thanks! It's impressive how much better and accurate completions have become due to this switch. :-)

Please sign in to comment.