[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/eglot2emacs c2d97d22aa 056/120: Implement on-type-formatting sup
From: |
João Távora |
Subject: |
feature/eglot2emacs c2d97d22aa 056/120: Implement on-type-formatting support |
Date: |
Thu, 20 Oct 2022 07:16:53 -0400 (EDT) |
branch: feature/eglot2emacs
commit c2d97d22aa535af2640676e1df05a41f9abbd1e3
Author: Felicián Németh <felician.nemeth@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Implement on-type-formatting support
* eglot.el (eglot-format): Add new optional argument `on-type-format'
to request :textDocument/onTypeFormatting, and ...
(eglot--post-self-insert-hook): ... call it from here when necessary.
* eglot-tests.el (eglot--simulate-key-event): New helper defun.
(rust-on-type-formatting): New test.
* NEWS.md: mention feature.
GitHub-reference: close https://github.com/joaotavora/eglot/issues/899
---
lisp/progmodes/eglot.el | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 58ad4588ae..1cf0b7ae63 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -1974,8 +1974,18 @@ THINGS are either registrations or unregisterations
(sic)."
"If non-nil, value of the last inserted character in buffer.")
(defun eglot--post-self-insert-hook ()
- "Set `eglot--last-inserted-char'."
- (setq eglot--last-inserted-char last-input-event))
+ "Set `eglot--last-inserted-char', call on-type-formatting if necessary."
+ (setq eglot--last-inserted-char last-input-event)
+ (when (or (eq last-input-event
+ (elt (eglot--server-capable
+ :documentOnTypeFormattingProvider
+ :firstTriggerCharacter)
+ 0))
+ (seq-find (lambda (elt) (eq last-input-event (elt elt 0)))
+ (eglot--server-capable
+ :documentOnTypeFormattingProvider
+ :moreTriggerCharacter)))
+ (eglot-format (point) nil (string last-input-event))))
(defun eglot--pre-command-hook ()
"Reset `eglot--last-inserted-char'."
@@ -2357,14 +2367,23 @@ Try to visit the target file for a richer summary line."
(interactive)
(eglot-format nil nil))
-(defun eglot-format (&optional beg end)
+(defun eglot-format (&optional beg end on-type-format)
"Format region BEG END.
If either BEG or END is nil, format entire buffer.
Interactively, format active region, or entire buffer if region
-is not active."
+is not active.
+
+If ON-TYPE-FORMAT is non-nil, request on-type-formatting from the
+server. The argument should be a one-character-long string that
+has just been inserted at BEG."
(interactive (and (region-active-p) (list (region-beginning) (region-end))))
(pcase-let ((`(,method ,cap ,args)
(cond
+ ((and beg on-type-format)
+ `(:textDocument/onTypeFormatting
+ :documentOnTypeFormattingProvider
+ ,`(:position ,(eglot--pos-to-lsp-position beg)
+ :ch ,on-type-format)))
((and beg end)
`(:textDocument/rangeFormatting
:documentRangeFormattingProvider
- feature/eglot2emacs 512d8b9f59 011/120: Add variable to withhold the init req process id, (continued)
- feature/eglot2emacs 512d8b9f59 011/120: Add variable to withhold the init req process id, João Távora, 2022/10/20
- feature/eglot2emacs 09c071d3d1 019/120: Add tooltip describing pending requests, João Távora, 2022/10/20
- feature/eglot2emacs f0b9018f52 018/120: Properly print error message of eglot-alternatives, João Távora, 2022/10/20
- feature/eglot2emacs ae7315b5f1 016/120: ; fix license statement, João Távora, 2022/10/20
- feature/eglot2emacs 49e46c3d53 017/120: Add up-to-date server executables for html/css/json, João Távora, 2022/10/20
- feature/eglot2emacs 34c7da506d 020/120: Support autoimporttext from pyright language server, João Távora, 2022/10/20
- feature/eglot2emacs 9adb310e08 021/120: Don't error out on unsupported diagnostic.codedescription, João Távora, 2022/10/20
- feature/eglot2emacs 0f44d338f1 025/120: Support optional diagnostic.tags, João Távora, 2022/10/20
- feature/eglot2emacs 0739cdcf20 031/120: Improve backwards-compatibility of eglot-mode-map, João Távora, 2022/10/20
- feature/eglot2emacs 9710754080 042/120: Add support for optional completionitem.tags, João Távora, 2022/10/20
- feature/eglot2emacs c2d97d22aa 056/120: Implement on-type-formatting support,
João Távora <=
- feature/eglot2emacs 1d9542cbe8 059/120: Protect against empty firsttriggercharacter strings, João Távora, 2022/10/20
- feature/eglot2emacs a63916f928 062/120: Tweak eglot mode-line menus, João Távora, 2022/10/20
- feature/eglot2emacs 4beab004d9 070/120: Ensure exit-function of eglot-c-at-point runs on exact match, João Távora, 2022/10/20
- feature/eglot2emacs 29f2ec2471 071/120: Consider diagnostic.code when generating flymake diagnostics, João Távora, 2022/10/20
- feature/eglot2emacs cc5d1a5a72 091/120: Always default eglot-strict-mode to nil, João Távora, 2022/10/20
- feature/eglot2emacs e74e199912 093/120: Add out-of-box support for perl lsp server, João Távora, 2022/10/20
- feature/eglot2emacs d2e842bbf5 098/120: Prefer documentchanges to changes in server-initiated edits, João Távora, 2022/10/20
- feature/eglot2emacs e5f77f8ca5 100/120: Rework readme.md about workspace configuration again, João Távora, 2022/10/20
- feature/eglot2emacs ec7d63cbe7 105/120: Don't return hash tables from e-w-configuration-plist, João Távora, 2022/10/20
- feature/eglot2emacs 1780b93d66 111/120: Make clojure-lsp handle more major modes at once, João Távora, 2022/10/20