aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-02-16 19:29:45 +0000
committerFlorian Diebold <[email protected]>2019-02-23 12:42:20 +0000
commitda8976d8657980c14cb1301e826ef4bfb5512b9b (patch)
tree2b349ebcd3c3ad2d8ca56f0b8bb2418708587a44 /editors
parente5fb33a94618d45051192d99e859bdd44c3daa36 (diff)
emacs-lsp: Add runnables support
Diffstat (limited to 'editors')
-rw-r--r--editors/emacs/ra-emacs-lsp.el44
1 files changed, 40 insertions, 4 deletions
diff --git a/editors/emacs/ra-emacs-lsp.el b/editors/emacs/ra-emacs-lsp.el
index b13068ee2..4af65c7f0 100644
--- a/editors/emacs/ra-emacs-lsp.el
+++ b/editors/emacs/ra-emacs-lsp.el
@@ -80,6 +80,12 @@
80 :ignore-messages nil 80 :ignore-messages nil
81 :server-id 'rust-analyzer)) 81 :server-id 'rust-analyzer))
82 82
83(with-eval-after-load 'company-lsp
84 ;; company-lsp provides a snippet handler for rust by default that adds () after function calls, which RA does better
85 (setq company-lsp--snippet-functions (assq-delete-all "rust" company-lsp--snippet-functions)))
86
87;; join lines
88
83(defun rust-analyzer--join-lines-params () 89(defun rust-analyzer--join-lines-params ()
84 "Join lines params." 90 "Join lines params."
85 (list :textDocument (lsp--text-document-identifier) 91 (list :textDocument (lsp--text-document-identifier)
@@ -94,10 +100,6 @@
94 (rust-analyzer--join-lines-params))) 100 (rust-analyzer--join-lines-params)))
95 (rust-analyzer--apply-source-change))) 101 (rust-analyzer--apply-source-change)))
96 102
97(with-eval-after-load 'company-lsp
98 ;; company-lsp provides a snippet handler for rust by default that adds () after function calls, which RA does better
99 (setq company-lsp--snippet-functions (assq-delete-all "rust" company-lsp--snippet-functions)))
100
101;; extend selection 103;; extend selection
102 104
103(defun rust-analyzer-extend-selection () 105(defun rust-analyzer-extend-selection ()
@@ -135,5 +137,39 @@
135(with-eval-after-load 'expand-region 137(with-eval-after-load 'expand-region
136 (add-hook 'rust-mode-hook 'rust-analyzer--add-er-expansion)) 138 (add-hook 'rust-mode-hook 'rust-analyzer--add-er-expansion))
137 139
140;; runnables
141(defvar rust-analyzer--last-runnable)
142
143(defun rust-analyzer--runnables-params ()
144 (list :textDocument (lsp--text-document-identifier)
145 :position (lsp--cur-position)))
146
147(defun rust-analyzer--runnables ()
148 (lsp-send-request (lsp-make-request "rust-analyzer/runnables"
149 (rust-analyzer--runnables-params))))
150
151(defun rust-analyzer--select-runnable ()
152 (lsp--completing-read
153 "Select runnable:"
154 (if rust-analyzer--last-runnable
155 (cons rust-analyzer--last-runnable (rust-analyzer--runnables))
156 (rust-analyzer--runnables))
157 (-lambda ((&hash "label")) label)))
158
159(defun rust-analyzer-run (runnable)
160 (interactive (list (rust-analyzer--select-runnable)))
161 (-let (((&hash "env" "bin" "args" "label") runnable))
162 (compilation-start
163 (string-join (cons bin args) " ")
164 ;; cargo-process-mode is nice, but try to work without it...
165 (if (functionp 'cargo-process-mode) 'cargo-process-mode nil)
166 (lambda (_) (concat "*" label "*")))
167 (setq rust-analyzer--last-runnable runnable)))
168
169(defun rust-analyzer-rerun (&optional runnable)
170 (interactive (list (or rust-analyzer--last-runnable
171 (rust-analyzer--select-runnable))))
172 (rust-analyzer-run (or runnable rust-analyzer--last-runnable)))
173
138(provide 'ra-emacs-lsp) 174(provide 'ra-emacs-lsp)
139;;; ra-emacs-lsp.el ends here 175;;; ra-emacs-lsp.el ends here