From da8976d8657980c14cb1301e826ef4bfb5512b9b Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 16 Feb 2019 20:29:45 +0100 Subject: emacs-lsp: Add runnables support --- editors/emacs/ra-emacs-lsp.el | 44 +++++++++++++++++++++++++++++++++++++++---- 1 file 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 @@ :ignore-messages nil :server-id 'rust-analyzer)) +(with-eval-after-load 'company-lsp + ;; company-lsp provides a snippet handler for rust by default that adds () after function calls, which RA does better + (setq company-lsp--snippet-functions (assq-delete-all "rust" company-lsp--snippet-functions))) + +;; join lines + (defun rust-analyzer--join-lines-params () "Join lines params." (list :textDocument (lsp--text-document-identifier) @@ -94,10 +100,6 @@ (rust-analyzer--join-lines-params))) (rust-analyzer--apply-source-change))) -(with-eval-after-load 'company-lsp - ;; company-lsp provides a snippet handler for rust by default that adds () after function calls, which RA does better - (setq company-lsp--snippet-functions (assq-delete-all "rust" company-lsp--snippet-functions))) - ;; extend selection (defun rust-analyzer-extend-selection () @@ -135,5 +137,39 @@ (with-eval-after-load 'expand-region (add-hook 'rust-mode-hook 'rust-analyzer--add-er-expansion)) +;; runnables +(defvar rust-analyzer--last-runnable) + +(defun rust-analyzer--runnables-params () + (list :textDocument (lsp--text-document-identifier) + :position (lsp--cur-position))) + +(defun rust-analyzer--runnables () + (lsp-send-request (lsp-make-request "rust-analyzer/runnables" + (rust-analyzer--runnables-params)))) + +(defun rust-analyzer--select-runnable () + (lsp--completing-read + "Select runnable:" + (if rust-analyzer--last-runnable + (cons rust-analyzer--last-runnable (rust-analyzer--runnables)) + (rust-analyzer--runnables)) + (-lambda ((&hash "label")) label))) + +(defun rust-analyzer-run (runnable) + (interactive (list (rust-analyzer--select-runnable))) + (-let (((&hash "env" "bin" "args" "label") runnable)) + (compilation-start + (string-join (cons bin args) " ") + ;; cargo-process-mode is nice, but try to work without it... + (if (functionp 'cargo-process-mode) 'cargo-process-mode nil) + (lambda (_) (concat "*" label "*"))) + (setq rust-analyzer--last-runnable runnable))) + +(defun rust-analyzer-rerun (&optional runnable) + (interactive (list (or rust-analyzer--last-runnable + (rust-analyzer--select-runnable)))) + (rust-analyzer-run (or runnable rust-analyzer--last-runnable))) + (provide 'ra-emacs-lsp) ;;; ra-emacs-lsp.el ends here -- cgit v1.2.3