401-rust: update rustic bindings and dependencies

* adapt lsp-ui handling
* update lsp handling
* update comany completion handling
* update yasnippet code snippet expansion

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2021-07-25 12:58:53 +02:00
parent cb385e40fd
commit 7c71a12cac

View File

@@ -8,41 +8,94 @@
;; load rustic -> IDE like for rust
;; it superseeds rust-mode
;; reference: https://robert.kra.hn/posts/2021-02-07_rust-with-emacs/
(use-package rustic
:ensure t
:bind (:map rustic-mode-map
("M-j" . lsp-ui-imenu)
("M-?" . lsp-find-references)
("C-c C-c l" . flycheck-list-errors)
("C-c C-c a" . lsp-execute-code-action)
("C-c C-c r" . lsp-rename)
("C-c C-c q" . lsp-workspace-restart)
("C-c C-c Q" . lsp-workspace-shutdown)
("C-c C-c s" . lsp-rust-analyzer-status))
:custom
(linum-on)
(linum-relative-mode 1)
(global-linum-mode)
(rustic-lsp-server 'rust-analyzer)
(setq-default indent-tabs-mode nil)
(rustic-lsp-format t)
;;(linum-relative-toggle)
(setq rustic-format-on-save t)
;;(linum-relative-mode 0)
;;(linum-relative-toggle)
;;(hs-minor-mode t)
;;(lsp-origami-try-enable)
;;(linum-relative-mode 1)
;;(setq-default indent-tabs-mode nil)
;;(rustic-lsp-server 'rust-analyzer)
;;(rustic-lsp-format t)
:config
;; recommended: use spaces instead of tabs
(add-hook 'rust-mode-hook
(lambda () (setq indent-tabs-mode nil)))
(add-hook 'rustic-mode-hook
(lambda () (setq indent-tabs-mode nil)))
;; enable code folding und line numbering rust buffers
(lambda () (setq indent-tabs-mode nil)))
;; enable code folding und line numbering rust buffers
(add-hook 'prog-mode-hook
;;'lsp-origami-mode
'hs-minor-mode
'linum-relative-mode)
;;(remove-hook 'rustic-mode-hook 'flycheck-mode)
;;'lsp-origami-mode
'hs-minor-mode
;;'linum-relative-mode
'tmp/rustic-mode-hook)
;; (remove-hook 'rustic-mode-hook 'flycheck-mode)
;; (setq lsp-eldoc-hook nil)
;; (setq lsp-enable-symbol-highlighting nil)
;; (setq lsp-signature-auto-activate nil)
;; use the lsp UI package
(defun tmp/rustic-mode-hook ()
;; so that run C-c C-c C-r works without having to confirm, but don't try to
;; save rust buffers that are not file visiting. Once
;; https://github.com/brotzeit/rustic/issues/253 has been resolved this should
;; no longer be necessary.
(when buffer-file-name
(setq-local buffer-save-without-query t)))
;; use the lsp package
;; https://emacs-lsp.github.io/lsp-mode
(use-package lsp-mode
:ensure
:commands lsp
:custom
;; what to use when checking on-save. "check" is default, I prefer clippy
(lsp-rust-analyzer-cargo-watch-command "clippy")
(lsp-eldoc-render-all t)
(lsp-idle-delay 0.6)
(lsp-rust-analyzer-server-display-inlay-hints t)
:config
(add-hook 'lsp-mode-hook 'lsp-ui-mode))
(use-package lsp-ivy
:ensure t)
(use-package lsp-ui
:ensure t)
:ensure t
:commands lsp-ui-mode
:custom
(lsp-ui-peek-always-show t)
(lsp-ui-sideline-show-hover t)
(lsp-ui-doc-enable nil))
;; use the company package
;; a completion framework for emacs
(use-package company
:ensure
:custom
(company-idle-delay 2.5) ;; how long to wait until popup
;; (company-begin-commands nil) ;; uncomment to disable popup
:bind
(:map company-active-map
("C-n". company-select-next)
("C-p". company-select-previous)
("M-<". company-select-first)
("M->". company-select-last))
(:map company-mode-map
("<tab>". tab-indent-or-complete)
("TAB". tab-indent-or-complete)))
;; use the yasnippet
(use-package yasnippet
@@ -54,11 +107,38 @@
(yas-reload-all))
;; company-capf.el from load-path
(use-package linum-relative
:config
(setq linum-relative-backend 'display-line-numbers-mode))
;;(use-package linum-relative
;; :config
;; (setq linum-relative-backend 'display-line-numbers-mode))
)
) ;; end use-package rustic
(defun company-yasnippet-or-completion ()
(interactive)
(or (do-yas-expand)
(company-complete-common)))
(defun check-expansion ()
(save-excursion
(if (looking-at "\\_>") t
(backward-char 1)
(if (looking-at "\\.") t
(backward-char 1)
(if (looking-at "::") t nil)))))
(defun do-yas-expand ()
(let ((yas/fallback-behavior 'return-nil))
(yas/expand)))
(defun tab-indent-or-complete ()
(interactive)
(if (minibufferp)
(minibuffer-complete)
(if (or (not yas/minor-mode)
(null (do-yas-expand)))
(if (check-expansion)
(company-complete-common)
(indent-for-tab-command)))))
(provide '401-rust)
;; Local Variables: