aboutsummaryrefslogtreecommitdiff
path: root/editors/emacs
diff options
context:
space:
mode:
Diffstat (limited to 'editors/emacs')
-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