[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dart-mode c172f19 106/192: Support completing multiple par
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dart-mode c172f19 106/192: Support completing multiple parameters |
Date: |
Sun, 29 Aug 2021 11:01:59 -0400 (EDT) |
branch: elpa/dart-mode
commit c172f193b4b20c15129017e39ec8b40481abddcb
Author: Natalie Weizenbaum <nex342@gmail.com>
Commit: Natalie Weizenbaum <nex342@gmail.com>
Support completing multiple parameters
---
CHANGELOG.md | 4 +-
README.md | 5 +++
dart-mode.el | 134 ++++++++++++++++++++++++++++++++++++++++-------------------
3 files changed, 99 insertions(+), 44 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c5845e..302b2c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,7 +19,9 @@
of references to members with a given name.
* Added a `dart-expand` command bound to `M-/` which cycles through possible
- completions for the text typed by the user.
+ completions for the text typed by the user, as well as a
+ `dart-expand-parameters` command bound to `M-?` which inserts the parameter
+ list for the chosen completion.
* `dart-executable-path`'s default value is now set correctly even if the
executable named `dart` on the user's path is a symlink or a wrapper script.
diff --git a/README.md b/README.md
index 511c721..fbbc4b5 100644
--- a/README.md
+++ b/README.md
@@ -89,6 +89,11 @@ autocomplete, but the UI works like Emacs'
[`dabbrev-expand`][dabbrev] command.
You can press `M-/` multiple times in a row to cycle through possible
completions.
+When you've selected an expansion that's a method call, you can press `M-?`
+(`M-/` plus shift) to insert the parameter list. The first parameter will be
+selected, and anything you type will replace it. Once it's replaced, you can
+press `M-?` again to select the second parameter, and so on.
+
[dabbrev]:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Dynamic-Abbrevs.html
If the analysis server isn't enabled for the current buffer, this will fall
back
diff --git a/dart-mode.el b/dart-mode.el
index ac4f41c..54f5133 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -1366,15 +1366,33 @@ defaults to the command globally bound to M-/."
(defvar dart--last-expand-results nil
"The results of the last call to `dart-expand'.")
-(defvar dart--last-expand-offset nil
- "The offset of the text inserted by the last call to `dart-expand'.")
+(defvar dart--last-expand-beginning nil
+ "The marker for the beginning of the text inserted by the last call to
`dart-expand'.")
-(defvar dart--last-expand-length nil
- "The length of the text inserted by the last call to `dart-expand'.")
+(defvar dart--last-expand-end nil
+ "The marker for the end of the text inserted by the last call to
`dart-expand'.")
(defvar dart--last-expand-index nil
"The index into `dart--last-expand-results' for the last call to
`dart-expand'.")
+(defvar dart--last-expand-parameters-index nil
+ "The index into for the last parameter suggestion from
`dart-expand-parameters'.
+
+This is an index into the paramaterNames and parameterTypes list
+in the suggestion identified by `dart--last-expand-index', and
+into `dart--last-expand-parameters-ranges'.")
+
+(defvar dart--last-expand-parameters-ranges nil
+ "The list of parameter ranges for the last call to `dart-expand-parameters'.
+
+This is a list of pairs of markers. Each pair identifies the
+beginning and end of a parameter in the parameter list generated
+by `dart-expand-parameters'`.
+
+Note that the end markers are placed one character after the
+actual ending of the parameter. This ensures that if the marker
+stayas in place when the parameter is overwritten.")
+
(defvar dart--last-expand-subscription nil
"The last analysis server subscription from a call to `dart-expand'.")
@@ -1391,15 +1409,15 @@ defaults to the command globally bound to M-/."
(when (>= dart--last-expand-index (length dart--last-expand-results))
(setq dart--last-expand-index 0))
(dart--use-expand-suggestion
- dart--last-expand-offset
- dart--last-expand-length
+ dart--last-expand-beginning
+ dart--last-expand-end
(elt dart--last-expand-results dart--last-expand-index)))
(when dart--last-expand-subscription
(dart--analysis-server-unsubscribe dart--last-expand-subscription))
(setq dart--last-expand-results nil)
- (setq dart--last-expand-offset nil)
- (setq dart--last-expand-length nil)
+ (setq dart--last-expand-beginning nil)
+ (setq dart--last-expand-end nil)
(setq dart--last-expand-index nil)
(setq dart--last-expand-subscription nil)
@@ -1451,24 +1469,24 @@ If FIRST is non-nil, this is the first completion event
for this completion."
;; calls.
(when first
(setq dart--last-expand-index 0)
- (setq dart--last-expand-offset (+ offset 1))
- (dart--use-expand-suggestion (+ offset 1) length (elt results 0)))
+ (setq dart--last-expand-beginning (copy-marker (+ offset 1)))
+ (dart--use-expand-suggestion (+ offset 1) (+ offset length 1) (elt
results 0)))
(setq first nil)
(setq dart--last-expand-results results)))
-(defun dart--use-expand-suggestion (offset length suggestion)
- "Inserts SUGGESTION at OFFSET and LENGTH."
+(defun dart--use-expand-suggestion (beginning end suggestion)
+ "Inserts SUGGESTION between BEGINNING and END."
(dart--json-let suggestion
(completion element
(selection-offset selectionOffset)
(is-deprecated isDeprecated)
(doc-summary docSummary))
- (setq dart--last-expand-length (length completion))
-
- (goto-char offset)
- (delete-char length)
- (save-excursion (insert completion))
+ (goto-char beginning)
+ (delete-region beginning end)
+ (save-excursion
+ (insert completion)
+ (setq dart--last-expand-end (point-marker)))
(forward-char selection-offset)
(with-temp-buffer
@@ -1510,8 +1528,13 @@ If FIRST is non-nil, this is the first completion event
for this completion."
This will select the first parameter, if one exists."
(interactive "*")
- (when (and (eq last-command 'dart-expand)
- dart--last-expand-results)
+ (cond
+ ((and (eq last-command 'dart-expand)
+ dart--last-expand-results)
+
+ ;; If this is called directly after `dart-expand', create the parameter
list
+ ;; and highlight the first entry.
+ (setq dart--last-expand-parameters-index 0)
(dart--json-let (elt dart--last-expand-results dart--last-expand-index)
((parameter-names parameterNames)
(argument-string defaultArgumentListString)
@@ -1521,35 +1544,60 @@ This will select the first parameter, if one exists."
(setq argument-ranges (or argument-ranges [0 0]))
(save-excursion
- (insert ?\( argument-string ?\)))
- (incf dart--last-expand-length (+ (length argument-string) 2))
-
- (setq transient-mark-mode nil)
- (forward-char (+ 1 (elt argument-ranges 0)))
- (push-mark nil t)
- (forward-char (elt argument-ranges 1))
-
- ;; Run this in a timer because `activate-mark' doesn't seem to work
- ;; directly, and because we don't want to disable
`delete-selection-mode'
- ;; after this command.
- (run-at-time
- "0 sec" nil
- (lambda ()
- (activate-mark)
-
- ;; Overwrite the current selection, but don't globally enable
- ;; delete-selection-mode.
- (unless delete-selection-mode
- (delete-selection-mode 1)
- (add-hook 'post-command-hook 'dart--disable-highlight t t))))))))
-
-(defun dart--disable-highlight ()
+ (insert ?\( argument-string ?\))
+ (setq dart--last-expand-end (point-marker)))
+
+ (setq dart--last-expand-parameters-ranges
+ (loop for i below (length argument-ranges) by 2
+ collect (let* ((beginning (+ (point) 1 (elt
argument-ranges i)))
+ (end (+ beginning (elt argument-ranges (+ i
1)) 1)))
+ (list (copy-marker beginning) (copy-marker
end)))))
+
+ (let ((range (car dart--last-expand-parameters-ranges)))
+ (dart--delsel-range (car range) (- (cadr range) 1))))))
+
+ ((and (< dart--last-expand-beginning (point) dart--last-expand-end)
+ dart--last-expand-parameters-index)
+
+ ;; If this is called when the point is within the text generated by the
+ ;; last `dart-expand-parameters' call, move to the next parameter in the
+ ;; list.
+ (incf dart--last-expand-parameters-index)
+ (when (>= dart--last-expand-parameters-index (length
dart--last-expand-parameters-ranges))
+ (setq dart--last-expand-parameters-index 0))
+
+ (let ((range (elt dart--last-expand-parameters-ranges
+ dart--last-expand-parameters-index)))
+ (dart--delsel-range (car range) (- (cadr range) 1))))))
+
+(defun dart--delsel-range (beginning end)
+ "Highlights the range between BEGINNING and END and enables
`delete-selection-mode' temporarily."
+ (setq transient-mark-mode nil)
+ (goto-char beginning)
+ (push-mark nil t)
+ (goto-char end)
+
+ ;; Run this in a timer because `activate-mark' doesn't seem to work
+ ;; directly, and because we don't want to disable `delete-selection-mode'
+ ;; when `post-command-hook' is invoked after the calling command finishes.
+ (run-at-time
+ "0 sec" nil
+ (lambda ()
+ (activate-mark)
+
+ ;; Overwrite the current selection, but don't globally enable
+ ;; delete-selection-mode.
+ (unless delete-selection-mode
+ (delete-selection-mode 1)
+ (add-hook 'post-command-hook 'dart--disable-delsel t t)))))
+
+(defun dart--disable-delsel ()
"Disables `delete-selection-mode' and deactivates the mark.
Also removes this function from `post-command-hook'."
(deactivate-mark)
(delete-selection-mode 0)
- (remove-hook 'post-command-hook 'dart--disable-delete-selection-mode t))
+ (remove-hook 'post-command-hook 'dart--disable-delsel t))
;;; Popup Mode
- [nongnu] elpa/dart-mode 4232d23 041/192: Actually set the style when initializing the mode., (continued)
- [nongnu] elpa/dart-mode 4232d23 041/192: Actually set the style when initializing the mode., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 2d00ec4 043/192: Properly indent multiline optional parameter lists., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode b1ba925 045/192: arglist-intro should be ++., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f16c1c1 047/192: Fix an odd indentation bug., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 147f554 063/192: Merge pull request #11 from hterkelsen/dartanalyzer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 89573d5 067/192: Use a pipe instead of a pty for the analysis server, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 35a794c 086/192: Add workaround for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=18845 (#40), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9b11e8f 088/192: Another attempt at fixing byte compilation. (#42), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 3a73a1f 090/192: Make dart-executable-path resilient to wrappers, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode b4e592f 098/192: Add more search commands, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c172f19 106/192: Support completing multiple parameters,
ELPA Syncer <=
- [nongnu] elpa/dart-mode 2b085f5 125/192: Do not fail if Flycheck is not available. (#52), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c973dea 127/192: Require ‘help-mode’., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 68f7f4f 132/192: Require cl for emacs 24.4, 24.5, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode caa7a19 124/192: Don't error out with revert-buffer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 199709f 148/192: Removes cc-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode da244c6 144/192: Fixes no such file or directory, dartfmt.exe, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9db2679 143/192: Fixes invalid file path format on Windows, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 06e2d4b 160/192: Respect font-lock-maximum-decoration, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 3082066 185/192: Don't font lock anchor in a string, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode ad93bc1 165/192: Edit headers, ELPA Syncer, 2021/08/29