[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 409cc64 344/495: cmd/oracle: usability improvement
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 409cc64 344/495: cmd/oracle: usability improvements to "describe", "referrers" |
Date: |
Sat, 7 Aug 2021 09:05:45 -0400 (EDT) |
branch: elpa/go-mode
commit 409cc64106c67c6d79382b08c34a26c4f21a2403
Author: Alan Donovan <adonovan@google.com>
Commit: Dominik Honnef <dominik@honnef.co>
cmd/oracle: usability improvements to "describe", "referrers"
Emacs integration:
- eliminate oracle minor mode
- in go-mode, bind F5, F6 to "describe", "referrers".
This reverts a previous policy decision but convenience matters too.
- don't insist on an analysis scope for modes that don't do PTA.
- don't hide the filename as "▶"; show the last 20 chars.
(Especially useful for "referrers" mode.)
- output postprocessing: don't get stuck in a loop if the output
is not as expected (e.g. when it includes a panic log).
referrers:
- show the matching lines (like grep does).
We do the I/O in parallel.
Change-Id: I86b18c1d3a4d9fa4242984cba62b314796669d8e
Reviewed-on: https://go-review.googlesource.com/8120
Reviewed-by: David Crawshaw <crawshaw@golang.org>
---
guru_import/cmd/oracle/oracle.el | 87 ++++++++++++++++++++--------------------
1 file changed, 44 insertions(+), 43 deletions(-)
diff --git a/guru_import/cmd/oracle/oracle.el b/guru_import/cmd/oracle/oracle.el
index f90a5fd..825eee1 100644
--- a/guru_import/cmd/oracle/oracle.el
+++ b/guru_import/cmd/oracle/oracle.el
@@ -36,22 +36,21 @@
nil
"History of values supplied to `go-oracle-set-scope'.")
-;; TODO(adonovan): I'd like to get rid of this separate mode since it
-;; makes it harder to use the oracle.
-(defvar go-oracle-mode-map
- (let ((m (make-sparse-keymap)))
- (define-key m (kbd "C-c C-o t") #'go-oracle-describe) ; t for type
- (define-key m (kbd "C-c C-o f") #'go-oracle-freevars)
- (define-key m (kbd "C-c C-o g") #'go-oracle-callgraph)
- (define-key m (kbd "C-c C-o i") #'go-oracle-implements)
- (define-key m (kbd "C-c C-o c") #'go-oracle-peers) ; c for channel
- (define-key m (kbd "C-c C-o r") #'go-oracle-referrers)
- (define-key m (kbd "C-c C-o d") #'go-oracle-definition)
- (define-key m (kbd "C-c C-o p") #'go-oracle-pointsto)
- (define-key m (kbd "C-c C-o s") #'go-oracle-callstack)
- (define-key m (kbd "C-c C-o <") #'go-oracle-callers)
- (define-key m (kbd "C-c C-o >") #'go-oracle-callees)
- m))
+;; Extend go-mode-map.
+(let ((m go-mode-map))
+ (define-key m (kbd "C-c C-o t") #'go-oracle-describe) ; t for type
+ (define-key m (kbd "C-c C-o f") #'go-oracle-freevars)
+ (define-key m (kbd "C-c C-o g") #'go-oracle-callgraph)
+ (define-key m (kbd "C-c C-o i") #'go-oracle-implements)
+ (define-key m (kbd "C-c C-o c") #'go-oracle-peers) ; c for channel
+ (define-key m (kbd "C-c C-o r") #'go-oracle-referrers)
+ (define-key m (kbd "C-c C-o d") #'go-oracle-definition)
+ (define-key m (kbd "C-c C-o p") #'go-oracle-pointsto)
+ (define-key m (kbd "C-c C-o s") #'go-oracle-callstack)
+ (define-key m (kbd "C-c C-o <") #'go-oracle-callers)
+ (define-key m (kbd "C-c C-o >") #'go-oracle-callees)
+ (define-key m (kbd "<f5>") #'go-oracle-describe)
+ (define-key m (kbd "<f6>") #'go-oracle-referrers))
;; TODO(dominikh): Rethink set-scope some. Setting it to a file is
;; painful because it doesn't use find-file, and variables/~ aren't
@@ -84,11 +83,11 @@ specify to 'go build'."
(error "You must specify a non-empty scope for the Go oracle"))
(setq go-oracle-scope scope)))
-(defun go-oracle--run (mode)
+(defun go-oracle--run (mode &optional need-scope)
"Run the Go oracle in the specified MODE, passing it the
-selected region of the current buffer. Process the output to
-replace each file name with a small hyperlink. Display the
-result."
+selected region of the current buffer. If NEED-SCOPE, prompt for
+a scope if not already set. Process the output to replace each
+file name with a small hyperlink. Display the result."
(if (not buffer-file-name)
(error "Cannot use oracle on a buffer without a file name"))
;; It's not sufficient to save a modified buffer since if
@@ -96,8 +95,9 @@ result."
;; disturb the selected region.
(if (buffer-modified-p)
(error "Please save the buffer before invoking go-oracle"))
- (if (string-equal "" go-oracle-scope)
- (go-oracle-set-scope))
+ (and need-scope
+ (string-equal "" go-oracle-scope)
+ (go-oracle-set-scope))
(let* ((filename (file-truename buffer-file-name))
(posflag (if (use-region-p)
(format "-pos=%s:#%d,#%d"
@@ -107,7 +107,6 @@ result."
(format "-pos=%s:#%d"
filename
(1- (position-bytes (point))))))
- ;; This would be simpler if we could just run 'go tool oracle'.
(env-vars (go-root-and-paths))
(goroot-env (concat "GOROOT=" (car env-vars)))
(gopath-env (concat "GOPATH=" (mapconcat #'identity (cdr env-vars)
":"))))
@@ -138,14 +137,23 @@ result."
(p 1))
(while (not (null p))
(let ((np (compilation-next-single-property-change p
'compilation-message)))
- ;; TODO(adonovan): this can be verbose in the *Messages* buffer.
- ;; (message "Post-processing link (%d%%)" (/ (* p 100)
(point-max)))
(if np
(when (equal (line-number-at-pos p) (line-number-at-pos np))
- ;; np is (typically) the space following ":"; consume it too.
- (put-text-property p np 'display "▶")
+ ;; Using a fixed width greatly improves readability, so
+ ;; if the filename is longer than 20, show
".../last/17chars.go".
+ ;; This usually includes the last segment of the package
name.
+ ;; Don't show the line or column number.
+ (let* ((loc (buffer-substring p np)) ;
"/home/foo/go/pkg/file.go:1:2-3:4"
+ (i (search ":" loc)))
+ (setq loc (cond
+ ((null i) "...")
+ ((>= i 17) (concat "..." (substring loc (- i
17) i)))
+ (t (substring loc 0 i))))
+ ;; np is (typically) the space following ":"; consume it
too.
+ (put-text-property p np 'display (concat loc ":")))
(goto-char np)
- (insert " ")))
+ (insert " ")
+ (incf np))) ; so we don't get stuck (e.g. on a panic stack
dump)
(setq p np)))
(message nil))
@@ -157,23 +165,23 @@ result."
(defun go-oracle-callees ()
"Show possible callees of the function call at the current point."
(interactive)
- (go-oracle--run "callees"))
+ (go-oracle--run "callees" t))
(defun go-oracle-callers ()
"Show the set of callers of the function containing the current point."
(interactive)
- (go-oracle--run "callers"))
+ (go-oracle--run "callers" t))
(defun go-oracle-callgraph ()
"Show the callgraph of the current program."
(interactive)
- (go-oracle--run "callgraph"))
+ (go-oracle--run "callgraph" t))
(defun go-oracle-callstack ()
"Show an arbitrary path from a root of the call graph to the
function containing the current point."
(interactive)
- (go-oracle--run "callstack"))
+ (go-oracle--run "callstack" t))
(defun go-oracle-definition ()
"Show the definition of the selected identifier."
@@ -188,7 +196,7 @@ function containing the current point."
(defun go-oracle-pointsto ()
"Show what the selected expression points to."
(interactive)
- (go-oracle--run "pointsto"))
+ (go-oracle--run "pointsto" t))
(defun go-oracle-implements ()
"Describe the 'implements' relation for types in the package
@@ -205,25 +213,18 @@ containing the current point."
"Enumerate the set of possible corresponding sends/receives for
this channel receive/send operation."
(interactive)
- (go-oracle--run "peers"))
+ (go-oracle--run "peers" t))
(defun go-oracle-referrers ()
"Enumerate all references to the object denoted by the selected
identifier."
(interactive)
- (go-oracle--run "referrers"))
+ (go-oracle--run "referrers" t))
(defun go-oracle-whicherrs ()
"Show globals, constants and types to which the selected
expression (of type 'error') may refer."
(interactive)
- (go-oracle--run "whicherrs"))
-
-;; TODO(dominikh): better docstring
-(define-minor-mode go-oracle-mode "Oracle minor mode for go-mode
-
-Keys specific to go-oracle-mode:
-\\{go-oracle-mode-map}"
- nil " oracle" go-oracle-mode-map)
+ (go-oracle--run "whicherrs" t))
(provide 'go-oracle)
- [nongnu] elpa/go-mode b91a6cd 479/495: Fix composite literal key fontification, (continued)
- [nongnu] elpa/go-mode b91a6cd 479/495: Fix composite literal key fontification, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 85a20da 482/495: Only fontify ident keys in composite literals, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 53c76cd 480/495: Speed up slow fontification after unclosed parens., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8bfc70a 484/495: Fix accidental old style backquote comma use., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d17d210 489/495: Improve go-fontify-variables logic., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3497434 495/495: Fix fontification of chained map types., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8d1594f 295/495: Automatically detect goimports, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 734d523 488/495: Move some defconsts up to fix compiler warnings., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 51f507c 315/495: Complete list of commands in mode docstring, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 004575e 330/495: Don't leave godef buffer around, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 409cc64 344/495: cmd/oracle: usability improvements to "describe", "referrers",
ELPA Syncer <=
- [nongnu] elpa/go-mode d9d47fa 332/495: go.tools/oracle: change -ptalog default to ""., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode bd236e5 367/495: cmd/guru: emacs: update default-directory, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2db2ff6 333/495: go.tools/oracle: change -pos flag syntax from "file pos-pos" to file:pos-pos., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 17a7d8a 370/495: cmd/guru: emacs: add function for expandiong region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode dbc9124 378/495: Move go-guru.el to top level, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b949a9b 363/495: cmd/guru: emacs: add go-guru-debug variable, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 04a2946 380/495: Merge branch 'import-guru', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 259110b 396/495: Use a named function for before-change-functions., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d964767 399/495: Use forward-word-strictly when available, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7c38d6a 477/495: Improve commenting partial lines., ELPA Syncer, 2021/08/07