2016-11-12 12:14:55 +00:00
|
|
|
|
;;; funcs.el --- rust Layer functions File for Spacemacs
|
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
2016-11-12 12:14:55 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: NJBS <DoNotTrackMeUsingThis@gmail.com>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(defun spacemacs//rust-backend ()
|
|
|
|
|
"Returns selected backend."
|
|
|
|
|
(if rust-backend
|
|
|
|
|
rust-backend
|
|
|
|
|
(cond
|
|
|
|
|
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
|
|
|
|
(t 'racer))))
|
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(defun spacemacs//rust-setup-backend ()
|
|
|
|
|
"Conditionally setup rust backend."
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//rust-backend)
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(`racer (spacemacs//rust-setup-racer))
|
|
|
|
|
(`lsp (spacemacs//rust-setup-lsp))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-setup-company ()
|
|
|
|
|
"Conditionally setup company based on backend."
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//rust-backend)
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(`racer (spacemacs//rust-setup-racer-company))
|
|
|
|
|
(`lsp (spacemacs//rust-setup-lsp-company))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-setup-dap ()
|
|
|
|
|
"Conditionally setup elixir DAP integration."
|
|
|
|
|
;; currently DAP is only available using LSP
|
2019-09-30 04:49:44 +00:00
|
|
|
|
(pcase (spacemacs//rust-backend)
|
2019-11-23 19:08:57 +00:00
|
|
|
|
(`lsp (spacemacs//rust-setup-lsp-dap))))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; lsp
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-setup-lsp ()
|
|
|
|
|
"Setup lsp backend"
|
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
|
|
|
|
(lsp)
|
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-setup-lsp-company ()
|
|
|
|
|
"Setup lsp auto-completion."
|
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
|
|
|
|
(progn
|
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
|
:backends company-lsp
|
|
|
|
|
:modes rust-mode))
|
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-setup-lsp-dap ()
|
|
|
|
|
"Setup DAP integration."
|
|
|
|
|
(require 'dap-gdb-lldb))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; racer
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-setup-racer ()
|
|
|
|
|
"Setup racer backend"
|
|
|
|
|
(progn
|
|
|
|
|
(racer-mode)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-setup-racer-company ()
|
|
|
|
|
"Setup racer auto-completion."
|
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
|
:backends company-capf
|
|
|
|
|
:modes rust-mode
|
|
|
|
|
:variables company-tooltip-align-annotations t))
|
|
|
|
|
|
2016-11-12 12:14:55 +00:00
|
|
|
|
(defun spacemacs/racer-describe ()
|
|
|
|
|
"Show a *Racer Help* buffer for the function or type at point.
|
|
|
|
|
If `help-window-select' is non-nil, also select the help window."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((window (racer-describe)))
|
|
|
|
|
(when help-window-select
|
|
|
|
|
(select-window window))))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
|
|
|
|
|
;; Misc
|
2016-11-16 18:33:01 +00:00
|
|
|
|
|
2019-12-23 05:31:34 +00:00
|
|
|
|
(defvar spacemacs//rust-quick-run-tmp-file nil
|
|
|
|
|
"Stores filename for the rust-quick-run function")
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-quick-run-generate-tmp-file-name (input-file-name)
|
|
|
|
|
(concat temporary-file-directory
|
|
|
|
|
(file-name-nondirectory (buffer-file-name))
|
|
|
|
|
"-"
|
|
|
|
|
(md5 (buffer-file-name))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//rust-quick-run-compilation-finish-function (buffer status)
|
|
|
|
|
(if (and (string-match "finished" status)
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(string-match (concat "rustc -o " temporary-file-directory) (buffer-string))))
|
|
|
|
|
(progn
|
|
|
|
|
(newline)
|
|
|
|
|
(shell-command (shell-quote-argument spacemacs//rust-quick-run-tmp-file) t))))
|
|
|
|
|
|
2016-11-16 18:33:01 +00:00
|
|
|
|
(defun spacemacs/rust-quick-run ()
|
|
|
|
|
"Quickly run a Rust file using rustc.
|
|
|
|
|
Meant for a quick-prototype flow only - use `spacemacs/open-junk-file' to
|
|
|
|
|
open a junk Rust file, type in some code and quickly run it.
|
2018-05-24 02:12:30 +00:00
|
|
|
|
If you want to use third-party crates, create a new project using `cargo-process-new' and run
|
2016-11-16 18:33:01 +00:00
|
|
|
|
using `cargo-process-run'."
|
|
|
|
|
(interactive)
|
2019-12-23 05:31:34 +00:00
|
|
|
|
(setq spacemacs//rust-quick-run-tmp-file
|
|
|
|
|
(spacemacs//rust-quick-run-generate-tmp-file-name(buffer-file-name)))
|
|
|
|
|
(compile
|
|
|
|
|
(format "rustc -o %s %s"
|
|
|
|
|
(shell-quote-argument spacemacs//rust-quick-run-tmp-file)
|
|
|
|
|
(shell-quote-argument buffer-file-name))))
|