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 = {
enable = true;
command = [ "lsp-mode" ];
bind = {
"C-c r r" = "lsp-rename";
"C-c r f" = "lsp-format-buffer";
};
config = ''
(setq lsp-keymap-prefix "C-c")
(setq lsp-eldoc-render-all nil)
(defvar lsp-language-id-configuration '(
${optionalString (elem "emacs::rust" config.machine.pkgs
''(rust-mode . "rust")'')}
${optionalString (elem "emacs::rust" config.machine.pkgs)
''(rust-mode . "rust")''}
))
'';
};
@ -36,6 +33,7 @@ mkIf (elem "emacs::lsp" config.machine.pkgs) {
lsp-ui-flycheck = {
enable = true;
package = epkgs: [ epkgs.lsp-ui ];
after = [ "lsp-ui" ]
++ 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 = {
enable = true;
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) {
programs.emacs.init.usePackage.rust-mode = {
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)'' ];
command = [ "rust-mode" ];
bindLocal = optionalAttrs (elem "emacs::company" config.machine.pkgs) { rust-mode-map = {
"<tab>" = "company-indent-or-complete-common";
};};
config = ''
(setq rust-rustfmt-bin "${pkgs.rustfmt}/bin/rustfmt")
(setq rust-format-on-save t)
@ -17,15 +23,11 @@ mkIf (elem "emacs::rust" config.machine.pkgs) {
programs.emacs.init.usePackage.cargo = {
enable = true;
defer = true;
# hook = [ ''ru];
};
programs.emacs.init.usePackage.racer = {
enable = true;
defer = true;
bindLocal = optionalAttrs (elem "emacs::company" config.machine.pkgs) { rust-mode-map = {
"<tab>" = "company-indent-or-complete-common";
};};
hook = [
''(racer-mode . (lambda () (eldoc-mode)))''
] ++ optional (elem "emacs::company" config.machine.pkgs) ''(racer-mode . (lambda () (company-mode)))'';

View file

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