Skip to content

Instantly share code, notes, and snippets.

@erickgnavar
Forked from sophiajt/emacs_rls.md
Created February 16, 2018 20:59
Show Gist options
  • Save erickgnavar/72f608b9e3b4765a024e704672e2cdbb to your computer and use it in GitHub Desktop.
Save erickgnavar/72f608b9e3b4765a024e704672e2cdbb to your computer and use it in GitHub Desktop.

Installing RLS support in Emacs

I tried this successfully with Emacs 25. It may also work with earlier versions.

Once installed, I opened my project with the dired/open directory feature, and then navigated to my .rs file.

Here's my resulting .emacs file:

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)

(add-to-list 'load-path "/home/jonathan/Source/markdown-mode")
(add-to-list 'load-path "/home/jonathan/Source/lsp-rust")
(add-to-list 'load-path "/home/jonathan/Source/lsp-mode")
(with-eval-after-load 'lsp-mode
    (require 'lsp-flycheck))
(require 'lsp-mode)

(add-to-list 'load-path "/home/jonathan/Source/rust-mode/")
(autoload 'rust-mode "rust-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))

(add-hook 'rust-mode-hook #'lsp-rust-enable)
(add-hook 'rust-mode-hook #'flycheck-mode)

(lsp-define-stdio-client
 ;; This can be a symbol of your choosing. It will be used as a the
 ;; prefix for a dynamically generated function "-enable"; in this
 ;; case: lsp-prog-major-mode-enable
 lsp-prog-major-mode
 "language-id"
 ;; This will be used to report a project's root directory to the LSP
 ;; server.
 (lambda () default-directory)
 ;; This is the command to start the LSP server. It may either be a
 ;; string containing the path of the command, or a list wherein the
 ;; car is a string containing the path of the command, and the cdr
 ;; are arguments to that command.
 '("/home/jonathan/.cargo/bin/rls"))

;; Here we'll add the function that was dynamically generated by the
;; call to lsp-define-stdio-client to the major-mode hook of the
;; language we want to run it under.
;;
;; This function will turn lsp-mode on and call the command given to
;; start the LSP server.
(add-hook 'prog-major-mode #'lsp-prog-major-mode-enable)
(with-eval-after-load 'lsp-mode
  (setq lsp-rust-rls-command '("rustup" "run" "nightly" "rls"))
  (require 'lsp-rust))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment