Doom-emacs: [HOWTO] rust-analyzer not working

Created on 15 Dec 2019  Â·  8Comments  Â·  Source: hlissner/doom-emacs

I am trying to install the rust-analyzer
I'm trying to install rust-analyzer but when I'm open rust buffer this message writes on bottom.
Server rls:20735 status:starting exited with status exit. Do you want to restart it? (y or n)
if I press y the number(20735) increase 1, every time. Also, the number(20735) different every time I open rust buffer.

I have done so far

  • I uncomment lsp on .doom.d/init.el
  • add +lsp to rust on .doom.d/init.el
  • cloned the rust-analyzer repo and installed
    git clone https://github.com/rust-analyzer/rust-analyzer && cd rust-analyzer cargo xtask install --server

    • installed these components

    • rustfmt-preview

    • cargo-check

    • clippy-preview

    • rust-src

    • and added these line to .doom.d/config.el

      (after! rustic (setq rustic-lsp-server 'rust-analyzer))

Additional information
ra_lsp_server on my path but when I run ra_lsp_server on my shell it's write to output nothing,
so I'm not sure that if it installed correctly or not.

System information


((emacs
(version . "26.3")
(features . "XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD LCMS2")
(build . "Aug 29, 2019")
(buildopts "--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-modules 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now")
(windowsys . batch)
(daemonp . server-running))
(doom
(version . "2.0.9")
(build . "HEAD -> develop 721b63547 2019-12-15 02:17:40 -0500"))
(system
(type . gnu/linux)
(config . "x86_64-pc-linux-gnu")
(shell . "/usr/bin/zsh")
(uname . "Linux 5.4.3-arch1-1 #1 SMP PREEMPT Fri, 13 Dec 2019 09:39:02 +0000 x86_64")
(path "~/.cargo/bin" "/usr/local/bin" "/usr/bin" "/bin" "/usr/local/sbin" "/usr/bin/site_perl" "/usr/bin/vendor_perl" "/usr/bin/core_perl" "/usr/lib/emacs/26.3/x86_64-pc-linux-gnu"))
(config
(envfile . envvar-file)
(elc-files . 0)
(modules :completion company ivy :ui doom doom-dashboard doom-quit hl-todo modeline nav-flash ophints (popup +all +defaults) vc-gutter vi-tilde-fringe window-select workspaces :editor (evil +everywhere) file-templates fold multiple-cursors rotate-text snippets :emacs dired electric ibuffer vc :tools (eval +overlay) flycheck (lookup +docsets) lsp magit :lang data emacs-lisp markdown (org +dragndrop +ipython +pandoc +present) (rust +lsp) sh :config (default +bindings +smartparens))
(packages "n/a")
(elpa "n/a")))

:lang rust :tools lsp question resolved

Most helpful comment

FYI, I recently had trouble getting rust-analyzer to work and the OPs steps helped me out. The problem I ran into though was that lsp-rust-server was being overwritten and I couldn't debug where that was happening.
That is, with (setq lsp-rust-server 'rust-analyzer) I would see lsp-rust-server == rust-analyer on startup (emacs &). However, after opening a Rust buffer, it would be changed to lsp-rust-server == rls.
In the end, I found that (setq rustic-lsp-server 'rust-analyzer) ;; $DOOMDIR/config.el would connect to rust-analyzer for all Rustic buffers.

All 8 comments

I just installed rls using rustup component add rls command and now completion is working but I guess it's not using rust-analyzer but rls even (setq rustic-lsp-server 'rust-analyzer)) in my config.el . How can I be sure which one is in use, rls or rust analyzer.

Use this instead:

(after! lsp-rust
  (setq lsp-rust-server 'rust-analyzer))

Doom now uses the lsp support built into lsp-mode, not the one built into rustic. I've just updated the README to reflect this.

Tried this

(after! lsp-rust
  (setq lsp-rust-server 'rust-analyzer))

but still when I open rust buffer this: LSP :: rls:2915 initialized successfullywrites at bottom. and M-x lsp-rust-analyzer-status says rust-analyzer not running

when I run ra_lsp_server --version on shell, it prints this: rust-analyzer ff8f805
I guess rust analyzer installed correctly but emacs not using it.

On this page it says emacs need dash and ht package and load this file. Should I do this by myself or doom emacs did it already for me?

You don't need to install it's dependencies, no. Try this instead:

(setq lsp-rust-server 'rust-analyzer)

Yes, this:

(setq lsp-rust-server 'rust-analyzer)

or this:

(after! rustic
  (setq lsp-rust-server 'rust-analyzer))

solve the problem, now emacs use rust analyzer instead of rls. Thank you.

I kept rustic-lsp-server because it is supposed to also work with eglot. Maybe this should also be mentioned for eglot users.

@brotzeit Done.

FYI, I recently had trouble getting rust-analyzer to work and the OPs steps helped me out. The problem I ran into though was that lsp-rust-server was being overwritten and I couldn't debug where that was happening.
That is, with (setq lsp-rust-server 'rust-analyzer) I would see lsp-rust-server == rust-analyer on startup (emacs &). However, after opening a Rust buffer, it would be changed to lsp-rust-server == rls.
In the end, I found that (setq rustic-lsp-server 'rust-analyzer) ;; $DOOMDIR/config.el would connect to rust-analyzer for all Rustic buffers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vvkmnn picture Vvkmnn  Â·  3Comments

rgrinberg picture rgrinberg  Â·  3Comments

governorgoat picture governorgoat  Â·  3Comments

pieterdd picture pieterdd  Â·  3Comments

Ptival picture Ptival  Â·  3Comments