diff options
| author | João Távora | 2023-09-20 11:00:19 +0100 |
|---|---|---|
| committer | João Távora | 2023-09-20 11:02:51 +0100 |
| commit | 76cdf293c480c3825eb99eae0ab863d185cf6570 (patch) | |
| tree | b9859f32fca403ae4c6280bf587183744bde569b | |
| parent | f0794ac9cafb8354119ef0052c67f092ed059eb4 (diff) | |
| download | emacs-76cdf293c480c3825eb99eae0ab863d185cf6570.tar.gz emacs-76cdf293c480c3825eb99eae0ab863d185cf6570.zip | |
Eglot: better consider diagnostics at point on code action requests
* lisp/progmodes/eglot.el (eglot--code-action-bounds): Rename from
eglot--code-action-bounds. Rework to consider diagnostics.
(eglot-code-actions): Use new eglot--code-action-bounds.
(eglot--code-action): Use new eglot--code-action-bounds.
* etc/EGLOT-NEWS: mention change.
GitHub-reference: https://github.com/joaotavora/eglot/discussions/1295
| -rw-r--r-- | etc/EGLOT-NEWS | 7 | ||||
| -rw-r--r-- | lisp/progmodes/eglot.el | 21 |
2 files changed, 21 insertions, 7 deletions
diff --git a/etc/EGLOT-NEWS b/etc/EGLOT-NEWS index ffc8095f752..f5f78ccd483 100644 --- a/etc/EGLOT-NEWS +++ b/etc/EGLOT-NEWS | |||
| @@ -43,6 +43,13 @@ For 'newline' commands, Eglot sometimes sent the wrong character code | |||
| 43 | to the server. Also made this feature less chatty in the mode-line | 43 | to the server. Also made this feature less chatty in the mode-line |
| 44 | and messages buffer. | 44 | and messages buffer. |
| 45 | 45 | ||
| 46 | ** Improve mouse invocation of code actions | ||
| 47 | |||
| 48 | When invoking code actions by middle clicking with the mouse on | ||
| 49 | Flymake diagnostics, it was often the case that Eglot didn't request | ||
| 50 | code actions correctly and thus no actions were offered to the user. | ||
| 51 | This has been fixed. github#1295 | ||
| 52 | |||
| 46 | 53 | ||
| 47 | * Changes in Eglot 1.15 (29/4/2023) | 54 | * Changes in Eglot 1.15 (29/4/2023) |
| 48 | 55 | ||
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 79b3dbb2994..e511df01850 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el | |||
| @@ -3579,11 +3579,18 @@ edit proposed by the server." | |||
| 3579 | :newName ,newname)) | 3579 | :newName ,newname)) |
| 3580 | this-command)) | 3580 | this-command)) |
| 3581 | 3581 | ||
| 3582 | (defun eglot--region-bounds () | 3582 | (defun eglot--code-action-bounds () |
| 3583 | "Region bounds if active, else bounds of things at point." | 3583 | "Calculate appropriate bounds depending on region and point." |
| 3584 | (if (use-region-p) `(,(region-beginning) ,(region-end)) | 3584 | (let (diags) |
| 3585 | (let ((boftap (bounds-of-thing-at-point 'sexp))) | 3585 | (cond ((use-region-p) `(,(region-beginning) ,(region-end))) |
| 3586 | (list (car boftap) (cdr boftap))))) | 3586 | ((setq diags (flymake-diagnostics (point))) |
| 3587 | (cl-loop for d in diags | ||
| 3588 | minimizing (flymake-diagnostic-beg d) into beg | ||
| 3589 | maximizing (flymake-diagnostic-end d) into end | ||
| 3590 | finally (cl-return (list beg end)))) | ||
| 3591 | (t | ||
| 3592 | (let ((boftap (bounds-of-thing-at-point 'sexp))) | ||
| 3593 | (list (car boftap) (cdr boftap))))))) | ||
| 3587 | 3594 | ||
| 3588 | (defun eglot-code-actions (beg &optional end action-kind interactive) | 3595 | (defun eglot-code-actions (beg &optional end action-kind interactive) |
| 3589 | "Find LSP code actions of type ACTION-KIND between BEG and END. | 3596 | "Find LSP code actions of type ACTION-KIND between BEG and END. |
| @@ -3593,7 +3600,7 @@ Interactively, default BEG and END to region's bounds else BEG is | |||
| 3593 | point and END is nil, which results in a request for code actions | 3600 | point and END is nil, which results in a request for code actions |
| 3594 | at point. With prefix argument, prompt for ACTION-KIND." | 3601 | at point. With prefix argument, prompt for ACTION-KIND." |
| 3595 | (interactive | 3602 | (interactive |
| 3596 | `(,@(eglot--region-bounds) | 3603 | `(,@(eglot--code-action-bounds) |
| 3597 | ,(and current-prefix-arg | 3604 | ,(and current-prefix-arg |
| 3598 | (completing-read "[eglot] Action kind: " | 3605 | (completing-read "[eglot] Action kind: " |
| 3599 | '("quickfix" "refactor.extract" "refactor.inline" | 3606 | '("quickfix" "refactor.extract" "refactor.inline" |
| @@ -3656,7 +3663,7 @@ at point. With prefix argument, prompt for ACTION-KIND." | |||
| 3656 | "Define NAME to execute KIND code action." | 3663 | "Define NAME to execute KIND code action." |
| 3657 | `(defun ,name (beg &optional end) | 3664 | `(defun ,name (beg &optional end) |
| 3658 | ,(format "Execute `%s' code actions between BEG and END." kind) | 3665 | ,(format "Execute `%s' code actions between BEG and END." kind) |
| 3659 | (interactive (eglot--region-bounds)) | 3666 | (interactive (eglot--code-action-bounds)) |
| 3660 | (eglot-code-actions beg end ,kind t))) | 3667 | (eglot-code-actions beg end ,kind t))) |
| 3661 | 3668 | ||
| 3662 | (eglot--code-action eglot-code-action-organize-imports "source.organizeImports") | 3669 | (eglot--code-action eglot-code-action-organize-imports "source.organizeImports") |