branch: elpa/dart-mode
commit a1f36f4e83f5da35519c1b1bb373998a06a7a716
Author: Natalie Weizenbaum <[email protected]>
Commit: Natalie Weizenbaum <[email protected]>
Allow dart-show-hover to display in a new buffer
---
README.md | 4 ++++
dart-mode.el | 32 +++++++++++++++++++++++---------
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index 42d4e79..6de7985 100644
--- a/README.md
+++ b/README.md
@@ -41,3 +41,7 @@ To see all the information the analyzer knows about a
particular identifier,
move your cursor onto it and press `C-c ?`. This will show the identifier's
type
and documentation in the echo area at the bottom of the editor, as well as some
extra information if it's available.
+
+Sometimes there's just too much documentation to fit down there, or you want to
+keep the documentation open as you're working. In that case, you can run `C-u
+C-c ?` instead to open the information in a new window to read at your leisure.
diff --git a/dart-mode.el b/dart-mode.el
index 6de744e..bc710ab 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -987,11 +987,15 @@ reported to CALLBACK."
;;;; Hover
-(defun dart-show-hover ()
- "Displays hover information for the current point."
- (interactive)
+(defun dart-show-hover (&optional show-in-buffer)
+ "Displays hover information for the current point.
+
+With a prefix argument, opens a new buffer rather than using the
+minibuffer."
+ (interactive "P")
(-when-let (filename (buffer-file-name))
- (lexical-let ((buffer (current-buffer)))
+ (lexical-let ((show-in-buffer show-in-buffer)
+ (buffer (current-buffer)))
(dart--analysis-server-send
"analysis.getHover"
`(("file" . ,filename) ("offset" . ,(point)))
@@ -1026,8 +1030,17 @@ reported to CALLBACK."
(when dartdoc) (insert ?\n))
(when dartdoc
(when (or element-description parameter) (insert ?\n))
- (insert (dart--highlight-dartdoc dartdoc)))
- (message "%s" (buffer-string))))))))))
+ (insert (dart--highlight-dartdoc dartdoc (not
show-in-buffer))))
+
+ (let ((text (buffer-string)))
+ (if show-in-buffer
+ (with-current-buffer-window
+ "*Dart Analysis*" nil nil
+ (insert text)
+ ;; We should really create our own mode, but this will do
+ ;; in a pinch.
+ (help-mode))
+ (message "%s" text)))))))))))
(defconst dart--highlight-keyword-re
(regexp-opt
@@ -1088,14 +1101,15 @@ reported to CALLBACK."
(and (looking-at (concat "\\(" dart--identifier-re "\\|[<>]\\)*"))
(eq (char-after (match-end 0)) ?\()))))
-(defun dart--highlight-dartdoc (dartdoc)
+(defun dart--highlight-dartdoc (dartdoc truncate)
"Returns a higlighted copy of DARTDOC."
(with-temp-buffer
(insert dartdoc)
;; Cut off long dartdocs so that the full signature is always visible.
- (goto-line 11)
- (delete-region (- (point) 1) (point-max))
+ (when truncate
+ (goto-line 11)
+ (delete-region (- (point) 1) (point-max)))
(goto-char (point-min))