aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-27 10:56:30 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-27 10:56:30 +0100
commitd23a7558702bcffd9c551bea444475f4a76ba201 (patch)
treea1707c6c6252181b9ab29bcba0979ff305c3274a /editors
parentdc6f0b5a4eaf0e9ac096551a9900a32a7efe742a (diff)
parent00c74b5d18c8c1ae5cd736e4e991ded7e2ba3b4e (diff)
Merge #1596
1596: Implement inlay hints for emacs r=matklad a=flodiebold I wanted to have the nice type hints in emacs as well :smile: ![2019-07-27-111718_982x171_scrot](https://user-images.githubusercontent.com/906069/61992560-43104700-b060-11e9-879f-8ad60f71b2e5.png) Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'editors')
-rw-r--r--editors/emacs/ra-emacs-lsp.el42
1 files changed, 39 insertions, 3 deletions
diff --git a/editors/emacs/ra-emacs-lsp.el b/editors/emacs/ra-emacs-lsp.el
index 21a90c86b..d7656476e 100644
--- a/editors/emacs/ra-emacs-lsp.el
+++ b/editors/emacs/ra-emacs-lsp.el
@@ -15,6 +15,7 @@
15;; - implements source changes (for code actions etc.), except for file system changes 15;; - implements source changes (for code actions etc.), except for file system changes
16;; - implements joinLines (you need to bind rust-analyzer-join-lines to a key) 16;; - implements joinLines (you need to bind rust-analyzer-join-lines to a key)
17;; - implements extendSelection (either bind rust-analyzer-extend-selection to a key, or use expand-region) 17;; - implements extendSelection (either bind rust-analyzer-extend-selection to a key, or use expand-region)
18;; - provides rust-analyzer-inlay-hints-mode for inline type hints
18 19
19;; What's missing: 20;; What's missing:
20;; - file system changes in apply-source-change 21;; - file system changes in apply-source-change
@@ -22,7 +23,6 @@
22;; - onEnter, parentModule, findMatchingBrace 23;; - onEnter, parentModule, findMatchingBrace
23;; - runnables 24;; - runnables
24;; - the debugging commands (syntaxTree and analyzerStatus) 25;; - the debugging commands (syntaxTree and analyzerStatus)
25;; - lsp-ui doesn't interpret the markdown we return currently and instead displays it raw (https://github.com/emacs-lsp/lsp-ui/issues/220 )
26;; - more 26;; - more
27 27
28;; Also, there's a problem with company-lsp's caching being too eager, sometimes 28;; Also, there's a problem with company-lsp's caching being too eager, sometimes
@@ -225,10 +225,46 @@
225 (with-current-buffer buf 225 (with-current-buffer buf
226 (let ((inhibit-read-only t)) 226 (let ((inhibit-read-only t))
227 (erase-buffer) 227 (erase-buffer)
228 (insert parse-result)) 228 (insert parse-result)))
229 )
230 (pop-to-buffer buf)))))) 229 (pop-to-buffer buf))))))
231 230
231;; inlay hints
232(defun rust-analyzer--update-inlay-hints ()
233 (lsp-send-request-async
234 (lsp-make-request "rust-analyzer/inlayHints"
235 (list :textDocument (lsp--text-document-identifier)))
236 (lambda (res)
237 (remove-overlays (point-min) (point-max) 'rust-analyzer--inlay-hint t)
238 (dolist (hint res)
239 (-let* (((&hash "range" "label" "kind") hint)
240 ((beg . end) (lsp--range-to-region range))
241 (overlay (make-overlay beg end)))
242 (overlay-put overlay 'rust-analyzer--inlay-hint t)
243 (overlay-put overlay 'evaporate t)
244 (overlay-put overlay 'after-string (propertize (concat ": " label)
245 'font-lock-face 'font-lock-comment-face)))))
246 'tick)
247 nil)
248
249(defvar-local rust-analyzer--inlay-hints-timer nil)
250
251(defun rust-analyzer--inlay-hints-change-handler (&rest rest)
252 (when rust-analyzer--inlay-hints-timer
253 (cancel-timer rust-analyzer--inlay-hints-timer))
254 (setq rust-analyzer--inlay-hints-timer
255 (run-with-idle-timer 0.1 nil #'rust-analyzer--update-inlay-hints)))
256
257(define-minor-mode rust-analyzer-inlay-hints-mode
258 "Mode for showing inlay hints."
259 nil nil nil
260 (cond
261 (rust-analyzer-inlay-hints-mode
262 (rust-analyzer--update-inlay-hints)
263 (add-hook 'after-change-functions #'rust-analyzer--inlay-hints-change-handler nil t))
264 (t
265 (remove-overlays (point-min) (point-max) 'rust-analyzer--inlay-hint t)
266 (remove-hook 'after-change-functions #'rust-analyzer--inlay-hints-change-handler t))))
267
232 268
233(provide 'ra-emacs-lsp) 269(provide 'ra-emacs-lsp)
234;;; ra-emacs-lsp.el ends here 270;;; ra-emacs-lsp.el ends here