emacs: Configure rust-mode with lsp.

This commit is contained in:
Kevin Baensch 2020-03-23 10:10:31 +01:00
parent ea8739bc21
commit 3cd9d1c77b
Signed by: derped
GPG key ID: C0F1D326C7626543
4 changed files with 14 additions and 12 deletions

View file

@ -7,16 +7,13 @@ mkIf (elem "emacs::lsp" config.machine.pkgs) {
lsp-mode = { lsp-mode = {
enable = true; enable = true;
command = [ "lsp-mode" ]; command = [ "lsp-mode" ];
bind = {
"C-c r r" = "lsp-rename";
"C-c r f" = "lsp-format-buffer";
};
config = '' config = ''
(setq lsp-keymap-prefix "C-c")
(setq lsp-eldoc-render-all nil) (setq lsp-eldoc-render-all nil)
(defvar lsp-language-id-configuration '( (defvar lsp-language-id-configuration '(
${optionalString (elem "emacs::rust" config.machine.pkgs ${optionalString (elem "emacs::rust" config.machine.pkgs)
''(rust-mode . "rust")'')} ''(rust-mode . "rust")''}
)) ))
''; '';
}; };
@ -36,6 +33,7 @@ mkIf (elem "emacs::lsp" config.machine.pkgs) {
lsp-ui-flycheck = { lsp-ui-flycheck = {
enable = true; enable = true;
package = epkgs: [ epkgs.lsp-ui ];
after = [ "lsp-ui" ] after = [ "lsp-ui" ]
++ optional (elem "emacs::flycheck" config.machine.pkgs) "flycheck"; ++ optional (elem "emacs::flycheck" config.machine.pkgs) "flycheck";
}; };

View file

@ -6,7 +6,7 @@ mkIf (elem "emacs::magit" config.machine.pkgs) {
programs.emacs.init.usePackage.magit = { programs.emacs.init.usePackage.magit = {
enable = true; enable = true;
bind = { bind = {
"C-c g" = "magit-status"; "C-c m" = "magit-status";
}; };
}; };
} }

View file

@ -5,9 +5,15 @@ with lib;
mkIf (elem "emacs::rust" config.machine.pkgs) { mkIf (elem "emacs::rust" config.machine.pkgs) {
programs.emacs.init.usePackage.rust-mode = { programs.emacs.init.usePackage.rust-mode = {
enable = true; enable = true;
hook = [ ''(rust-mode . (lambda () (racer-mode)))'' ]; hook = [ ''(rust-mode . (lambda () (cargo-minor-mode)))'' ]
++ (if (elem "emacs::lsp" config.machine.pkgs)
then [''(rust-mode . (lambda () (lsp)))'']
else [''(rust-mode . (lambda () (racer-mode)))'']);
mode = [ ''("\\.rs\\'" . rust-mode)'' ]; mode = [ ''("\\.rs\\'" . rust-mode)'' ];
command = [ "rust-mode" ]; command = [ "rust-mode" ];
bindLocal = optionalAttrs (elem "emacs::company" config.machine.pkgs) { rust-mode-map = {
"<tab>" = "company-indent-or-complete-common";
};};
config = '' config = ''
(setq rust-rustfmt-bin "${pkgs.rustfmt}/bin/rustfmt") (setq rust-rustfmt-bin "${pkgs.rustfmt}/bin/rustfmt")
(setq rust-format-on-save t) (setq rust-format-on-save t)
@ -17,15 +23,11 @@ mkIf (elem "emacs::rust" config.machine.pkgs) {
programs.emacs.init.usePackage.cargo = { programs.emacs.init.usePackage.cargo = {
enable = true; enable = true;
defer = true; defer = true;
# hook = [ ''ru];
}; };
programs.emacs.init.usePackage.racer = { programs.emacs.init.usePackage.racer = {
enable = true; enable = true;
defer = true; defer = true;
bindLocal = optionalAttrs (elem "emacs::company" config.machine.pkgs) { rust-mode-map = {
"<tab>" = "company-indent-or-complete-common";
};};
hook = [ hook = [
''(racer-mode . (lambda () (eldoc-mode)))'' ''(racer-mode . (lambda () (eldoc-mode)))''
] ++ optional (elem "emacs::company" config.machine.pkgs) ''(racer-mode . (lambda () (company-mode)))''; ] ++ optional (elem "emacs::company" config.machine.pkgs) ''(racer-mode . (lambda () (company-mode)))'';

View file

@ -4,7 +4,9 @@ let
stablepkgs = import <nixos-stable> {}; stablepkgs = import <nixos-stable> {};
in { in {
config.machine.pkgsets.rustpkgs.pkgs = with stablepkgs; [ config.machine.pkgsets.rustpkgs.pkgs = with stablepkgs; [
diesel-cli
rustup rustup
rls
carnix carnix
rustracer rustracer
]; ];